ADD seed admin user
This commit is contained in:
@@ -2,6 +2,12 @@ from duckdb import connect
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
import json
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
from lib.helpers import hash_password
|
||||
|
||||
load_dotenv()
|
||||
|
||||
DB_PATH = Path("./data/data.duckdb").absolute()
|
||||
SQL_PATH = Path("./lib/database.sql").absolute()
|
||||
@@ -19,6 +25,7 @@ def get_connection():
|
||||
|
||||
|
||||
def seed_db() -> None:
|
||||
# Seed Songs
|
||||
with open(SEED_JSON_PATH, "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
@@ -46,6 +53,7 @@ def seed_db() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
# Seed CountryCodes
|
||||
with open(COUNTRYCODES_JSON_PATH, "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
@@ -63,6 +71,24 @@ def seed_db() -> None:
|
||||
),
|
||||
)
|
||||
|
||||
# Seed Teams
|
||||
with get_connection() as conn:
|
||||
conn.execute("INSERT INTO Team (name) VALUES (?)", ("Pontus",))
|
||||
|
||||
# Seed Admin users
|
||||
admin_username = os.getenv("ADMIN_USERNAME")
|
||||
hashed_admin_password = hash_password(os.getenv("ADMIN_PASSWORD"))
|
||||
with get_connection() as conn:
|
||||
conn.execute(
|
||||
'INSERT INTO "User" (username, hashed_password, team_id, is_active) VALUES (?, ?, ?, ?)',
|
||||
(
|
||||
admin_username,
|
||||
hashed_admin_password,
|
||||
1,
|
||||
True,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def init_db():
|
||||
with open(SQL_PATH, "r") as f:
|
||||
|
||||
Reference in New Issue
Block a user