feat: migrate course content start time and series price
Some checks failed
build / build (push) Has been cancelled

This commit is contained in:
Glore Zeng 2026-10-19 22:47:31 +08:00
parent 093f0ca14a
commit d76623f59d
4 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE course DROP COLUMN start_time, DROP COLUMN content_html;
ALTER TABLE course_series DROP COLUMN price, DROP COLUMN start_time, DROP COLUMN content_html;

View File

@ -0,0 +1,2 @@
ALTER TABLE course ADD COLUMN start_time DATETIME NULL, ADD COLUMN content_html LONGTEXT NULL;
ALTER TABLE course_series ADD COLUMN price INT NULL COMMENT 'Independent series price in cents; NULL means not configured', ADD COLUMN start_time DATETIME NULL, ADD COLUMN content_html LONGTEXT NULL;

View File

@ -5,3 +5,5 @@
在上级工作区运行 `./scripts/workspace.ps1 migrate`,使用隔离的本地 MySQL 和 golang-migrate 记录版本。已有数据库须先核对 schema_migrations 与实际结构;禁止盲目 force。已执行的 SQL 不修改,新变更新增时间戳文件。 在上级工作区运行 `./scripts/workspace.ps1 migrate`,使用隔离的本地 MySQL 和 golang-migrate 记录版本。已有数据库须先核对 schema_migrations 与实际结构;禁止盲目 force。已执行的 SQL 不修改,新变更新增时间戳文件。
`node scripts/check-migrations.mjs` 仅检查命名、版本唯一性和非空。SQL 是否可执行须在脱敏基线数据库验证。现有迁移无 down 脚本,生产回退依赖经验证的备份恢复或补偿迁移,不自动回滚。 `node scripts/check-migrations.mjs` 仅检查命名、版本唯一性和非空。SQL 是否可执行须在脱敏基线数据库验证。现有迁移无 down 脚本,生产回退依赖经验证的备份恢复或补偿迁移,不自动回滚。
新增 `1792400000_course_details.up.sql`:为 course 和 course_series 增加 start_time、content_html,系列增加可空独立售价 price(分)。先迁移,再部署对应 API。该版本包含 down 脚本,执行会丢失这些新字段中的数据,必须先备份。历史版本仍无 down 脚本。已在 MySQL 8 临时表验证此版本 up/down;生产完整基线仍需部署前验证。

View File

@ -4,10 +4,12 @@ const files = readdirSync('.').filter(f => f.endsWith('.sql')).sort();
assert(files.length > 0, 'No migrations'); assert(files.length > 0, 'No migrations');
const versions = new Set(); const versions = new Set();
for (const file of files) { for (const file of files) {
const match = /^(\d+)_[a-z0-9_]+\.up\.sql$/.exec(file); const match = /^(\d+)_([a-z0-9_]+)\.(up|down)\.sql$/.exec(file);
assert(match, `Invalid migration filename: ${file}`); assert(match, `Invalid migration filename: ${file}`);
assert(!versions.has(match[1]), `Duplicate version: ${file}`); const key = `${match[1]}:${match[3]}`;
versions.add(match[1]); assert(!versions.has(key), `Duplicate version and direction: ${file}`);
versions.add(key);
if (match[3] === 'down') assert(files.includes(`${match[1]}_${match[2]}.up.sql`), `Missing matching up migration: ${file}`);
assert(readFileSync(file, 'utf8').trim(), `Empty migration: ${file}`); assert(readFileSync(file, 'utf8').trim(), `Empty migration: ${file}`);
} }
console.log(`${files.length} migration files checked (structure only; MySQL execution still required).`); console.log(`${files.length} migration files checked (structure only; MySQL execution still required).`);