Spaces:
Sleeping
Sleeping
| import os | |
| import dotenv | |
| from config.constant import EnvPostgresConstants, EnvFilepath | |
| dotenv.load_dotenv(EnvFilepath.ENVPATH) | |
| from externals.databases.pg_models import Base | |
| from sqlalchemy import create_engine, text | |
| from utils.logger import get_logger | |
| logger = get_logger("init schema") | |
| def create_tables(): | |
| try: | |
| DATABASE_URL = EnvPostgresConstants.CONSTRING | |
| engine = create_engine(DATABASE_URL) | |
| # Create extension | |
| with engine.connect() as conn: | |
| conn.execute(text('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";')) | |
| conn.commit() | |
| # Create tables | |
| Base.metadata.create_all(engine) | |
| logger.info("✅ init schema success") | |
| except Exception as E: | |
| logger.error(f"❌ init schema failed, {E}") | |
| if __name__ == "__main__": | |
| create_tables() |