Changed database scripts
This commit is contained in:
@ -1,35 +1,16 @@
|
||||
import mariadb
|
||||
import sqlmodel
|
||||
from sqlalchemy.future import Engine
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
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)
|
||||
)"""
|
||||
def get_engine(host: str, user: str, passwd: str, db: str) -> Engine:
|
||||
engine = sqlmodel.create_engine(
|
||||
f"mariadb+mariadbconnector://{user}:{passwd}@{host}/{db}"
|
||||
)
|
||||
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()
|
||||
print(type(engine))
|
||||
return engine
|
||||
|
||||
|
||||
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)
|
||||
def prepare(engine: Engine) -> None:
|
||||
sqlmodel.SQLModel.metadata.create_all(engine)
|
||||
|
Reference in New Issue
Block a user