Define database and add script to create if dne.

This commit is contained in:
2023-07-16 22:18:17 -04:00
parent 1cb16d5a39
commit fc9eb7b151
4 changed files with 45 additions and 0 deletions
+1
View File
@@ -139,3 +139,4 @@ TODO.txt
sql_tester.py
conf
outputs
dakiny.db
+15
View File
@@ -0,0 +1,15 @@
"""
Small script to create the database if it doesn't already exist.
"""
import sqlite3
from os.path import exists
if not exists("dakiny.db"):
with sqlite3.connect("dakiny.db") as con:
cur = con.cursor()
with open("database.sql", mode="r", encoding="utf-8") as file:
database_script = file.read()
cur.executescript(database_script)
con.commit()
+2
View File
@@ -6,6 +6,7 @@ import nextcord
from hydra.core.config_store import ConfigStore
from nextcord.ext import commands
import create_database
from config import DakinyConfig
cs = ConfigStore.instance()
@@ -38,6 +39,7 @@ def main(cfg: DakinyConfig):
async def on_ready():
"""When Discord is connected"""
assert bot.user is not None
create_database # pylint: disable=pointless-statement
print(f"{bot.user.name} has connected to Discord!")
# Run Discord bot
+27
View File
@@ -0,0 +1,27 @@
-- CREATE DATABASE dakiny;
-- use dakiny;
CREATE TABLE ElectionInformation(
ElectionCycle varchar(30) not null unique,
ElectionChannel bigint unsigned,
PRIMARY KEY (ElectionCycle)
);
CREATE TABLE CouncilMembers(
ElectionCycle varchar(30) not null unique,
MemberId bigint unsigned not null,
Elected boolean DEFAULT false,
HighCouncilElect boolean DEFAULT false,
DiscordManager boolean DEFAULT false,
ClanLeader boolean DEFAULT false,
FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle),
PRIMARY KEY (ElectionCycle, MemberId)
);
CREATE TABLE Votes(
ElectionCycle varchar(30) not null unique,
VoterId bigint unsigned not null,
VotedForId bigint unsigned not null,
FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle),
PRIMARY KEY (ElectionCycle, VoterId)
);