초기 커밋
This commit is contained in:
45
scripts/create_superuser.py
Normal file
45
scripts/create_superuser.py
Normal file
@@ -0,0 +1,45 @@
|
||||
"""Create a superuser account."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
from app.core.constants import Role
|
||||
from app.core.security import hash_password
|
||||
from app.db.mariadb import AsyncSessionLocal, async_engine
|
||||
from app.models.mariadb.user import User, UserProfile
|
||||
|
||||
|
||||
async def create_superuser(email: str, password: str, full_name: str = "Super Admin") -> None:
|
||||
async with AsyncSessionLocal() as session:
|
||||
user = User(
|
||||
email=email,
|
||||
hashed_password=hash_password(password),
|
||||
role=Role.SUPERADMIN,
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
)
|
||||
session.add(user)
|
||||
await session.flush()
|
||||
|
||||
profile = UserProfile(
|
||||
user_id=user.id,
|
||||
full_name=full_name,
|
||||
)
|
||||
session.add(profile)
|
||||
await session.commit()
|
||||
|
||||
await async_engine.dispose()
|
||||
print(f"Superuser '{email}' created successfully!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: python -m scripts.create_superuser <email> <password> [full_name]")
|
||||
sys.exit(1)
|
||||
|
||||
email = sys.argv[1]
|
||||
password = sys.argv[2]
|
||||
name = sys.argv[3] if len(sys.argv) > 3 else "Super Admin"
|
||||
|
||||
asyncio.run(create_superuser(email, password, name))
|
||||
44
scripts/init_db.py
Normal file
44
scripts/init_db.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""Initialize database with seed data."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from sqlmodel import SQLModel
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.constants import Role
|
||||
from app.core.security import hash_password
|
||||
from app.db.mariadb import async_engine, AsyncSessionLocal
|
||||
from app.models.mariadb.auth import OAuthAccount, RefreshToken # noqa: F401
|
||||
from app.models.mariadb.device import Device, DeviceGroup # noqa: F401
|
||||
from app.models.mariadb.monitoring import Alert, AlertRule # noqa: F401
|
||||
from app.models.mariadb.system import AuditLog, SystemConfig # noqa: F401
|
||||
from app.models.mariadb.user import User, UserProfile
|
||||
|
||||
|
||||
async def init() -> None:
|
||||
# Create tables
|
||||
async with async_engine.begin() as conn:
|
||||
await conn.run_sync(SQLModel.metadata.create_all)
|
||||
|
||||
# Seed default data
|
||||
async with AsyncSessionLocal() as session:
|
||||
# Create default device group
|
||||
group = DeviceGroup(name="default", description="Default device group")
|
||||
session.add(group)
|
||||
|
||||
# Create system configs
|
||||
configs = [
|
||||
SystemConfig(key="maintenance_mode", value="false", description="Enable maintenance mode"),
|
||||
SystemConfig(key="max_devices_per_user", value="50", description="Max devices per user"),
|
||||
]
|
||||
for c in configs:
|
||||
session.add(c)
|
||||
|
||||
await session.commit()
|
||||
|
||||
print("Database initialized successfully!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(init())
|
||||
5
scripts/run_beat.sh
Normal file
5
scripts/run_beat.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "Starting Celery beat scheduler..."
|
||||
celery -A app.tasks.celery_app beat --loglevel=info
|
||||
5
scripts/run_dev.sh
Normal file
5
scripts/run_dev.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "Starting development server..."
|
||||
uvicorn app.asgi:app --host 0.0.0.0 --port 8000 --reload
|
||||
8
scripts/run_worker.sh
Normal file
8
scripts/run_worker.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "Starting Celery worker..."
|
||||
celery -A app.tasks.celery_app worker \
|
||||
--loglevel=info \
|
||||
--concurrency=4 \
|
||||
-Q default,analytics,notifications,devices
|
||||
Reference in New Issue
Block a user