Update db.py just contain engine and create database.
This commit is contained in:
+5
-22
@@ -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 sqlmodel import SQLModel, create_engine
|
||||||
# from sqlalchemy.ext.automap import automap_base
|
|
||||||
from sqlmodel import BigInteger, Column, Field, SQLModel, create_engine
|
|
||||||
from utilities import config
|
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":
|
if config.ENVIRONMENT == "prod":
|
||||||
url = f"mysql+pymysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
|
url = f"mysql+pymysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}"
|
||||||
else:
|
else:
|
||||||
url = "sqlite:///database.db"
|
url = "sqlite:///database.db"
|
||||||
engine = create_engine(url)
|
engine = create_engine(url)
|
||||||
SQLModel.metadata.create_all(engine)
|
|
||||||
# Base = automap_base()
|
|
||||||
# Base.prepare(autoload_with=engine)
|
|
||||||
|
|
||||||
# # define the classes
|
# Don't need to create all when connected to prod.
|
||||||
# Category = Base.classes.Categories
|
SQLModel.metadata.create_all(engine)
|
||||||
# CategoryGroup = Base.classes.CategoryGroups
|
|
||||||
# Guild = Base.classes.Guilds
|
|
||||||
# Score = Base.classes.Scores
|
|
||||||
# Submission = Base.classes.Submissions
|
|
||||||
|
|||||||
Reference in New Issue
Block a user