From 36eae177516d45c9c7dc123c9420787ca6281e25 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Mon, 3 Mar 2025 15:16:24 -0500 Subject: [PATCH] Update db.py just contain engine and create database. --- database_setup/db.py | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/database_setup/db.py b/database_setup/db.py index a9147b9..8c3d97d 100644 --- a/database_setup/db.py +++ b/database_setup/db.py @@ -1,32 +1,15 @@ -"""Simple file to set up the sqlalchemy connection to database.""" +"""Simple file to set up the sqlmodel connection to database.""" -# from sqlalchemy import create_engine -# from sqlalchemy.ext.automap import automap_base -from sqlmodel import BigInteger, Column, Field, SQLModel, create_engine +from sqlmodel import SQLModel, create_engine from utilities import config +from . import models # noqa: F401 Need this import for creating the models. -class Guilds(SQLModel, table=True): - id: int = Field(sa_column=Column(BigInteger(), primary_key=True)) - name: str - submission_channel: int = Field(sa_column=Column(BigInteger())) - verification_channel: int = Field(sa_column=Column(BigInteger())) - active: bool = Field(default=True) - - -# connect with sql alchemy and autoload schema if config.ENVIRONMENT == "prod": url = f"mysql+pymysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}" else: url = "sqlite:///database.db" engine = create_engine(url) -SQLModel.metadata.create_all(engine) -# Base = automap_base() -# Base.prepare(autoload_with=engine) -# # define the classes -# Category = Base.classes.Categories -# CategoryGroup = Base.classes.CategoryGroups -# Guild = Base.classes.Guilds -# Score = Base.classes.Scores -# Submission = Base.classes.Submissions +# Don't need to create all when connected to prod. +SQLModel.metadata.create_all(engine)