From fa3de8bf966a69a436b68acdd31c2ae50a6140be Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 19 Aug 2026 17:06:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(iteration):=20create=5Ftables.py=20?= =?UTF-8?q?=E5=B9=82=E7=AD=89=E8=BF=81=E7=A7=BB=E2=80=94=E2=80=94sd=5Fiter?= =?UTF-8?q?ations=20=E5=8A=A0=20seq=5Fno=20=E5=88=97=20+=20=E5=AD=98?= =?UTF-8?q?=E9=87=8F=E5=9B=9E=E5=A1=AB=20+=20active=E2=86=92in=5Fprogress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/create_tables.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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())