added create.py in db
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/res/db/database.db
|
||||
@@ -23,7 +23,6 @@ class ConfigError(Exception):
|
||||
|
||||
|
||||
_teletoken = getenv('LTLNOTIFIER_TELETOKEN')
|
||||
print(_teletoken[9])
|
||||
# Check api token
|
||||
if not _teletoken:
|
||||
raise ConfigError('virtual environment LTLNOTIFIER_TELETOKEN not set.')
|
||||
@@ -31,7 +30,6 @@ if len(_teletoken) != 45 or _teletoken[9] != ':' or not _teletoken[:9].isdigit()
|
||||
raise ConfigError('virtual environment LTLNOTIFIER_TELETOKEN incorrect.')
|
||||
|
||||
_bot_owner = getenv('LTLNOTIFIER_BOT_OWNER')
|
||||
print(_bot_owner)
|
||||
# Check bot owner
|
||||
if not _bot_owner:
|
||||
raise ConfigError('virtual environment LTLNOTIFIER_BOT_OWNER not set.')
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import aiosqlite
|
||||
|
||||
from .create import create_tables_if_not_exists
|
||||
|
||||
|
||||
DB_PATH = 'res/db/'
|
||||
DB_FILENAME = 'database.db'
|
||||
|
||||
|
||||
create_tables_if_not_exists(f'{DB_PATH}{DB_FILENAME}')
|
||||
|
||||
29
db/create.py
Normal file
29
db/create.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import sqlite3
|
||||
|
||||
CREATE_SERVICES_TABLE = '''CREATE TABLE IF NOT EXISTS services (
|
||||
service_id INTEGER PRIMARY KEY,
|
||||
token TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT DEFAULT "Нет описания.",
|
||||
representation INTEGER DEFAULT 0,
|
||||
by_request INTEGER DEFAULT 0
|
||||
);'''
|
||||
|
||||
CREATE_NOTIFICATIONS_TABLE = '''CREATE TABLE IF NOT EXISTS notifications (
|
||||
notification_id INTEGER PRIMARY KEY,
|
||||
service_id INTEGER NOT NULL,
|
||||
timestamp TEXT NOT NULL,
|
||||
content_json TEXT NOT NULL,
|
||||
FOREIGN KEY (service_id) REFERENCES services(service_id)
|
||||
ON UPDATE CASCADE ON DELETE CASCADE
|
||||
);'''
|
||||
|
||||
|
||||
def create_tables_if_not_exists(dbfile: str) -> None:
|
||||
connection = sqlite3.connect(dbfile)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute('PRAGMA foreign_keys=0')
|
||||
cursor.execute(CREATE_SERVICES_TABLE)
|
||||
cursor.execute(CREATE_NOTIFICATIONS_TABLE)
|
||||
connection.commit()
|
||||
connection.close()
|
||||
Reference in New Issue
Block a user