Skip to content

Commit

Permalink
create dbinfo and schema handler
Browse files Browse the repository at this point in the history
This will allow to update databases incrementally in the future
  • Loading branch information
Eibe committed Jun 17, 2020
1 parent 850dd32 commit 4321ad2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .migration import *
from .database import *
from .github import *
from .schema import *
11 changes: 8 additions & 3 deletions core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,29 @@

import sqlite3
from random import randint
from . import schema


def initialize(database):
conn = sqlite3.connect(database)
cursor = conn.cursor()
cursor.execute(
"CREATE TABLE IF NOT EXISTS 'messages' ('message_id' INT, 'channel' INT,"
" 'reactionrole_id' INT);"
" 'reactionrole_id' INT, 'guild_id' INT);"
)
cursor.execute(
"CREATE TABLE IF NOT EXISTS 'reactionroles' ('reactionrole_id' INT, 'reaction'"
" NVCARCHAR, 'role_id' INT);"
)
cursor.execute("CREATE TABLE IF NOT EXISTS 'admins' ('role_id' INT);")
cursor.execute("CREATE TABLE IF NOT EXISTS 'dbinfo' ('version' INT);")
conn.commit()
cursor.close()
conn.close()

updater = schema.SchemaHandler(database)
updater.update()


class ReactionRoleCreationTracker:
def __init__(self, user, channel, database):
Expand All @@ -63,7 +68,7 @@ def _generate_reactionrole_id(self):
self.reactionrole_id = randint(0, 100000)
cursor = conn.cursor()
cursor.execute(
"SELECT * FROM messages WHERE reactionrole_id = ?",
"SELECT * FROM messages WHERE reactionrole_id = ?;",
(self.reactionrole_id,),
)
already_exists = cursor.fetchall()
Expand Down Expand Up @@ -218,7 +223,7 @@ def fetch_all_messages(self):
try:
conn = sqlite3.connect(self.database)
cursor = conn.cursor()
cursor.execute(f"SELECT message_id, channel FROM messages;")
cursor.execute("SELECT message_id, channel FROM messages;")
all_messages = {}
for row in cursor:
message_id = int(row[0])
Expand Down

0 comments on commit 4321ad2

Please sign in to comment.