This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
PassManager/src/database/prepare.py
2022-10-05 15:10:10 +03:00

36 lines
990 B
Python

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(con: mariadb.Connection) -> None:
_create_tables(con)
_create_index(con)