class RunTicket(DataFrameMixin, db.Model): __tablename__ = "run_tickets" __table_args__ = ( db.ForeignKeyConstraint( ["tank_id", "reading_id"], [f"tank_readings.tank_id", f"tank_readings.id"]), # {"schema": schema}, ) id = db.Column(db.Integer, primary_key=True, nullable=False) tank_id = db.Column(db.Integer, nullable=False) reading_id = db.Column(db.Integer, nullable=False) ticket_date = db.Column(db.Date(), nullable=False) run_ticket_number = db.Column(db.String(), nullable=True, default="") total = db.Column(db.Float, nullable=True) product_type = db.Column(db.String(), nullable=True, default="") picture_url = db.Column(db.String(), nullable=True, default="") comments = db.Column(db.String(), nullable=True, default="") updated_by = db.Column(db.Integer, nullable=True) iwell_created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False)
class Well(DataFrameMixin, db.Model): __tablename__ = "wells" # __table_args__ = {"schema": schema} id = db.Column(db.Integer, primary_key=True, nullable=False) well_name = db.Column(db.String(), nullable=True) well_type = db.Column(db.String(), nullable=True) well_alias = db.Column(db.String(), nullable=True) is_active = db.Column(db.Boolean(), default=False, nullable=False) latest_production_time = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) groups = db.relationship("WellGroupWell", backref="well", lazy=True) meters = db.relationship("Meter", backref="well", lazy=True) # meter_readings = db.relationship("MeterReading", backref="well", lazy=True) notes = db.relationship("WellNote", backref="well", lazy=True) fields = db.relationship("WellField", backref="well", lazy=True) # field_values = db.relationship("FieldValue", backref="well", lazy=True) production = db.relationship("Production", backref="well", lazy=True)
class Field(DataFrameMixin, db.Model): __tablename__ = "fields" # __table_args__ = {"schema": schema} id = db.Column(db.Integer, primary_key=True, nullable=False) field_name = db.Column(db.String(), nullable=True) field_type = db.Column(db.String(), nullable=True) field_unit = db.Column(db.String(), nullable=True) field_order = db.Column(db.Integer, nullable=True) is_historic = db.Column(db.Boolean(), default=False, nullable=False) is_remembered = db.Column(db.Boolean(), default=False, nullable=False) is_required = db.Column(db.Boolean(), default=False, nullable=False) iwell_created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) well_fields = db.relationship("WellField", backref="field", lazy=True)
class Meter(DataFrameMixin, db.Model): __tablename__ = "meters" # __table_args__ = {"schema": schema} id = db.Column(db.Integer, primary_key=True, nullable=False) well_id = db.Column(db.Integer, db.ForeignKey(f"wells.id"), primary_key=True, nullable=False) meter_name = db.Column(db.String(), nullable=True) meter_order = db.Column(db.Integer, nullable=True) product_type = db.Column(db.String(), nullable=True) iwell_created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) readings = db.relationship("MeterReading", backref="meter", lazy=True)
class FieldValue(DataFrameMixin, db.Model): __tablename__ = "field_values" __table_args__ = ( db.ForeignKeyConstraint( ["field_id", "well_id"], [f"well_fields.field_id", f"well_fields.well_id"]), # {"schema": schema}, ) id = db.Column(db.Integer, primary_key=True, nullable=False) field_id = db.Column(db.Integer, nullable=False) well_id = db.Column(db.Integer, nullable=False) reading_at = db.Column(db.DateTime(timezone=True), nullable=False) value = db.Column(db.String(), nullable=False) updated_by = db.Column(db.Integer, nullable=True) iwell_created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False)
class WellNote(DataFrameMixin, db.Model): __tablename__ = "well_notes" # __table_args__ = {"schema": schema} id = db.Column(db.Integer, primary_key=True, nullable=False) well_id = db.Column(db.Integer, db.ForeignKey(f"wells.id"), primary_key=True, nullable=False) noted_at = db.Column(db.DateTime(timezone=True), nullable=False) # note_time message = db.Column(db.String(), nullable=True) author = db.Column(db.Integer, db.ForeignKey(f"users.id"), nullable=True) is_pumper_content = db.Column(db.Boolean) iwell_created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False)
class User(DataFrameMixin, db.Model): __tablename__ = "users" # __table_args__ = {"schema": schema} id = db.Column(db.Integer, primary_key=True, nullable=False) name = db.Column(db.String(), nullable=False) email = db.Column(db.String(), nullable=True) phone = db.Column(db.String(), nullable=True) user_type = db.Column(db.String(), nullable=True) # type status = db.Column(db.String(), nullable=True) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False)
class IntegrationLog(DataFrameMixin, db.Model): __tablename__ = "integration_log" # __table_args__ = {"schema": schema} id = db.Column(db.Integer, primary_key=True, nullable=False) integrated_at = db.Column(db.DateTime(timezone=True), nullable=False) model_name = db.Column(db.String(), nullable=False) inserts = db.Column(db.Integer(), nullable=False, default=0) updates = db.Column(db.Integer(), nullable=False, default=0) deletes = db.Column(db.Integer(), nullable=False, default=0) updated_by = db.Column(db.String(), default=func.current_user(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False)
class Tank(DataFrameMixin, db.Model): __tablename__ = "tanks" # __table_args__ = {"schema": schema} id = db.Column(db.Integer, primary_key=True, nullable=False) tank_name = db.Column(db.String(), nullable=True) tank_type = db.Column(db.String(), nullable=True) capacity = db.Column(db.Integer, nullable=True) multiplier = db.Column(db.Float, nullable=True) iwell_created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) readings = db.relationship("TankReading", backref="tank", lazy=True)
class WellGroup(DataFrameMixin, db.Model): __tablename__ = "well_groups" # __table_args__ = {"schema": schema} id = db.Column(db.Integer, primary_key=True, nullable=False) group_name = db.Column(db.String(), nullable=True) is_active = db.Column(db.Boolean(), default=False, nullable=False) group_latest_production_time = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) iwell_updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) created_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), default=func.now(), nullable=False) wells = db.relationship("WellGroupWell", backref="well_group", lazy=True)