<jupyter_start><jupyter_text>Creating connection<jupyter_code>connection_url_postgres = URL.create(
  'postgresql+psycopg2',
  username='postgres',
  password='<PASSWORD>',
  host='10.0.0.9',
  port=5432,
  database='postgres'
)
engine_postgres = create_engine(connection_url_postgres)
session_postgres = Session(engine_postgres, future=True)<jupyter_output><empty_output><jupyter_text>Creating Models<jupyter_code>Base = declarative_base()

class Machine(Base):
    __tablename__ = 'machine'
    
    MachineID  = Column(Integer, primary_key=True,  autoincrement=False)

    MachineCode = Column(String(64))
    MachineDescription = Column( String(64))
    MachineImageUrl = Column( String(2056))
    MachineThumbnailUrl = Column( String(2056))
    MachineTypeID = Column( Integer,ForeignKey("machine_type.MachineTypeID"))
    ActiveWorkerID =Column( Integer, ForeignKey("worker.WorkerID"))
    LineID = Column( Integer,ForeignKey("line.LineID"))
    Operations =Column(JSON)
    CreatedAt=Column(DateTime)
    UpdatedAt =Column(DateTime)
    BoxID=Column(Integer)
    #COLUMNS ADDED LATER
    IsMachineDown=Column(Boolean)
    LineCode =Column( String(64))
    LineDescription =Column( String(64))  
    WorkerID=Column(Integer)
    WorkerCode=Column(String(64))
    WorkerDescription=Column( String(64))
    WorkerImageUrl=Column(String(2056))
    WorkerThumbnailUrl=Column(String(2056))
    AllocatedMachines=Column(JSON)
    MachineTypeCode =Column(String(64))
    MachineTypeDescription=Column( String(64))
    Allowance=Column( Float)    

    line = relationship("Line")
    machine_type = relationship("MachineType")
    worker = relationship("Worker")
    
class Line(Base):
    __tablename__ = 'line'
    
    LineID=Column(Integer, primary_key = True, autoincrement=False)

    LineCode=Column(String(64))
    LineDescription=Column(String(64))
    CreatedAt=Column(DateTime)
    UpdatedAt=Column(DateTime)

class MachineType(Base):
    __tablename__ = 'machine_type'

    MachineTypeID=Column(Integer, primary_key = True, autoincrement=False)

    MachineTypeCode=Column(String(64))
    MachineTypeDescription=Column(String(64))
    Allowance=Column(Float)
    CreatedAt=Column(DateTime)
    UpdatedAt=Column(DateTime)

class Worker(Base):
    __tablename__ = 'worker'

    WorkerID=Column(Integer, primary_key = True, autoincrement=False)

    WorkerCode=Column(String(64))
    WorkerDescription=Column(String(64))
    WorkerImageUrl=Column(String(2056))
    WorkerThumbnailUrl=Column(String(2056))
    AllocatedMachines=Column(JSON)
    CreatedAt=Column( DateTime)
    UpdatedAt=Column(DateTime)

class WorkerScan(Base):
    __tablename__ = 'worker_scan'
    __table_args__ = {'extend_existing': True} #additional arguments to be supplied to the Table constructor should be provided using the __table_args__ declarative class attribute.

    WorkerScanID=Column(BIGINT, primary_key = True, autoincrement=False) 

    WorkerID =Column(Integer, ForeignKey("worker.WorkerID"))
    LineID=Column(Integer,ForeignKey("line.LineID"))
    MachineID=Column(Integer,ForeignKey("machine.MachineID"))
    WorkerOperations=Column(JSON)
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    HasExpired=Column(Integer)
    EndedAt=Column(DateTime) 
    LineCode=Column(String(64))
    LineDescription=Column(String(64)) 
    WorkerCode=Column(String(64))
    WorkerDescription=Column(String(64)) 
    WorkerImageUrl=Column(String(2056)) 
    WorkerThumbnailUrl=Column(String(2056)) 
    AllocatedMachines=Column(JSON)
    MachineCode=Column(String(64))
    MachineDescription=Column(String(64))
    MachineImageUrl=Column(String(2056)) 
    MachineThumbnailUrl=Column(String(2056))
    MachineTypeID=Column(Integer, ForeignKey("machine_type.MachineTypeID"))
    ActiveWorkerID=Column(Integer)
    Operations=Column(JSON)
    BoxID=Column(Integer)
    #COLUMN ADDED LATER
    IsMachineDown=Column(Boolean)
    MachineTypeCode=Column(String(64)) 
    MachineTypeDescription=Column(String(64)) 
    Allowance=Column(Float)
    

    line = relationship("Line")
    machine = relationship("Machine")
    worker = relationship("Worker")
    machine_type = relationship("MachineType")    

class ProductionOrder(Base):
    __tablename__ = 'production_order'
    __table_args__ = {'extend_existing': True}

    ProductionOrderID=Column(Integer, primary_key = True, autoincrement=False) 
    
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer, ForeignKey("sale_order.SaleOrderID"))
    StyleTemplateID=Column(Integer, ForeignKey("style_template.StyleTemplateID"))    
    IsFollowOperationSequence=Column(Boolean)
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    
    SaleOrderCode=Column(String(100))
    Customer=Column(String(64))
    OrderQuantity=Column(Integer)            

    StyleTemplateCode=Column(String(64))

    
    sale_order = relationship("SaleOrder")
    style_template = relationship("StyleTemplate")

class SaleOrder(Base):
    __tablename__ = 'sale_order'
    __table_args__ = {'extend_existing': True}

    SaleOrderID=Column(Integer, primary_key = True, autoincrement=False) 
    SaleOrderCode=Column(String(100))

    Customer=Column(String(64))
    OrderQuantity=Column(Integer)     
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  

class StyleTemplate(Base):
    __tablename__ = 'style_template'
    __table_args__ = {'extend_existing': True}

    StyleTemplateID=Column(Integer, primary_key = True, autoincrement=False) 
    StyleTemplateCode=Column(String(64))     
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  

class Marker(Base):
    __tablename__ = 'marker'
    __table_args__ = {'extend_existing': True}

    MarkerID=Column(Integer, primary_key = True, autoincrement=False) 
    MarkerCode=Column(String(64))    
    ProductionOrderID=Column(Integer, ForeignKey("production_order.ProductionOrderID"))
    MarkerMapping=Column(JSON)  
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    ProductionOrderCode=Column(String(64))
    
    SaleOrderID=Column(Integer, ForeignKey("sale_order.SaleOrderID"))
    StyleTemplateID=Column(Integer, ForeignKey("style_template.StyleTemplateID"))

    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(100))
    Customer=Column(String(64))
    OrderQuantity=Column(Integer)    
    
    StyleTemplateCode=Column(String(64))   
    
    # Size=Column(Integer) 
    # Inseam=Column(Integer) 
    # Ratio=Column(Integer) 


    production_order = relationship("ProductionOrder")
    sale_order = relationship("SaleOrder")
    style_template = relationship("StyleTemplate")


class CutJob(Base):
    __tablename__ = 'cut_job'
    __table_args__ = {'extend_existing': True}

    CutJobID=Column(Integer, primary_key = True, autoincrement=False) 
    CutNo=Column(Integer)
    ProductionOrderID=Column(Integer, ForeignKey("production_order.ProductionOrderID"))
    CutQuantity=Column(Integer)




    MarkerID=Column(Integer, ForeignKey("marker.MarkerID")) 
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer, ForeignKey("sale_order.SaleOrderID"))
    StyleTemplateID=Column(Integer, ForeignKey("style_template.StyleTemplateID"))
    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(100))
    Customer=Column(String(64))


    
    OrderQuantity=Column(Integer)    
    
    StyleTemplateCode=Column(String(64))   
    MarkerCode=Column(String(64))    
    
    MarkerMapping=Column(JSON)    

    production_order = relationship("ProductionOrder")
    sale_order = relationship("SaleOrder")
    style_template = relationship("StyleTemplate")
    marker = relationship("Marker")


class CutReport(Base):
    __tablename__ = 'cut_report'
    __table_args__ = {'extend_existing': True}

    BundleID=Column(Integer, primary_key = True, autoincrement=False)
    
    BundleCode=Column(String(64))
    BundleQuantity=Column(Integer)
    ScannedQuantity=Column(Integer)

    RemainingQuantity=Column(Integer)
    CutJobID=Column(Integer, ForeignKey("cut_job.CutJobID"))
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    CutNo=Column(Integer)
    ProductionOrderID=Column(Integer, ForeignKey("production_order.ProductionOrderID"))
    CutQuantity=Column(Integer)
    
    MarkerID=Column(Integer, ForeignKey("marker.MarkerID")) 
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer, ForeignKey("sale_order.SaleOrderID"))
    StyleTemplateID=Column(Integer, ForeignKey("style_template.StyleTemplateID"))
    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(100))
    
    Customer=Column(String(64))
    
    
    OrderQuantity=Column(Integer)    
    
    StyleTemplateCode=Column(String(64))   
    MarkerCode=Column(String(64))    
    MarkerMapping=Column(JSON)    

    cut_job = relationship("CutJob")
    production_order = relationship("ProductionOrder")
    sale_order = relationship("SaleOrder")
    style_template = relationship("StyleTemplate")
    marker = relationship("Marker")


class Operation(Base):
    __tablename__ = 'operation'
    __table_args__ = {'extend_existing': True}

    OperationID=Column(Integer, primary_key = True, autoincrement=False) 
    OperationCode=Column(String(64))    
    OperationName =Column(String(64))
    OperationDescription = Column(String(64))    
    Department = Column(String(64))
    PieceRate=Column(Integer)      

    OperationType=Column(String(64))
    OperationImageUrl=Column(String(2056))
    OperationThumbnailUrl=Column(String(2056))

    SectionID = Column(Integer, ForeignKey("section.SectionID"))
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    SectionCode=Column(String(64))
    SectionDescription=Column(String(64))    


    section = relationship("Section")

class Section(Base):
    __tablename__ = 'section'
    __table_args__ = {'extend_existing': True}

    SectionID=Column(Integer, primary_key = True, autoincrement=False) 
    SectionCode=Column(String(64))
    SectionDescription=Column(String(64))
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  

class PieceWiseCutReport(Base):
    __tablename__ = 'piece_wise_cut_report'
    __table_args__ = {'extend_existing': True}

    PieceID=Column(Integer, primary_key = True, autoincrement=False)
    BundleID=Column(Integer, ForeignKey("cut_report.BundleID"))
    PieceNumber=Column(Integer)
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    BundleCode=Column(String(64)) 
    BundleQuantity=Column(Integer)
    ScannedQuantity=Column(Integer)
    RemainingQuantity=Column(Integer)
    CutJobID=Column(Integer, ForeignKey("cut_job.CutJobID"))
    CutNo=Column(Integer) 
    ProductionOrderID=Column(Integer, ForeignKey("production_order.ProductionOrderID"))
    CutQuantity=Column(Integer)
    MarkerID=Column(Integer, ForeignKey("marker.MarkerID")) 
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer, ForeignKey("sale_order.SaleOrderID"))
    StyleTemplateID=Column(Integer, ForeignKey("style_template.StyleTemplateID"))
    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(100))
    Customer=Column(String(64))
    OrderQuantity=Column(Integer)    
    StyleTemplateCode=Column(String(64))   
    MarkerCode=Column(String(64))    
    MarkerMapping=Column(JSON)    

    production_order = relationship("ProductionOrder")
    sale_order = relationship("SaleOrder")
    style_template = relationship("StyleTemplate")
    marker = relationship("Marker")
    cut_report = relationship("CutReport")
    cut_job = relationship("CutJob")    


class Scan(Base):
    __tablename__ = 'scan'
    __table_args__ = {'extend_existing': True}

    ScanID=Column(BIGINT, primary_key = True, autoincrement=False)
    ShortAddress=Column(String(64)) 
    LongAddress=Column(String(64)) 
    HostIP=Column(String(64)) 
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    LineID=Column(Integer,ForeignKey("line.LineID"))
    LineCode=Column(String(64))
    LineDescription=Column(String(64)) 
    WorkerID =Column(Integer, ForeignKey("worker.WorkerID"))
    WorkerCode=Column(String(64))
    WorkerDescription=Column(String(64))    
    WorkerImageUrl=Column(String(2056)) 
    WorkerThumbnailUrl=Column(String(2056)) 
    AllocatedMachines=Column(JSON)
    BundleID=Column(Integer, ForeignKey("cut_report.BundleID"))
    BundleCode=Column(String(64)) 
    BundleQuantity=Column(Integer)
    ScannedQuantity=Column(Integer)
    RemainingQuantity=Column(Integer)
    CutJobID=Column(Integer, ForeignKey("cut_job.CutJobID"))
    CutNo=Column(Integer) 
    ProductionOrderID=Column(Integer, ForeignKey("production_order.ProductionOrderID"))
    CutQuantity=Column(Integer)
    MarkerID=Column(Integer, ForeignKey("marker.MarkerID")) 
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer, ForeignKey("sale_order.SaleOrderID"))
    StyleTemplateID=Column(Integer, ForeignKey("style_template.StyleTemplateID"))
    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(100))
    Customer=Column(String(64))
    OrderQuantity=Column(Integer)    
    StyleTemplateCode=Column(String(64))   
    MarkerCode=Column(String(64))    
    MarkerMapping=Column(JSON)    
    MachineID=Column(Integer,ForeignKey("machine.MachineID"))
    MachineCode=Column(String(64))
    MachineDescription=Column(String(64))
    MachineImageUrl=Column(String(2056)) 
    MachineThumbnailUrl=Column(String(2056))
    MachineTypeID=Column(Integer)
    ActiveWorkerID=Column(Integer)
    Operations=Column(JSON)
    BoxID=Column(Integer)
    MachineTypeCode=Column(String(64)) 
    MachineTypeDescription=Column(String(64)) 
    Allowance=Column(Float)
    OperationID=Column(Integer,ForeignKey("operation.OperationID"))
    OperationCode=Column(String(64))
    OperationName=Column(String(64))
    OperationDescription=Column(String(64))
    Department=Column(String(64))
    PieceRate=Column(Integer)
    OperationType=Column(String(64))
    OperationImageUrl=Column(String(2056))
    OperationThumbnailUrl=Column(String(2056))
    SectionID=Column(Integer, ForeignKey("section.SectionID"))
    SectionCode=Column(String(64))
    SectionDescription=Column(String(64))
    PieceID=Column(Integer)
    PieceNumber=Column(Integer)
    WorkerScanID=Column(BIGINT, ForeignKey("worker_scan.WorkerScanID")) 
    WorkerOperations=Column(JSON)
    HasExpired=Column(Integer)
    EndedAt=Column(DateTime) 


    section = relationship("Section")
    operation = relationship("Operation")

    production_order = relationship("ProductionOrder")
    sale_order = relationship("SaleOrder")
    style_template = relationship("StyleTemplate")
    marker = relationship("Marker")
    cut_report = relationship("CutReport")
    cut_job = relationship("Cutjob")
    machine = relationship("Machine")
    line = relationship("Line")
    worker = relationship("Worker")    
    worker_scan = relationship("WorkerScan")        

class ScanGroup(Base):
    __tablename__ = 'scan_group'
    __table_args__ = {'extend_existing': True}

    GroupID=Column(Integer, primary_key = True, autoincrement=False) 
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
class PieceWiseScan(Base):
    __tablename__ = 'piece_wise_scan'
    __table_args__ = {'extend_existing': True}

    PieceWiseScanningID=Column(Integer, primary_key = True, autoincrement=False)
    WorkerID =Column(Integer, ForeignKey("worker.WorkerID"))
    LineID=Column(Integer,ForeignKey("line.LineID"))
    MachineID=Column(Integer,ForeignKey("machine.MachineID"))
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    PieceID=Column(Integer, ForeignKey("piece_wise_cut_report.PieceID"))
    PieceNumber=Column(Integer)
    BundleCode=Column(String(64)) 
    BundleQuantity=Column(Integer)
    ScannedQuantity=Column(Integer)
    RemainingQuantity=Column(Integer)
    CutJobID=Column(Integer, ForeignKey("cut_job.CutJobID"))
    CutNo=Column(Integer)
    ProductionOrderID=Column(Integer, ForeignKey("production_order.ProductionOrderID"))
    CutQuantity=Column(Integer)
    MarkerID=Column(Integer, ForeignKey("marker.MarkerID")) 
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer, ForeignKey("sale_order.SaleOrderID"))
    StyleTemplateID=Column(Integer, ForeignKey("style_template.StyleTemplateID"))
    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(100))
    Customer=Column(String(64))
    OrderQuantity=Column(Integer)    
    StyleTemplateCode=Column(String(64))   
    MarkerCode=Column(String(64))    
    MarkerMapping=Column(JSON)    
    OperationID=Column(Integer, ForeignKey("operation.OperationID")) 
    OperationCode=Column(String(64))    
    OperationName =Column(String(64))
    OperationDescription = Column(String(64))      
    Department = Column(String(64))
    PieceRate=Column(Integer)      
    OperationType=Column(String(64))
    OperationImageUrl=Column(String(2056))
    OperationThumbnailUrl=Column(String(2056))
    SectionID = Column(Integer, ForeignKey("section.SectionID"))
    SectionCode=Column(String(64))
    SectionDescription=Column(String(64))    
    ScanID=Column(BIGINT, ForeignKey("scan.ScanID"))

    ShortAddress=Column(String(64)) 
    LongAddress=Column(String(64)) 
    HostIP=Column(String(64)) 
    LineCode=Column(String(64))
    LineDescription=Column(String(64)) 
    WorkerCode=Column(String(64))
    WorkerDescription=Column(String(64)) 
    WorkerImageUrl=Column(String(2056)) 
    WorkerThumbnailUrl=Column(String(2056)) 
    AllocatedMachines=Column(JSON)
    MachineCode=Column(String(64))
    MachineDescription=Column(String(64))
    MachineImageUrl=Column(String(2056)) 
    MachineThumbnailUrl=Column(String(2056))
    MachineTypeID=Column(Integer)
    ActiveWorkerID=Column(Integer)
    Operations=Column(JSON)
    BoxID=Column(Integer)
    
    IsMachineDown=Column(Boolean)
    MachineTypeCode=Column(String(64)) 
    MachineTypeDescription=Column(String(64)) 
    Allowance=Column(Float)
    WorkerScanID=Column(BIGINT, ForeignKey("worker_scan.WorkerScanID")) 
    WorkerOperations=Column(JSON)
    HasExpired=Column(Integer)
    EndedAt=Column(DateTime) 
    BundleID=Column(Integer, ForeignKey("cut_report.BundleID"))

    PieceWiseGroupID=Column(Integer) 
    GroupName=Column(String(1024))  
    GroupID=Column(Integer,ForeignKey("scan_group.GroupID"))

    production_order = relationship("ProductionOrder")
    sale_order = relationship("SaleOrder")
    style_template = relationship("StyleTemplate")
    marker = relationship("Marker")
    cut_report = relationship("CutReport")
    cut_job = relationship("Cutjob")
    machine = relationship("Machine")
    line = relationship("Line")
    worker = relationship("Worker")    
    worker_scan = relationship("WorkerScan")
    scan_group = relationship("ScanGroup") 
    piece_wise_cut_report = relationship("PieceWiseCutReport")     
    operation = relationship("Operation")            
    section = relationship("Section")  


class Module(Base):
    __tablename__ = 'module'
    __table_args__ = {'extend_existing': True}

    ModuleID=Column(Integer, primary_key = True, autoincrement=False) 
    ModuleCode=Column(String(64))
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
class StyleBulletin(Base):
    __tablename__ = 'style_bulletin'
    __table_args__ = {'extend_existing': True}

    StyleBulletinID=Column(Integer, primary_key = True, autoincrement=False) 
   
    StyleTemplateID=Column(Integer,ForeignKey("style_template.StyleTemplateID"))
    OperationID=Column(Integer, ForeignKey("operation.OperationID")) 
    OperationSequence=Column(Integer)    
   
    ScanType=Column(String(10))
    IsFirst=Column(Boolean)
    IsLast=Column(Boolean)

    MachineTypeID=Column(Integer, ForeignKey("machine_type.MachineTypeID"))
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
   
    StyleTemplateCode=Column(String(64))

    OperationCode=Column(String(64))    
    OperationName =Column(String(64))
    OperationDescription = Column(String(64))    
    Department = Column(String(64))
    PieceRate=Column(Float)      
    OperationType=Column(String(64))
    OperationImageUrl=Column(String(2056))
    OperationThumbnailUrl=Column(String(2056))
    SectionID = Column(Integer, ForeignKey("section.SectionID"))
    SectionCode=Column(String(64))
    SectionDescription=Column(String(64))    

    MachineTypeCode=Column(String(64))
    MachineTypeDescription=Column(String(64))
    Allowance=Column(Float)


    style_template = relationship("StyleTemplate")
    operation = relationship("Operation")
    section = relationship("Section")
    machine_type = relationship("MachineType")
class Tag(Base):
    __tablename__ = 'tag'
    __table_args__ = {'extend_existing': True}

    TagID=Column(Integer, primary_key = True, autoincrement=False) 
    
    BundleID=Column(Integer, ForeignKey("cut_report.BundleID"))
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  
    #COLUMN ADDED LATER
    PieceID=Column(Integer)
    GroupID=Column(Integer,ForeignKey("scan_group.GroupID"))
    
    BundleCode=Column(String(64))

    BundleQuantity=Column(Integer)
    ScannedQuantity=Column(Integer)
    RemainingQuantity=Column(Integer)
    CutJobID=Column(Integer, ForeignKey("cut_job.CutJobID"))
    CutNo=Column(Integer) 
    ProductionOrderID=Column(Integer, ForeignKey("production_order.ProductionOrderID"))
    CutQuantity=Column(Integer)



    MarkerID=Column(Integer, ForeignKey("marker.MarkerID")) 
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer, ForeignKey("sale_order.SaleOrderID"))
    StyleTemplateID=Column(Integer, ForeignKey("style_template.StyleTemplateID"))
    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(100))

    Customer=Column(String(64))

    OrderQuantity=Column(Integer)    
    StyleTemplateCode=Column(String(64))   
    MarkerCode=Column(String(64))    
    
    
    
    MarkerMapping=Column(JSON) 


    cut_report = relationship("CutReport")
    cut_job = relationship("CutJob")
    marker = relationship("Marker")
    production_order = relationship("ProdcutionOrder")
    sale_order = relationship("SaleOrder")
    style_template = relationship("StyleTemplate")


    scan_group = relationship("ScanGroup")
class User(Base):
    __tablename__ = 'user'
    __table_args__ = {'extend_existing': True}

    UserID=Column(Integer, primary_key = True, autoincrement=False) 
    UserName=Column(String(64))
    Password=Column(String(1024))    
    UserType=Column(String(64))

    LineID=Column(Integer,ForeignKey("line.LineID"))
    SectionID=Column(Integer,ForeignKey("section.SectionID")) 
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  


    LineCode=Column(String(64))
    LineDescription=Column(String(64))

    SectionCode=Column(String(64))
    SectionDescription=Column(String(64))


    line = relationship("Line")
    section = relationship("Section")

class UserPermission(Base):
    __tablename__ = 'userpermission'
    __table_args__ = {'extend_existing': True}

    UserPermissionID=Column(Integer, primary_key = True, autoincrement=False) 
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)  

    ModuleID=Column(Integer, ForeignKey("module.ModuleID"))    
    ModuleCode=Column(String(64))
    UserID=Column(Integer,ForeignKey("user.UserID")) 
    

    UserName=Column(String(64))
    Password=Column(String(1024))    
    UserType=Column(String(64))
    LineID=Column(Integer,ForeignKey("line.LineID"))
    SectionID=Column(Integer,ForeignKey("section.SectionID")) 
    LineCode=Column(String(64))
    LineDescription=Column(String(64))
    SectionCode=Column(String(64))
    SectionDescription=Column(String(64))


    user = relationship("User")
    module = relationship("Module")
    line = relationship("Line")
    section = relationship("Section")<jupyter_output><empty_output><jupyter_text>New tables<jupyter_code>class Box(Base):
    __tablename__ = 'box'
    __table_args__ = {'extend_existing': True}

    BoxID=Column(Integer, primary_key = True, autoincrement=False) 
    BoxCode=Column(String(64)) 

    IssueDate=Column(DateTime)
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime) 
  
class PieceWiseGroup(Base):
    __tablename__ = 'piece_wise_group'
    __table_args__ = {'extend_existing': True}

    PieceWiseGroupID=Column(Integer, primary_key = True, autoincrement=False) 
    BundleID=Column(Integer)
    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)

    GroupName=Column(String(1024))    
    GroupID=Column(Integer,ForeignKey("scan_group.GroupID"))
    PieceID=Column(Integer,ForeignKey("piece_wise_cut_report.PieceID"))

    PieceNumber=Column(Integer) 
    BundleCode=Column(String(64))
    BundleQuantity=Column(Integer)

    ScannedQuantity=Column(Integer)
    RemainingQuantity=Column(Integer)
    CutJobID=Column(Integer)
        
    CutNo=Column(Integer)
    ProductionOrderID=Column(Integer)
    CutQuantity=Column(Integer)
    
    MarkerID=Column(Integer)
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer)

    StyleTemplateID=Column(Integer)


    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(64))
    Customer=Column(String(64))        

    OrderQuantity=Column(Integer)
    StyleTemplateCode=Column(String(64))        

    MarkerCode=Column(String(64))
    MarkerMapping=Column(JSON)        


    piece_wise_cut_report = relationship("PieceWiseCutReport")
    scan_group = relationship("ScanGroup")
class MachineDownTime(Base):
    __tablename__ = 'machine_down_time'
    __table_args__ = {'extend_existing': True}

    MachineDownTimeID=Column(Integer, primary_key = True, autoincrement=False) 
    DownReason=Column(String(64))
    StartTime=Column(DateTime) 
    EndTime=Column(DateTime)

    CreatedAt=Column(DateTime)    
    UpdatedAt=Column(DateTime)
    MachineID=Column(Integer,ForeignKey("machine.MachineID"))

    MachineCode=Column(String(64)) 
    MachineDescription=Column(String(64))
    MachineImageUrl=Column(String(64))

    MachineThumbnailUrl=Column(String(64))
    MachineTypeID=Column(Integer)
    ActiveWorkerID=Column(Integer)
    LineID=Column(Integer)
    Operations=Column(JSON)
    BoxID=Column(Integer)
    IsMachineDown=Column(Boolean)
    
    LineCode=Column(String(64))


    LineDescription=Column(String(64))
    WorkerID=Column(Integer)

    WorkerCode=Column(String(64))      

    WorkerDescription=Column(String(64))
    WorkerImageUrl=Column(String(64))

    WorkerThumbnailUrl=Column(String(64))      

    AllocatedMachines=Column(Boolean)
    MachineTypeCode=Column(String(64))

    MachineTypeDescription=Column(String(64))      
    Allowance=Column(Float)

    machine = relationship("Machine")
class LineLayout(Base):
    __tablename__ = 'line_layout'
    __table_args__ = {'extend_existing': True}

    LineLayoutID=Column(Integer, primary_key = True, autoincrement=False) 
    RevisionNo=Column(Integer)
    LineLayoutDate=Column(DateTime) 
    LineLayoutStatus=Column(String(64))

    LineLayoutOperationMachines=Column(JSON)   

    IsAnyMachines=Column(Boolean)
    ParentLineLayoutID=Column(Integer)

    CreatedAt=Column(DateTime) 
    UpdatedAt=Column(DateTime)
    LineID=Column(Integer,ForeignKey("line.LineID"))

    LineCode=Column(String(64))
    LineDescription=Column(String(64))
    ProductionOrderID=Column(Integer,ForeignKey("production_order.ProductionOrderID"))
        
    ProductionOrderCode=Column(String(64))
    SaleOrderID=Column(Integer)
    StyleTemplateID=Column(Integer)
    
    IsFollowOperationSequence=Column(Boolean)
    SaleOrderCode=Column(String(64))
    Customer=Column(String(64))

    OrderQuantity=Column(Integer)


    StyleTemplateCode=Column(String(64))
     


    line = relationship("Line")
    production_order = relationship("ProductionOrder")<jupyter_output><empty_output><jupyter_text>Creating tables in postgres<jupyter_code>Base.metadata.create_all(engine_postgres)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11274683275532593, 'fraction_numerical': 0.01666784627362163, 'mean_word_length': 5.234061328038826, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '176557', 'license': 'MIT', 'n_tokens_mistral': 8869, 'n_tokens_neox': 8271, 'n_words': 1031, 'path': 'DataEngineering/flaskapp/create_models.ipynb', 'repo_name': 'SyedArsalanAmin/datascience-projects', 'size': '28257'}