diff --git a/scripts/create_tables.py b/scripts/create_tables.py index d2f4ebd..b2fd415 100644 --- a/scripts/create_tables.py +++ b/scripts/create_tables.py @@ -304,6 +304,30 @@ async def main(): except Exception as e: print(f' WARN: pipeline_git_locks ensure failed: {e}') + # sd_iterations 迭代序号 seq_no 列 + 存量回填 + 脏状态修复(active→in_progress) + # 「当前迭代」改为显式 status='in_progress' 标记,迭代按 seq_no 顺序编号推进, + # 不再靠 created_at 推断当前迭代。 + try: + r = await sor.sqlExe( + "SELECT COUNT(*) as c FROM information_schema.COLUMNS " + "WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='sd_iterations' " + "AND COLUMN_NAME='seq_no'", {}) + await sor.sqlExe("COMMIT", {}) + if not r or getattr(r[0], 'c', 0) == 0: + await sor.execute("ALTER TABLE sd_iterations ADD COLUMN seq_no INT NOT NULL DEFAULT 0", {}) + # 存量回填:seq_no=0 的迭代按每项目 created_at ASC 顺序赋 1,2,3... + await sor.sqlExe( + "UPDATE sd_iterations t JOIN (" + "SELECT id, ROW_NUMBER() OVER (PARTITION BY project_id ORDER BY created_at ASC, id ASC) AS rn " + "FROM sd_iterations WHERE seq_no = 0) x ON x.id = t.id " + "SET t.seq_no = x.rn", {}) + # 脏状态修复:迭代状态合法值 planning/in_progress/completed/cancelled,无 active + await sor.sqlExe( + "UPDATE sd_iterations SET status='in_progress', updated_at=NOW() WHERE status='active'", {}) + print(' migrate: sd_iterations seq_no column + backfill + active→in_progress ensured') + except Exception as e: + print(f' WARN: sd_iterations migrate failed: {e}') + if __name__ == '__main__': asyncio.run(main())