-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_admin.py
More file actions
25 lines (22 loc) · 787 Bytes
/
Copy pathcreate_admin.py
File metadata and controls
25 lines (22 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import asyncio
import uuid
from core.database import AsyncSessionLocal, engine, Base
from core.security import get_password_hash
from models import User, UserRole # this import registers all models with Base
async def create_admin():
# create all tables first
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
print("[DB] Tables created")
async with AsyncSessionLocal() as db:
admin = User(
id=uuid.uuid4(),
username="admin",
email="admin@safesteps.com",
password_hash=get_password_hash("changeme123"),
role=UserRole.admin
)
db.add(admin)
await db.commit()
print("Admin created: admin / changeme123")
asyncio.run(create_admin())