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 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)
|
||||
|
||||
Reference in New Issue
Block a user