Add SnakeCase column names that are already in database.
This commit is contained in:
Vendored
+8
-1
@@ -1,5 +1,12 @@
|
||||
{
|
||||
"cSpell.words": ["gmtime", "highscore", "highscores", "imcompiling", "nextcord"],
|
||||
"cSpell.words": [
|
||||
"gmtime",
|
||||
"highscore",
|
||||
"highscores",
|
||||
"imcompiling",
|
||||
"nextcord",
|
||||
"ondelete"
|
||||
],
|
||||
"python.analysis.diagnosticSeverityOverrides": {
|
||||
"reportOptionalMemberAccess": false,
|
||||
"reportArgumentType": "information",
|
||||
|
||||
+23
-12
@@ -1,19 +1,30 @@
|
||||
from sqlmodel import Session, SQLModel, create_engine, select
|
||||
import os
|
||||
|
||||
from models import Guild
|
||||
from dotenv import load_dotenv
|
||||
from sqlmodel import Session, SQLModel, create_engine
|
||||
|
||||
from models import CategoryGroup, Guild
|
||||
|
||||
load_dotenv()
|
||||
|
||||
SQL_DB = os.getenv("SQL_DB", "")
|
||||
SQL_HOST = os.getenv("SQL_HOST", "")
|
||||
SQL_PASS = os.getenv("SQL_PASS", "")
|
||||
SQL_USER = os.getenv("SQL_USER", "")
|
||||
|
||||
url = "sqlite:///database.db"
|
||||
# url = f"mysql+pymysql://{SQL_USER}:{SQL_PASS}@{SQL_HOST}/{SQL_DB}"
|
||||
engine = create_engine(url)
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
with Session(engine) as session:
|
||||
# guild = Guild(id=1, name="test guild", submission_channel=1, verification_channel=2)
|
||||
# session.add(guild)
|
||||
# group1 = CategoryGroup(name="group1", channel_id=1, guild_id=1, message_id=1)
|
||||
# group2 = CategoryGroup(name="group2", channel_id=2, guild_id=1, message_id=2)
|
||||
# session.add(group1)
|
||||
# session.add(group2)
|
||||
# session.commit()
|
||||
guild = Guild(id=1, name="test guild", submission_channel=1, verification_channel=2)
|
||||
session.add(guild)
|
||||
group1 = CategoryGroup(name="group1", channel_id=1, guild_id=1, message_id=1)
|
||||
group2 = CategoryGroup(name="group2", channel_id=2, guild_id=1, message_id=2)
|
||||
session.add(group1)
|
||||
session.add(group2)
|
||||
session.commit()
|
||||
|
||||
# anotherone = Guild(id=2, name="test guild 2", submission_channel=1, verification_channel=2)
|
||||
# session.add(anotherone)
|
||||
@@ -23,7 +34,7 @@ with Session(engine) as session:
|
||||
# session.add(group2)
|
||||
# session.commit()
|
||||
|
||||
stmt = select(Guild).where(Guild.id == 1)
|
||||
guild = session.scalar(stmt)
|
||||
# stmt = select(Guild)
|
||||
# guild = session.scalars(stmt)
|
||||
|
||||
print(guild.category_groups)
|
||||
# print(guild)
|
||||
|
||||
+33
-28
@@ -1,6 +1,6 @@
|
||||
"""File holds all model definitions of SQL tables."""
|
||||
|
||||
from sqlalchemy.dialects.mysql import BIGINT, INTEGER, SMALLINT
|
||||
from sqlalchemy.dialects.mysql import BIGINT, BOOLEAN, FLOAT, INTEGER, SMALLINT, VARCHAR
|
||||
from sqlmodel import Column, Field, ForeignKey, Relationship, SQLModel, UniqueConstraint
|
||||
|
||||
|
||||
@@ -19,12 +19,12 @@ class Guild(SQLModel, table=True):
|
||||
|
||||
__tablename__: str = "Guilds"
|
||||
|
||||
id: int = Field(sa_column=Column(BIGINT(unsigned=True), primary_key=True, nullable=False))
|
||||
name: str = Field(max_length=95)
|
||||
id: int = Field(sa_column=Column("GuildId", BIGINT(unsigned=True), primary_key=True, nullable=False))
|
||||
name: str = Field(sa_column=Column("GuildName", VARCHAR), max_length=95)
|
||||
# deprecated, not currently used.
|
||||
submission_channel: int = Field(sa_column=Column(BIGINT(unsigned=True)))
|
||||
verification_channel: int = Field(sa_column=Column(BIGINT(unsigned=True)))
|
||||
active: bool = Field(default=True)
|
||||
submission_channel: int = Field(sa_column=Column("SubmissionChannel", BIGINT(unsigned=True)))
|
||||
verification_channel: int = Field(sa_column=Column("VerificationChannel", BIGINT(unsigned=True)))
|
||||
active: bool = Field(sa_column=Column("Active", BOOLEAN()), default=True)
|
||||
|
||||
category_groups: list["CategoryGroup"] = Relationship(back_populates="guild", cascade_delete=True)
|
||||
|
||||
@@ -49,19 +49,20 @@ class CategoryGroup(SQLModel, table=True):
|
||||
|
||||
__tablename__: str = "CategoryGroups"
|
||||
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
name: str = Field(max_length=50)
|
||||
channel_id: int = Field(sa_column=Column(BIGINT(unsigned=True)))
|
||||
id: int | None = Field(sa_column=Column("GroupId", INTEGER, primary_key=True), default=None)
|
||||
name: str = Field(sa_column=Column("GroupName", VARCHAR), max_length=50)
|
||||
channel_id: int = Field("ChannelId", sa_column=Column(BIGINT(unsigned=True)))
|
||||
guild_id: int = Field(
|
||||
sa_column=Column(
|
||||
"GuildId",
|
||||
BIGINT(unsigned=True),
|
||||
ForeignKey("Guilds.id", ondelete="CASCADE"),
|
||||
ForeignKey("Guilds.GuildId", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
)
|
||||
)
|
||||
message_id: int = Field(sa_column=Column(BIGINT(unsigned=True)))
|
||||
pad_length: int = Field(default=12, sa_column=Column(SMALLINT(unsigned=True)))
|
||||
username_length: int = Field(default=12, sa_column=Column(SMALLINT(unsigned=True)))
|
||||
message_id: int = Field(sa_column=Column("MessageId", BIGINT(unsigned=True)))
|
||||
pad_length: int = Field(default=12, sa_column=Column("PadLength", SMALLINT(unsigned=True)))
|
||||
username_length: int = Field(default=12, sa_column=Column("UsernameLength", SMALLINT(unsigned=True)))
|
||||
|
||||
__table_args__ = (UniqueConstraint("guild_id", "name", name="UniqueGuildCategoryGroup"),)
|
||||
|
||||
@@ -91,19 +92,20 @@ class Category(SQLModel, table=True):
|
||||
|
||||
__tablename__: str = "Categories"
|
||||
|
||||
id: int = Field(default=None, primary_key=True)
|
||||
name: str = Field(max_length=30)
|
||||
id: int = Field(sa_column=Column("CategoryId", INTEGER, primary_key=True), default=None)
|
||||
name: str = Field(sa_column=Column("CategoryName", VARCHAR), max_length=30)
|
||||
group_id: int = Field(
|
||||
sa_column=Column(
|
||||
"GroupId",
|
||||
INTEGER(unsigned=True),
|
||||
ForeignKey("CategoryGroups.id", ondelete="CASCADE"),
|
||||
ForeignKey("CategoryGroups.GroupId", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
)
|
||||
)
|
||||
size: int = Field(sa_column=Column(SMALLINT(unsigned=True), default=3, nullable=False))
|
||||
is_ascending: bool = Field(default=True, nullable=False)
|
||||
is_time_record: bool = Field(default=False, nullable=False)
|
||||
is_validated: bool = Field(default=True, nullable=False)
|
||||
size: int = Field(sa_column=Column("Size", SMALLINT(unsigned=True), nullable=False), default=3)
|
||||
is_ascending: bool = Field(sa_column=Column("IsAscending", nullable=False), default=True)
|
||||
is_time_record: bool = Field(sa_column=Column("IsTimeRecord", nullable=False), default=False)
|
||||
is_validated: bool = Field(sa_column=Column("IsValidated", nullable=False), default=True)
|
||||
|
||||
__table_args__ = (UniqueConstraint("group_id", "name", name="UniqueCategoryInGroup"),)
|
||||
|
||||
@@ -126,12 +128,13 @@ class Score(SQLModel, table=True):
|
||||
|
||||
__tablename__: str = "Scores"
|
||||
|
||||
username: str = Field(max_length=30, nullable=False, primary_key=True)
|
||||
score: float = Field(nullable=False)
|
||||
username: str = Field(sa_column=Column("UserName", VARCHAR, primary_key=True, nullable=False), max_length=30)
|
||||
score: float = Field(sa_column=Column("Score", FLOAT, nullable=False))
|
||||
category_id: int = Field(
|
||||
sa_column=Column(
|
||||
"CategoryId",
|
||||
INTEGER(unsigned=True),
|
||||
ForeignKey("Categories.id", ondelete="CASCADE"),
|
||||
ForeignKey("Categories.CategoryId", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
primary_key=True,
|
||||
),
|
||||
@@ -158,6 +161,7 @@ class Submission(SQLModel, table=True):
|
||||
|
||||
category_id: int = Field(
|
||||
sa_column=Column(
|
||||
"CategoryId",
|
||||
INTEGER(unsigned=True),
|
||||
nullable=False,
|
||||
primary_key=True,
|
||||
@@ -165,13 +169,14 @@ class Submission(SQLModel, table=True):
|
||||
)
|
||||
group_id: int = Field(
|
||||
sa_column=Column(
|
||||
"GroupId",
|
||||
INTEGER(unsigned=True),
|
||||
nullable=False,
|
||||
)
|
||||
)
|
||||
guild_id: int = Field(sa_column=Column(BIGINT(unsigned=True), nullable=False))
|
||||
message_id: int = Field(sa_column=Column(BIGINT(unsigned=True), nullable=False))
|
||||
guild_id: int = Field(sa_column=Column("GuildId", BIGINT(unsigned=True), nullable=False))
|
||||
message_id: int = Field(sa_column=Column("MessageId", BIGINT(unsigned=True), nullable=False))
|
||||
# Score is stored as a string until converted during submission.
|
||||
score: str = Field(max_length=30, nullable=False)
|
||||
user_id: int = Field(sa_column=Column(BIGINT(unsigned=True), nullable=False))
|
||||
username: str = Field(max_length=30, nullable=False, primary_key=True)
|
||||
score: str = Field(sa_column=Column("Score", VARCHAR, nullable=False), max_length=30)
|
||||
user_id: int = Field(sa_column=Column("UserId", BIGINT(unsigned=True), nullable=False))
|
||||
username: str = Field(sa_column=Column("UserName", VARCHAR, nullable=False, primary_key=True), max_length=30)
|
||||
|
||||
Reference in New Issue
Block a user