Created database/prepare.py

This commit is contained in:
StNicolay 2022-09-26 22:44:48 +03:00
parent 1bde1a1739
commit 44bab0fb48

39
src/database/prepare.py Normal file
View File

@ -0,0 +1,39 @@
import mariadb
def _create_tables(con: mariadb.Connection) -> None:
cursor = con.cursor()
cursor.execute(
"""CREATE TABLE IF NOT EXISTS master_pass (user_id INT,
salt BINARY(64),
PASSWD BINARY(64),
PRIMARY KEY(user_id)
)"""
)
cursor.execute(
"""CREATE TABLE IF NOT EXISTS accounts(user_id INT,
acc_name VARCHAR(255),
salt BINARY(64),
enc_login BINARY(64),
enc_pass BINARY(64),
UNIQUE(acc_name, user_id)
)"""
)
cursor.close()
def _create_index(con: mariadb.Connection) -> None:
cursor = con.cursor()
cursor.execute(
"""CREATE INDEX IF NOT EXISTS user_id_to_acc on accounts(user_id)
"""
)
def prepare(host: int, user: str, passwd: str, database: str) -> None:
con: mariadb.Connection = mariadb.connect(
host=host, user=user, password=passwd, database=database
)
_create_tables(con)
_create_index(con)
con.close()