feat: update schema version to 10 and remove scheduled_task_bound_partner migration
This commit is contained in:
1 parent
d53abd5fe5
commit
8a2b906194
4 files changed
+6
-60
No files matched your search
+2
-3
@@ -52,10 +52,9 @@ SQLite 保存以下业务数据:
|
||||
|
||||
### 当前边界
|
||||
|
||||
- 当前代码支持的最终 schema version 是 `11`,由 `CURRENT_SCHEMA_VERSION` 定义。
|
||||
- 当前代码支持的最终 schema version 是 `10`,由 `CURRENT_SCHEMA_VERSION` 定义。
|
||||
- version `1–9` 已随正式版发布,永久保留且不可改写。已知历史例外只有 version 2 的旧名称 `workspace_change_sets`;version 9 继续负责修复通知字段。
|
||||
- version `10` 是破坏性升级,不迁旧数据。`upgrade_from_v9` 从 v9 升级时 DROP 旧表再建最终结构:新增 `partner`;删除 `chat_session`、`chat_session_ui_state`(以及 `chat_conversation_memory`、`chat_session_resume_snapshot`、`ai_run_event`、`chat_session_skill_state`、`chat_message`);`chat_session_message_log` / `ai_run` / `ai_file_change` / `docx_apply` 改挂 `partner_id`;新增 `partner_ui_state`;`workbench_ui_state` 只留 `active_view_key`,删除 `draft_state_json`;`scheduled_task` 改挂 `partner_id`;`workspace_source` 去掉 name 且 `root_path UNIQUE`;`web_source` 去掉 `workspace_id` 且 `UNIQUE(normalized_url)`;`ai_run` 不再保存 `workspace_json`。不存在、也不新建 `chat_search_turn`。新增 `schema_migration_hooks`,供版本声明提交后副作用。v10 的 `afterCommit` 在 SQLite 事务提交后、LanceDB 连接前删除 `userData/lancedb`;hook 记 `pending/done`,失败可重试,`done` 后不重跑。空库仍执行 version `1–10`,跑完后结构与 v9 升级路径一致。
|
||||
- version `11`(`scheduled_task_bound_partner`)重建 `scheduled_task`:增加 `busy_cancel_notice_at`;去掉 `partner_id` 对外键 CASCADE,专属伙伴删除后任务可保留并由服务重建。
|
||||
- version `10` 是破坏性升级,不迁旧数据。`upgrade_from_v9` 从 v9 升级时 DROP 旧表再建最终结构:新增 `partner`;删除 `chat_session`、`chat_session_ui_state`(以及 `chat_conversation_memory`、`chat_session_resume_snapshot`、`ai_run_event`、`chat_session_skill_state`、`chat_message`);`chat_session_message_log` / `ai_run` / `ai_file_change` / `docx_apply` 改挂 `partner_id`;新增 `partner_ui_state`;`workbench_ui_state` 只留 `active_view_key`,删除 `draft_state_json`;`scheduled_task` 改挂 `partner_id`(无外键 CASCADE,专属伙伴删除后任务可保留并由服务重建),并含 `busy_cancel_notice_at`;`workspace_source` 去掉 name 且 `root_path UNIQUE`;`web_source` 去掉 `workspace_id` 且 `UNIQUE(normalized_url)`;`ai_run` 不再保存 `workspace_json`。不存在、也不新建 `chat_search_turn`。新增 `schema_migration_hooks`,供版本声明提交后副作用。v10 的 `afterCommit` 在 SQLite 事务提交后、LanceDB 连接前删除 `userData/lancedb`;hook 记 `pending/done`,失败可重试,`done` 后不重跑。空库仍执行 version `1–10`,跑完后结构与 v9 升级路径一致。
|
||||
- 哪些 migration 已正式发布,以 `migrations/released-migrations.json` 为唯一边界。未进入清单的连续迁移可以在发布前合并或重写;进入清单后只能新增更高版本修复。
|
||||
|
||||
### 版本身份与执行规则
|
||||
|
||||
@@ -13,7 +13,6 @@ import { aiRunExecutionPermissionMigration } from './migrations/007_ai_run_execu
|
||||
import { dropLlmStrategyPreferenceMigration } from './migrations/008_drop_llm_strategy_preference'
|
||||
import { repairAiRuntimeSystemNotificationsColumnMigration } from './migrations/009_repair_ai_runtime_system_notifications_column'
|
||||
import { upgradeFromV9Migration } from './migrations/010_upgrade_from_v9'
|
||||
import { scheduledTaskBoundPartnerMigration } from './migrations/011_scheduled_task_bound_partner'
|
||||
|
||||
export type SqliteDatabase = Database.Database
|
||||
export type SqliteStatement = Database.Statement
|
||||
@@ -28,11 +27,10 @@ const MIGRATIONS: readonly Migration[] = [
|
||||
aiRunExecutionPermissionMigration,
|
||||
dropLlmStrategyPreferenceMigration,
|
||||
repairAiRuntimeSystemNotificationsColumnMigration,
|
||||
upgradeFromV9Migration,
|
||||
scheduledTaskBoundPartnerMigration
|
||||
upgradeFromV9Migration
|
||||
]
|
||||
|
||||
export const CURRENT_SCHEMA_VERSION = 11
|
||||
export const CURRENT_SCHEMA_VERSION = 10
|
||||
|
||||
const MIGRATION_NAME_ALIASES = new Map<number, ReadonlySet<string>>([
|
||||
[2, new Set(['workspace_change_sets'])]
|
||||
|
||||
@@ -159,9 +159,9 @@ CREATE TABLE scheduled_task (
|
||||
ai_preference TEXT NOT NULL DEFAULT 'default',
|
||||
execution_permission TEXT NOT NULL DEFAULT 'full_access',
|
||||
next_run_at INTEGER,
|
||||
busy_cancel_notice_at INTEGER,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
FOREIGN KEY (partner_id) REFERENCES partner(id) ON DELETE CASCADE
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
CREATE INDEX idx_scheduled_task_enabled
|
||||
ON scheduled_task(enabled, next_run_at);
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import type { Migration } from './types'
|
||||
|
||||
/**
|
||||
* scheduled_task:增加 busy_cancel_notice_at;去掉 partner_id 外键 CASCADE,
|
||||
* 专属伙伴删除后任务仍保留,由服务层自动重建伙伴。
|
||||
*/
|
||||
export const scheduledTaskBoundPartnerMigration: Migration = {
|
||||
version: 11,
|
||||
name: 'scheduled_task_bound_partner',
|
||||
run: (db) => {
|
||||
db.exec(`
|
||||
CREATE TABLE scheduled_task_v11 (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL DEFAULT '',
|
||||
prompt TEXT NOT NULL DEFAULT '',
|
||||
enabled INTEGER NOT NULL DEFAULT 0,
|
||||
schedule_type TEXT NOT NULL DEFAULT 'daily',
|
||||
time_of_day TEXT NOT NULL DEFAULT '09:00',
|
||||
weekday INTEGER,
|
||||
partner_id TEXT NOT NULL,
|
||||
main_model_config_id TEXT NOT NULL DEFAULT '',
|
||||
main_model_name TEXT NOT NULL DEFAULT '',
|
||||
ai_preference TEXT NOT NULL DEFAULT 'default',
|
||||
execution_permission TEXT NOT NULL DEFAULT 'full_access',
|
||||
next_run_at INTEGER,
|
||||
busy_cancel_notice_at INTEGER,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO scheduled_task_v11 (
|
||||
id, name, prompt, enabled, schedule_type, time_of_day, weekday,
|
||||
partner_id, main_model_config_id, main_model_name,
|
||||
ai_preference, execution_permission, next_run_at, busy_cancel_notice_at,
|
||||
created_at, updated_at
|
||||
)
|
||||
SELECT
|
||||
id, name, prompt, enabled, schedule_type, time_of_day, weekday,
|
||||
partner_id, main_model_config_id, main_model_name,
|
||||
ai_preference, execution_permission, next_run_at, NULL,
|
||||
created_at, updated_at
|
||||
FROM scheduled_task;
|
||||
|
||||
DROP TABLE scheduled_task;
|
||||
ALTER TABLE scheduled_task_v11 RENAME TO scheduled_task;
|
||||
|
||||
CREATE INDEX idx_scheduled_task_enabled
|
||||
ON scheduled_task(enabled, next_run_at);
|
||||
`)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user