-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.py
More file actions
38 lines (29 loc) · 1.04 KB
/
Copy pathseed.py
File metadata and controls
38 lines (29 loc) · 1.04 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
from app.core import database as db
from app.models import user as user_model, product as product_model
from app.models.user import User
from app.core.security import hash_password
from sqlalchemy import select
from app.models.base import Base
async def main():
await db.verify_db_connection()
async with db.engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
async with db.AsyncSessionFactory() as session:
email = "admin@example.com"
password = "admin123"
existing = await session.execute(select(User).where(User.email == email))
if existing.scalar_one_or_none():
print("Admin already exists")
return
user = User(
email=email,
hashed_password=hash_password(password),
role="admin",
is_active=True
)
session.add(user)
await session.commit()
print(f"Seeded admin user: {email} / {password}")
if __name__ == "__main__":
asyncio.run(main())