init commit

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-26 15:34:31 +08:00
commit 80513a3258
141 changed files with 24966 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
from sqlalchemy import text
from core.database import engine
def add_superuser_field():
try:
with engine.connect() as conn:
conn.execute(text("ALTER TABLE users ADD COLUMN is_superuser BOOLEAN NOT NULL DEFAULT 0"))
conn.commit()
print("Successfully added is_superuser field to users table")
except Exception as e:
if "duplicate column name" in str(e).lower() or "already exists" in str(e).lower():
print("is_superuser field already exists, skipping")
else:
print(f"Error adding is_superuser field: {e}")
raise
if __name__ == "__main__":
add_superuser_field()

View File

@@ -0,0 +1,40 @@
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent))
from core.database import SessionLocal
from core.security import get_password_hash
from db.crud import get_user_by_username, create_user_by_admin
def create_admin():
db = SessionLocal()
try:
existing_admin = get_user_by_username(db, username="admin")
if existing_admin:
print("Admin user already exists")
if not existing_admin.is_superuser:
existing_admin.is_superuser = True
db.commit()
print("Updated existing admin user to superuser")
return
hashed_password = get_password_hash("admin123456")
admin_user = create_user_by_admin(
db,
username="admin",
email="admin@example.com",
hashed_password=hashed_password,
is_superuser=True
)
print(f"Created admin user successfully: {admin_user.username}")
print("Username: admin")
print("Password: admin123456")
except Exception as e:
print(f"Error creating admin user: {e}")
raise
finally:
db.close()
if __name__ == "__main__":
create_admin()