first commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""Initialize the database and seed the default local administrator."""
|
||||
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.config import get_settings
|
||||
from app.db.repositories.repositories import UserRepository
|
||||
|
||||
DEFAULT_USERNAME = "gly"
|
||||
DEFAULT_PASSWORD = "maxta2026"
|
||||
|
||||
|
||||
def initialize() -> bool:
|
||||
command.upgrade(Config("alembic.ini"), "head")
|
||||
engine = create_engine(get_settings().database_url)
|
||||
with Session(engine) as db:
|
||||
repo = UserRepository(db)
|
||||
if repo.get_by_username(DEFAULT_USERNAME):
|
||||
return False
|
||||
repo.create(username=DEFAULT_USERNAME, password=DEFAULT_PASSWORD, is_admin=True)
|
||||
return True
|
||||
|
||||
|
||||
def main() -> None:
|
||||
created = initialize()
|
||||
print(f"Database initialized; user {DEFAULT_USERNAME} {'created' if created else 'already exists'}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user