更新渠道删除

This commit is contained in:
Ubuntu
2025-12-25 10:59:02 +00:00
parent f3e10771ea
commit 658548b61c
8 changed files with 719 additions and 651 deletions
+162
View File
@@ -0,0 +1,162 @@
#!/usr/bin/env python3
"""
生成初始用户的SQL插入语句
使用bcrypt加密密码
"""
import uuid
from datetime import datetime
import bcrypt
def hash_password(password: str) -> str:
"""使用bcrypt加密密码"""
# bcrypt需要bytes类型的密码
password_bytes = password.encode('utf-8')
# 生成salt并加密
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(password_bytes, salt)
# 返回字符串形式
return hashed.decode('utf-8')
# 定义初始用户
USERS = [
{
"name": "超级管理员",
"username": "admin",
"email": "admin@test.com",
"password": "admin123",
"role": "super_admin",
"full_name": "系统超级管理员",
"is_active": True,
"is_admin": True,
"subscription_tier": "enterprise",
"balance": 100000,
"credit_limit": 500000,
"status": "active"
},
{
"name": "渠道管理员",
"username": "channel",
"email": "channel@test.com",
"password": "channel123",
"role": "channel_admin",
"full_name": "渠道管理员",
"is_active": True,
"is_admin": False,
"subscription_tier": "business",
"balance": 50000,
"credit_limit": 100000,
"status": "active"
},
{
"name": "供应商管理员",
"username": "provider",
"email": "provider@test.com",
"password": "provider123",
"role": "provider_admin",
"full_name": "供应商管理员",
"is_active": True,
"is_admin": False,
"subscription_tier": "business",
"balance": 50000,
"credit_limit": 100000,
"status": "active"
},
{
"name": "测试用户",
"username": "user",
"email": "user@test.com",
"password": "user123",
"role": "user",
"full_name": "普通测试用户",
"is_active": True,
"is_admin": False,
"subscription_tier": "free",
"balance": 100,
"credit_limit": 1000,
"status": "active"
},
{
"name": "计费管理员",
"username": "billing",
"email": "billing@test.com",
"password": "billing123",
"role": "billing_admin",
"full_name": "计费管理员",
"is_active": True,
"is_admin": False,
"subscription_tier": "business",
"balance": 10000,
"credit_limit": 50000,
"status": "active"
},
{
"name": "运维管理员",
"username": "operations",
"email": "operations@test.com",
"password": "operations123",
"role": "operations_admin",
"full_name": "运维管理员",
"is_active": True,
"is_admin": False,
"subscription_tier": "business",
"balance": 10000,
"credit_limit": 50000,
"status": "active"
}
]
def generate_sql():
"""生成SQL插入语句"""
print("-- 初始用户数据")
print("-- 自动生成时间:", datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print("-- 注意: 此脚本会在用户不存在时插入初始用户\n")
for user in USERS:
user_id = str(uuid.uuid4())
password_hash = hash_password(user["password"])
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"-- 创建用户: {user['name']} ({user['email']})")
print(f"INSERT INTO users (")
print(f" id, created_at, updated_at,")
print(f" name, username, email,")
print(f" password_hash, hashed_password,")
print(f" role, full_name,")
print(f" is_active, is_admin,")
print(f" subscription_tier, balance, credit_limit,")
print(f" status, discount")
print(f") VALUES (")
print(f" '{user_id}', '{now}', '{now}',")
print(f" '{user['name']}', '{user['username']}', '{user['email']}',")
print(f" '{password_hash}', '{password_hash}',")
print(f" '{user['role']}', '{user['full_name']}',")
print(f" {user['is_active']}, {user['is_admin']},")
print(f" '{user['subscription_tier']}', {user['balance']}, {user['credit_limit']},")
print(f" '{user['status']}', 0")
print(f") ON CONFLICT (email) DO NOTHING;")
print()
def main():
print("="*80)
print("Taiji AI-PAD 初始用户SQL生成器")
print("="*80)
print()
generate_sql()
print("\n-- 用户信息汇总:")
print("-- " + "="*76)
for user in USERS:
print(f"-- {user['name']:15} | {user['email']:25} | 密码: {user['password']}")
print("-- " + "="*76)
print("\n-- 提示: 将上述SQL语句添加到 scripts/init.sql 文件末尾")
print("-- 或者创建新的 scripts/init_users.sql 文件")
if __name__ == "__main__":
main()