new changes

This commit is contained in:
Niranjan
2026-04-07 03:57:44 +05:30
parent 3872d90ee7
commit 73148d2b09
4 changed files with 43 additions and 10 deletions

View File

@@ -14,12 +14,19 @@ from app.core.security import get_password_hash
from app.models.user import User
async def seed():
async def seed(*, reset_password: bool = False):
await init_db()
async with AsyncSessionLocal() as db:
result = await db.execute(select(User).where(User.username == "admin"))
if result.scalar_one_or_none():
print("Admin user already exists")
existing = result.scalar_one_or_none()
if existing:
if reset_password:
existing.password = get_password_hash("admin")
existing.is_active = True
await db.commit()
print("Admin password reset: username=admin, password=admin")
else:
print("Admin user already exists (use --reset-password to force admin/admin)")
return
admin = User(
username="admin",
@@ -32,4 +39,5 @@ async def seed():
if __name__ == "__main__":
asyncio.run(seed())
reset = "--reset-password" in sys.argv
asyncio.run(seed(reset_password=reset))