PauloFN/draft-estimation
0
1from sqlalchemy import create_engine, Column, Integer, String, Float, DateTime, LargeBinary2from sqlalchemy.ext.declarative import declarative_base3from sqlalchemy.orm import sessionmaker4 5# Define the database connection URL6DATABASE_URL = "sqlite:////tmp/ship_draft_reports.db"7 8# Create the SQLAlchemy engine9engine = create_engine(10 DATABASE_URL, connect_args={"check_same_thread": False} # check_same_thread is for SQLite only11)12 13# Create a session factory14SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)15 16# Create a base class for declarative models17Base = declarative_base()18 19# Define the Report model20class Report(Base):21 __tablename__ = "reports"22 23 id = Column(Integer, primary_key=True, index=True)24 ship_id = Column(String, index=True)25 timestamp = Column(DateTime)26 latitude = Column(Float)27 longitude = Column(Float)28 draft_measurement = Column(Float)29 confidence_score = Column(Float) # New field30 pdf_path = Column(String, unique=True)31 image_bytes = Column(LargeBinary) # New field32 33def create_db_and_tables():34 """Function to create the database and tables."""35 Base.metadata.create_all(bind=engine)36 