Compare commits
3
Commits
ae1f98abe3
...
77ce54f383
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77ce54f383 | ||
|
|
f81ebca4de | ||
|
|
2e66b1c37c |
@@ -1,13 +0,0 @@
|
||||
"""Small script to create the database if it doesn't already exist."""
|
||||
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
if not Path("database/dakiny.db").exists():
|
||||
with sqlite3.connect("database/dakiny.db") as con:
|
||||
cur = con.cursor()
|
||||
|
||||
with Path("dakiny_bot/database/database.sql").open() as file:
|
||||
database_script = file.read()
|
||||
cur.executescript(database_script)
|
||||
con.commit()
|
||||
@@ -0,0 +1,13 @@
|
||||
"""Simple file to set up the sqlmodel connection to database."""
|
||||
|
||||
from sqlmodel import SQLModel, create_engine
|
||||
|
||||
from dakiny_bot.logger import dakiny_logger
|
||||
|
||||
from . import models # noqa: F401 - Need this import for creating the models.
|
||||
|
||||
url = "sqlite:///database/dakiny.db"
|
||||
dakiny_logger.info("Connected to local dev database.")
|
||||
engine = create_engine(url)
|
||||
|
||||
SQLModel.metadata.create_all(engine)
|
||||
@@ -19,6 +19,8 @@ class ElectionInformation(SQLModel, table=True):
|
||||
votes: All votes cast during this election.
|
||||
"""
|
||||
|
||||
__tablename__: str = "ElectionInformation"
|
||||
|
||||
name: str = Field(sa_column=Column("ElectionName", VARCHAR, primary_key=True, unique=True), max_length=30)
|
||||
thread_id: int = Field(sa_column=Column("ThreadId", BIGINT(unsigned=True), nullable=False))
|
||||
council_vote_msg_id: int | None = Field(
|
||||
@@ -109,9 +111,11 @@ class Vote(SQLModel, table=True):
|
||||
voter_id: int = Field(sa_column=Column("VoterId", BIGINT(unsigned=True), primary_key=True, nullable=False))
|
||||
# might have to set this foreign key later with alembic migration...
|
||||
voted_for_id: int | None = Field(
|
||||
sa_column=Column("VotedForId", BIGINT(unsigned=True), ForeignKey("CouncilMembers.member_id"), nullable=True)
|
||||
sa_column=Column("VotedForId", BIGINT(unsigned=True), ForeignKey("CouncilMembers.MemberId"), nullable=True)
|
||||
)
|
||||
type: str = Field(
|
||||
sa_column=Column("Type", VARCHAR, primary_key=True, nullable=False, default="council"), max_length=14
|
||||
)
|
||||
type: str = Field(sa_column=Column("Type", primary_key=True, nullable=False, default="council"), max_length=14)
|
||||
|
||||
election: ElectionInformation | None = Relationship(back_populates="votes")
|
||||
council_member: CouncilMember | None = Relationship(back_populates="votes")
|
||||
@@ -184,7 +188,7 @@ class Message(SQLModel, table=True):
|
||||
|
||||
__tablename__: str = "Messages"
|
||||
|
||||
path: str = Field(sa_column=Column("Path", primary_key=True, nullable=False), max_length=100)
|
||||
path: str = Field(sa_column=Column("Path", VARCHAR, primary_key=True, nullable=False), max_length=100)
|
||||
id: int = Field(sa_column=Column("Id", BIGINT(unsigned=True), nullable=False))
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
"""Simple file to set up the sqlalchemy connection to database."""
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.automap import automap_base
|
||||
|
||||
# connect with sql alchemy and autoload schema
|
||||
URL = "sqlite+pysqlite:///database/dakiny.db"
|
||||
engine = create_engine(URL)
|
||||
Base = automap_base()
|
||||
Base.prepare(autoload_with=engine)
|
||||
|
||||
# define the classes
|
||||
Points = Base.classes.Points
|
||||
PointsLimit = Base.classes.PointsLimit
|
||||
CouncilMembers = Base.classes.CouncilMembers
|
||||
ElectionInformation = Base.classes.ElectionInformation
|
||||
Messages = Base.classes.Messages
|
||||
Presences = Base.classes.Presences
|
||||
UserBirthday = Base.classes.UserBirthday
|
||||
Votes = Base.classes.Votes
|
||||
Reference in New Issue
Block a user