mirror of
https://github.com/chatfire-AI/huobao-drama.git
synced 2026-08-28 18:07:48 +08:00
9998c3a769
- storyboards 表删除 action/dialogue 两列;启动迁移带守卫(SHOW COLUMNS), 先把存量数据合并进 description(action 直接追加、dialogue 以「对白:」前缀追加)再 DROP - 画面描述统一按【镜头N】承载子镜头画面与台词/旁白(「角色名说:「…」」「旁白:…」) - storyboard_breaker prompt/skill 字段清单收敛为 description+atmosphere, 对白下限改为按 description 中台词字数计算的台词时长下限 - video-prompt skill 与 prompt_generator 系统提示词新增映射规则: 每个【镜头N】→ 1-2 个连续 3 秒段,台词从 description 原位提取,不新创台词 - 工作台分镜面板移除「动作」编辑框与「添加对白/旁白」入口,只保留画面描述与氛围 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
/**
|
|
* 导出初始化 SQL — 把 src/db/mysql-schema.ts 中的内嵌 DDL/种子生成为独立 init.sql
|
|
*
|
|
* 用法: npx tsx scripts/export-init-sql.ts [输出路径]
|
|
* 默认输出: <repo>/docker/init.sql
|
|
*
|
|
* 说明:
|
|
* - 应用启动时本就会自动执行同样的初始化(initMySqlSchema: 建表 + 种子),该文件是可选产物,
|
|
* 用于 DBA 审核、预建表或挂到 MySQL 容器的 /docker-entrypoint-initdb.d/
|
|
*/
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
import {
|
|
mysqlSchemaStatements,
|
|
mysqlDataSeedStatements,
|
|
} from '../src/db/mysql-schema.js'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
const outPath = path.resolve(process.argv[2] || path.join(__dirname, '../../docker/init.sql'))
|
|
|
|
/** 把 ? 占位符内联为 SQL 字面量(导出静态文件,不走参数化) */
|
|
function inlineParams(sql: string, params: unknown[]): string {
|
|
let i = 0
|
|
const inlined = sql.replace(/\?/g, () => {
|
|
const v = params[i++]
|
|
if (v === null || v === undefined) return 'NULL'
|
|
if (typeof v === 'number') return String(v)
|
|
return `'${String(v).replace(/'/g, "''")}'`
|
|
})
|
|
if (i !== params.length) throw new Error(`参数数量与占位符不匹配: ${sql}`)
|
|
return inlined
|
|
}
|
|
|
|
const sections: string[] = []
|
|
|
|
sections.push(`-- ============================================================================
|
|
-- Huobao Drama 初始化 SQL
|
|
-- 由 backend/scripts/export-init-sql.ts 从 backend/src/db/mysql-schema.ts 生成
|
|
-- 生成时间: ${new Date().toISOString()}
|
|
--
|
|
-- 注意: 应用启动时会自动执行同等初始化(幂等),本文件不是部署必需,
|
|
-- 仅供 DBA 审核或在应用外预建表使用
|
|
-- ============================================================================
|
|
|
|
SET NAMES utf8mb4;
|
|
`)
|
|
|
|
sections.push(`-- ----------------------------------------------------------------------------
|
|
-- 1. 建表(${mysqlSchemaStatements.length} 张)
|
|
-- ----------------------------------------------------------------------------
|
|
${mysqlSchemaStatements.map(s => `${s};`).join('\n\n')}
|
|
`)
|
|
|
|
sections.push(`-- ----------------------------------------------------------------------------
|
|
-- 2. 种子数据: 风格预设(幂等,只补缺失行)
|
|
-- ----------------------------------------------------------------------------
|
|
${mysqlDataSeedStatements.map(s => `${inlineParams(s.sql, s.params)};`).join('\n')}
|
|
`)
|
|
|
|
fs.mkdirSync(path.dirname(outPath), { recursive: true })
|
|
fs.writeFileSync(outPath, sections.join('\n'), 'utf8')
|
|
console.log(`✅ 已导出: ${outPath}`)
|
|
console.log(` 建表 ${mysqlSchemaStatements.length} 条, 种子 ${mysqlDataSeedStatements.length} 条`)
|