Define database and add script to create if dne.
This commit is contained in:
@@ -139,3 +139,4 @@ TODO.txt
|
|||||||
sql_tester.py
|
sql_tester.py
|
||||||
conf
|
conf
|
||||||
outputs
|
outputs
|
||||||
|
dakiny.db
|
||||||
@@ -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()
|
||||||
@@ -6,6 +6,7 @@ import nextcord
|
|||||||
from hydra.core.config_store import ConfigStore
|
from hydra.core.config_store import ConfigStore
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
import create_database
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
|
||||||
cs = ConfigStore.instance()
|
cs = ConfigStore.instance()
|
||||||
@@ -38,6 +39,7 @@ def main(cfg: DakinyConfig):
|
|||||||
async def on_ready():
|
async def on_ready():
|
||||||
"""When Discord is connected"""
|
"""When Discord is connected"""
|
||||||
assert bot.user is not None
|
assert bot.user is not None
|
||||||
|
create_database # pylint: disable=pointless-statement
|
||||||
print(f"{bot.user.name} has connected to Discord!")
|
print(f"{bot.user.name} has connected to Discord!")
|
||||||
|
|
||||||
# Run Discord bot
|
# Run Discord bot
|
||||||
|
|||||||
@@ -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)
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user