feat: 添加测试用户到种子数据, AI改写功能优化, 前端联调修复
This commit is contained in:
29
server/sql/add_test_user.py
Normal file
29
server/sql/add_test_user.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""添加测试用户"""
|
||||
import os
|
||||
import pymysql
|
||||
from pathlib import Path
|
||||
|
||||
SERVER_DIR = Path(__file__).parent.parent
|
||||
env_file = SERVER_DIR / '.env'
|
||||
if env_file.exists():
|
||||
with open(env_file, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#') and '=' in line:
|
||||
key, value = line.split('=', 1)
|
||||
os.environ.setdefault(key.strip(), value.strip())
|
||||
|
||||
conn = pymysql.connect(
|
||||
host=os.getenv('DB_HOST', 'localhost'),
|
||||
port=int(os.getenv('DB_PORT', 3306)),
|
||||
user=os.getenv('DB_USER', 'root'),
|
||||
password=os.getenv('DB_PASSWORD', ''),
|
||||
database='stardom_story',
|
||||
charset='utf8mb4'
|
||||
)
|
||||
cur = conn.cursor()
|
||||
cur.execute("INSERT IGNORE INTO users (id, openid, nickname) VALUES (1, 'test_user', '测试用户')")
|
||||
conn.commit()
|
||||
print('测试用户创建成功')
|
||||
cur.close()
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user