diff --git a/.gitignore b/.gitignore index 4defef7..87899b1 100644 --- a/.gitignore +++ b/.gitignore @@ -135,3 +135,4 @@ deleted_backups/ highscores_data/ TODO.txt sql_tester.py +database.db diff --git a/database_setup/database_test.py b/database_setup/database_test.py new file mode 100644 index 0000000..ab3d577 --- /dev/null +++ b/database_setup/database_test.py @@ -0,0 +1,14 @@ +from sqlmodel import BigInteger, Column, Field, SQLModel, create_engine + + +class Guilds(SQLModel, table=True): + id: int = Field(sa_column=Column(BigInteger(), primary_key=True)) + name: str = Field(max_length=95) + submission_channel: int = Field(sa_column=Column(BigInteger())) + verification_channel: int = Field(sa_column=Column(BigInteger())) + active: bool = Field(default=True) + + +url = "sqlite:///database.db" +engine = create_engine(url) +SQLModel.metadata.create_all(engine) diff --git a/database_setup/sql_data_classes.py b/database_setup/sql_data_classes.py index 25d42d5..a9147b9 100644 --- a/database_setup/sql_data_classes.py +++ b/database_setup/sql_data_classes.py @@ -1,18 +1,32 @@ """Simple file to set up the sqlalchemy connection to database.""" -from sqlalchemy import create_engine -from sqlalchemy.ext.automap import automap_base +# from sqlalchemy import create_engine +# from sqlalchemy.ext.automap import automap_base +from sqlmodel import BigInteger, Column, Field, SQLModel, create_engine from utilities import config -# connect with sql alchemy and autoload schema -url = f"mysql+pymysql://{config.SQL_USER}:{config.SQL_PASS}@{config.SQL_HOST}/{config.SQL_DB}" -engine = create_engine(url) -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 +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 diff --git a/utilities/config.py b/utilities/config.py index dcba7ca..baf0aac 100644 --- a/utilities/config.py +++ b/utilities/config.py @@ -1,6 +1,4 @@ -""" -Loads environment variables for use in bot. -""" +"""Loads environment variables for use in bot.""" import os @@ -15,3 +13,4 @@ SQL_DB = os.getenv("SQL_DB", "") SQL_HOST = os.getenv("SQL_HOST", "") SQL_PASS = os.getenv("SQL_PASS", "") SQL_USER = os.getenv("SQL_USER", "") +ENVIRONMENT: str = os.getenv("ENVIRONMENT", "prod")