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()
|
||||
@@ -9,12 +9,25 @@ from pathlib import Path
|
||||
# 获取当前脚本所在目录
|
||||
SQL_DIR = Path(__file__).parent
|
||||
|
||||
# 数据库配置(从环境变量或默认值)
|
||||
# 从.env文件读取配置
|
||||
def load_env():
|
||||
env_file = SQL_DIR.parent / '.env'
|
||||
config = {}
|
||||
if env_file.exists():
|
||||
for line in env_file.read_text(encoding='utf-8').splitlines():
|
||||
if '=' in line and not line.startswith('#'):
|
||||
k, v = line.split('=', 1)
|
||||
config[k.strip()] = v.strip()
|
||||
return config
|
||||
|
||||
env_config = load_env()
|
||||
|
||||
# 数据库配置(优先从.env读取)
|
||||
DB_CONFIG = {
|
||||
'host': os.getenv('DB_HOST', 'localhost'),
|
||||
'port': int(os.getenv('DB_PORT', 3306)),
|
||||
'user': os.getenv('DB_USER', 'root'),
|
||||
'password': os.getenv('DB_PASSWORD', '123456'),
|
||||
'host': env_config.get('DB_HOST', os.getenv('DB_HOST', 'localhost')),
|
||||
'port': int(env_config.get('DB_PORT', os.getenv('DB_PORT', 3306))),
|
||||
'user': env_config.get('DB_USER', os.getenv('DB_USER', 'root')),
|
||||
'password': env_config.get('DB_PASSWORD', os.getenv('DB_PASSWORD', '')),
|
||||
'charset': 'utf8mb4'
|
||||
}
|
||||
|
||||
|
||||
74
server/sql/rebuild_db.py
Normal file
74
server/sql/rebuild_db.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""删库重建脚本"""
|
||||
import os
|
||||
import sys
|
||||
import pymysql
|
||||
from pathlib import Path
|
||||
|
||||
SQL_DIR = Path(__file__).parent
|
||||
SERVER_DIR = SQL_DIR.parent
|
||||
|
||||
# 加载 .env 文件
|
||||
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())
|
||||
|
||||
DB_CONFIG = {
|
||||
'host': os.getenv('DB_HOST', 'localhost'),
|
||||
'port': int(os.getenv('DB_PORT', 3306)),
|
||||
'user': os.getenv('DB_USER', 'root'),
|
||||
'password': os.getenv('DB_PASSWORD', '123456'),
|
||||
'charset': 'utf8mb4'
|
||||
}
|
||||
|
||||
def read_sql_file(filename):
|
||||
with open(SQL_DIR / filename, 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
|
||||
def execute_sql(cursor, sql, desc):
|
||||
print(f'{desc}...')
|
||||
for stmt in [s.strip() for s in sql.split(';') if s.strip()]:
|
||||
try:
|
||||
cursor.execute(stmt)
|
||||
except pymysql.Error as e:
|
||||
if e.args[0] not in [1007, 1050]:
|
||||
print(f' 警告: {e.args[1]}')
|
||||
print(f' {desc}完成!')
|
||||
|
||||
def rebuild():
|
||||
print('=' * 50)
|
||||
print('星域故事汇 - 删库重建')
|
||||
print('=' * 50)
|
||||
|
||||
conn = pymysql.connect(**DB_CONFIG)
|
||||
cur = conn.cursor()
|
||||
|
||||
# 删库
|
||||
print('删除旧数据库...')
|
||||
cur.execute('DROP DATABASE IF EXISTS stardom_story')
|
||||
conn.commit()
|
||||
print(' 删除完成!')
|
||||
|
||||
# 重建
|
||||
schema_sql = read_sql_file('schema.sql')
|
||||
execute_sql(cur, schema_sql, '创建数据库表结构')
|
||||
conn.commit()
|
||||
|
||||
seed1 = read_sql_file('seed_stories_part1.sql')
|
||||
execute_sql(cur, seed1, '导入种子数据(第1部分)')
|
||||
conn.commit()
|
||||
|
||||
seed2 = read_sql_file('seed_stories_part2.sql')
|
||||
execute_sql(cur, seed2, '导入种子数据(第2部分)')
|
||||
conn.commit()
|
||||
|
||||
print('\n数据库重建完成!')
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
rebuild()
|
||||
@@ -1,107 +1,158 @@
|
||||
-- 星域故事汇数据库初始化脚本
|
||||
-- 创建数据库
|
||||
CREATE DATABASE IF NOT EXISTS stardom_story DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
-- ============================================
|
||||
-- 星域故事汇数据库结构
|
||||
-- 基于实际数据库导出,共7张表
|
||||
-- ============================================
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS stardom_story DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
USE stardom_story;
|
||||
|
||||
-- 故事主表
|
||||
CREATE TABLE IF NOT EXISTS stories (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
title VARCHAR(100) NOT NULL COMMENT '故事标题',
|
||||
cover_url VARCHAR(255) DEFAULT '' COMMENT '封面图URL',
|
||||
description TEXT COMMENT '故事简介',
|
||||
author_id INT DEFAULT 0 COMMENT '作者ID,0表示官方',
|
||||
category VARCHAR(50) NOT NULL COMMENT '故事分类',
|
||||
play_count INT DEFAULT 0 COMMENT '游玩次数',
|
||||
like_count INT DEFAULT 0 COMMENT '点赞数',
|
||||
is_featured BOOLEAN DEFAULT FALSE COMMENT '是否精选',
|
||||
status TINYINT DEFAULT 1 COMMENT '状态:0下架 1上架',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_category (category),
|
||||
INDEX idx_featured (is_featured),
|
||||
INDEX idx_play_count (play_count)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='故事主表';
|
||||
|
||||
-- 故事节点表
|
||||
CREATE TABLE IF NOT EXISTS story_nodes (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
story_id INT NOT NULL COMMENT '故事ID',
|
||||
node_key VARCHAR(50) NOT NULL COMMENT '节点唯一标识',
|
||||
content TEXT NOT NULL COMMENT '节点内容文本',
|
||||
speaker VARCHAR(50) DEFAULT '' COMMENT '说话角色名',
|
||||
background_image VARCHAR(255) DEFAULT '' COMMENT '背景图URL',
|
||||
character_image VARCHAR(255) DEFAULT '' COMMENT '角色立绘URL',
|
||||
bgm VARCHAR(255) DEFAULT '' COMMENT '背景音乐',
|
||||
is_ending BOOLEAN DEFAULT FALSE COMMENT '是否为结局节点',
|
||||
ending_name VARCHAR(100) DEFAULT '' COMMENT '结局名称',
|
||||
ending_score INT DEFAULT 0 COMMENT '结局评分',
|
||||
ending_type VARCHAR(20) DEFAULT '' COMMENT '结局类型:good/bad/normal/hidden',
|
||||
sort_order INT DEFAULT 0 COMMENT '排序',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_story_id (story_id),
|
||||
INDEX idx_node_key (story_id, node_key),
|
||||
FOREIGN KEY (story_id) REFERENCES stories(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='故事节点表';
|
||||
|
||||
-- 故事选项表
|
||||
CREATE TABLE IF NOT EXISTS story_choices (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
node_id INT NOT NULL COMMENT '所属节点ID',
|
||||
story_id INT NOT NULL COMMENT '故事ID(冗余,便于查询)',
|
||||
text VARCHAR(200) NOT NULL COMMENT '选项文本',
|
||||
next_node_key VARCHAR(50) NOT NULL COMMENT '下一个节点key',
|
||||
sort_order INT DEFAULT 0 COMMENT '排序',
|
||||
is_locked BOOLEAN DEFAULT FALSE COMMENT '是否锁定(需广告解锁)',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_node_id (node_id),
|
||||
INDEX idx_story_id (story_id),
|
||||
FOREIGN KEY (node_id) REFERENCES story_nodes(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='故事选项表';
|
||||
|
||||
-- 用户表
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
openid VARCHAR(100) UNIQUE NOT NULL COMMENT '微信openid',
|
||||
nickname VARCHAR(100) DEFAULT '' COMMENT '昵称',
|
||||
avatar_url VARCHAR(255) DEFAULT '' COMMENT '头像URL',
|
||||
gender TINYINT DEFAULT 0 COMMENT '性别:0未知 1男 2女',
|
||||
total_play_count INT DEFAULT 0 COMMENT '总游玩次数',
|
||||
total_endings INT DEFAULT 0 COMMENT '解锁结局数',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_openid (openid)
|
||||
-- ============================================
|
||||
-- 1. 用户表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`openid` VARCHAR(100) NOT NULL COMMENT '微信openid',
|
||||
`nickname` VARCHAR(100) DEFAULT '' COMMENT '昵称',
|
||||
`avatar_url` VARCHAR(255) DEFAULT '' COMMENT '头像URL',
|
||||
`gender` TINYINT DEFAULT 0 COMMENT '性别:0未知 1男 2女',
|
||||
`total_play_count` INT DEFAULT 0 COMMENT '总游玩次数',
|
||||
`total_endings` INT DEFAULT 0 COMMENT '解锁结局数',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `openid` (`openid`),
|
||||
KEY `idx_openid` (`openid`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
|
||||
|
||||
-- 用户进度表
|
||||
CREATE TABLE IF NOT EXISTS user_progress (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
user_id INT NOT NULL COMMENT '用户ID',
|
||||
story_id INT NOT NULL COMMENT '故事ID',
|
||||
current_node_key VARCHAR(50) DEFAULT 'start' COMMENT '当前节点',
|
||||
is_completed BOOLEAN DEFAULT FALSE COMMENT '是否完成',
|
||||
ending_reached VARCHAR(100) DEFAULT '' COMMENT '达成的结局',
|
||||
is_liked BOOLEAN DEFAULT FALSE COMMENT '是否点赞',
|
||||
is_collected BOOLEAN DEFAULT FALSE COMMENT '是否收藏',
|
||||
play_count INT DEFAULT 1 COMMENT '游玩次数',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uk_user_story (user_id, story_id),
|
||||
INDEX idx_user_id (user_id),
|
||||
INDEX idx_story_id (story_id),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (story_id) REFERENCES stories(id) ON DELETE CASCADE
|
||||
-- ============================================
|
||||
-- 2. 故事主表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `stories` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`title` VARCHAR(100) NOT NULL COMMENT '故事标题',
|
||||
`cover_url` VARCHAR(255) DEFAULT '' COMMENT '封面图URL',
|
||||
`description` TEXT COMMENT '故事简介',
|
||||
`author_id` INT DEFAULT 0 COMMENT '作者ID,0表示官方',
|
||||
`category` VARCHAR(50) NOT NULL COMMENT '故事分类',
|
||||
`play_count` INT DEFAULT 0 COMMENT '游玩次数',
|
||||
`like_count` INT DEFAULT 0 COMMENT '点赞数',
|
||||
`is_featured` TINYINT(1) DEFAULT 0 COMMENT '是否精选',
|
||||
`status` TINYINT DEFAULT 1 COMMENT '状态:0下架 1上架',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_category` (`category`),
|
||||
KEY `idx_featured` (`is_featured`),
|
||||
KEY `idx_play_count` (`play_count`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='故事主表';
|
||||
|
||||
-- ============================================
|
||||
-- 3. 故事节点表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `story_nodes` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`story_id` INT NOT NULL COMMENT '故事ID',
|
||||
`node_key` VARCHAR(50) NOT NULL COMMENT '节点唯一标识',
|
||||
`content` TEXT NOT NULL COMMENT '节点内容文本',
|
||||
`speaker` VARCHAR(50) DEFAULT '' COMMENT '说话角色名',
|
||||
`background_image` VARCHAR(255) DEFAULT '' COMMENT '背景图URL',
|
||||
`character_image` VARCHAR(255) DEFAULT '' COMMENT '角色立绘URL',
|
||||
`bgm` VARCHAR(255) DEFAULT '' COMMENT '背景音乐',
|
||||
`is_ending` TINYINT(1) DEFAULT 0 COMMENT '是否为结局节点',
|
||||
`ending_name` VARCHAR(100) DEFAULT '' COMMENT '结局名称',
|
||||
`ending_score` INT DEFAULT 0 COMMENT '结局评分',
|
||||
`ending_type` VARCHAR(20) DEFAULT '' COMMENT '结局类型:good/bad/normal/hidden',
|
||||
`sort_order` INT DEFAULT 0 COMMENT '排序',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_story_id` (`story_id`),
|
||||
KEY `idx_node_key` (`story_id`, `node_key`),
|
||||
CONSTRAINT `story_nodes_ibfk_1` FOREIGN KEY (`story_id`) REFERENCES `stories` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='故事节点表';
|
||||
|
||||
-- ============================================
|
||||
-- 4. 故事选项表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `story_choices` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`node_id` INT NOT NULL COMMENT '所属节点ID',
|
||||
`story_id` INT NOT NULL COMMENT '故事ID(冗余,便于查询)',
|
||||
`text` VARCHAR(200) NOT NULL COMMENT '选项文本',
|
||||
`next_node_key` VARCHAR(50) NOT NULL COMMENT '下一个节点key',
|
||||
`sort_order` INT DEFAULT 0 COMMENT '排序',
|
||||
`is_locked` TINYINT(1) DEFAULT 0 COMMENT '是否锁定(需广告解锁)',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_node_id` (`node_id`),
|
||||
KEY `idx_story_id` (`story_id`),
|
||||
CONSTRAINT `story_choices_ibfk_1` FOREIGN KEY (`node_id`) REFERENCES `story_nodes` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='故事选项表';
|
||||
|
||||
-- ============================================
|
||||
-- 5. 用户进度表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `user_progress` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`user_id` INT NOT NULL COMMENT '用户ID',
|
||||
`story_id` INT NOT NULL COMMENT '故事ID',
|
||||
`current_node_key` VARCHAR(50) DEFAULT 'start' COMMENT '当前节点',
|
||||
`is_completed` TINYINT(1) DEFAULT 0 COMMENT '是否完成',
|
||||
`ending_reached` VARCHAR(100) DEFAULT '' COMMENT '达成的结局',
|
||||
`is_liked` TINYINT(1) DEFAULT 0 COMMENT '是否点赞',
|
||||
`is_collected` TINYINT(1) DEFAULT 0 COMMENT '是否收藏',
|
||||
`play_count` INT DEFAULT 1 COMMENT '游玩次数',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_user_story` (`user_id`, `story_id`),
|
||||
KEY `idx_user_id` (`user_id`),
|
||||
KEY `idx_story_id` (`story_id`),
|
||||
CONSTRAINT `user_progress_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `user_progress_ibfk_2` FOREIGN KEY (`story_id`) REFERENCES `stories` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户进度表';
|
||||
|
||||
-- 用户结局收集表
|
||||
CREATE TABLE IF NOT EXISTS user_endings (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
user_id INT NOT NULL,
|
||||
story_id INT NOT NULL,
|
||||
ending_name VARCHAR(100) NOT NULL,
|
||||
ending_score INT DEFAULT 0,
|
||||
unlocked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uk_user_ending (user_id, story_id, ending_name),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (story_id) REFERENCES stories(id) ON DELETE CASCADE
|
||||
-- ============================================
|
||||
-- 6. 用户结局收集表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `user_endings` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`user_id` INT NOT NULL,
|
||||
`story_id` INT NOT NULL,
|
||||
`ending_name` VARCHAR(100) NOT NULL,
|
||||
`ending_score` INT DEFAULT 0,
|
||||
`unlocked_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_user_ending` (`user_id`, `story_id`, `ending_name`),
|
||||
KEY `story_id` (`story_id`),
|
||||
CONSTRAINT `user_endings_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `user_endings_ibfk_2` FOREIGN KEY (`story_id`) REFERENCES `stories` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户结局收集表';
|
||||
|
||||
-- ============================================
|
||||
-- 7. AI改写草稿表
|
||||
-- ============================================
|
||||
CREATE TABLE IF NOT EXISTS `story_drafts` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`user_id` INT NOT NULL COMMENT '用户ID',
|
||||
`story_id` INT NOT NULL COMMENT '原故事ID',
|
||||
`title` VARCHAR(100) DEFAULT '' COMMENT '草稿标题',
|
||||
`path_history` JSON DEFAULT NULL COMMENT '用户之前的选择路径',
|
||||
`current_node_key` VARCHAR(50) DEFAULT '' COMMENT '改写起始节点',
|
||||
`current_content` TEXT COMMENT '当前节点内容',
|
||||
`user_prompt` VARCHAR(500) NOT NULL COMMENT '用户改写指令',
|
||||
`ai_nodes` JSON DEFAULT NULL COMMENT 'AI生成的新节点',
|
||||
`entry_node_key` VARCHAR(50) DEFAULT '' COMMENT '入口节点',
|
||||
`tokens_used` INT DEFAULT 0 COMMENT '消耗token数',
|
||||
`status` ENUM('pending', 'processing', 'completed', 'failed') DEFAULT 'pending' COMMENT '状态',
|
||||
`error_message` VARCHAR(500) DEFAULT '' COMMENT '失败原因',
|
||||
`is_read` TINYINT(1) DEFAULT 0 COMMENT '用户是否已查看',
|
||||
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
`completed_at` TIMESTAMP NULL DEFAULT NULL COMMENT '完成时间',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_user` (`user_id`),
|
||||
KEY `idx_story` (`story_id`),
|
||||
KEY `idx_status` (`status`),
|
||||
KEY `idx_user_unread` (`user_id`, `is_read`),
|
||||
CONSTRAINT `story_drafts_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `story_drafts_ibfk_2` FOREIGN KEY (`story_id`) REFERENCES `stories` (`id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='AI改写草稿表';
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
-- 10个种子故事数据
|
||||
-- 种子数据:测试用户 + 10个故事
|
||||
USE stardom_story;
|
||||
|
||||
-- ============================================
|
||||
-- 测试用户
|
||||
-- ============================================
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(1, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
|
||||
-- ============================================
|
||||
-- 1. 都市言情:《总裁的替身新娘》
|
||||
-- ============================================
|
||||
INSERT INTO stories (id, title, cover_url, description, category, play_count, like_count, is_featured) VALUES
|
||||
(1, '总裁的替身新娘', '', '一场阴差阳错的婚礼,让平凡的你成为了霸道总裁的替身新娘。他冷漠、神秘,却在深夜对你展现出不一样的温柔...', '都市言情', 15680, 3420, TRUE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user