PRAGMA foreign_keys=OFF;--> statement-breakpoint CREATE TABLE `__new_sessions` ( `id` text PRIMARY KEY NOT NULL, `source` text NOT NULL, `profile_id` text, `provider` text NOT NULL, `model` text NOT NULL, `permission_mode` text, `system_prompt_append` text DEFAULT '' NOT NULL, `provider_session_id` text, `workspace_dir` text NOT NULL, `title` text DEFAULT '' NOT NULL, `last_seq` integer DEFAULT 0 NOT NULL, `archived` integer DEFAULT false NOT NULL, `created_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL, `updated_at` text DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')) NOT NULL ); --> statement-breakpoint INSERT INTO `__new_sessions`("id", "source", "profile_id", "provider", "model", "permission_mode", "system_prompt_append", "provider_session_id", "workspace_dir", "title", "last_seq", "archived", "created_at", "updated_at") SELECT "id", "source", "profile_id", "provider", "model", "permission_mode", "system_prompt_append", "provider_session_id", "workspace_dir", "title", "last_seq", "archived", "created_at", "updated_at" FROM `sessions`;--> statement-breakpoint DROP TABLE `sessions`;--> statement-breakpoint ALTER TABLE `__new_sessions` RENAME TO `sessions`;--> statement-breakpoint PRAGMA foreign_keys=ON;--> statement-breakpoint CREATE INDEX `sessions_source_idx` ON `sessions` (`source`,`updated_at`);--> statement-breakpoint ALTER TABLE `api_keys` ADD `allowed_profile_ids` text DEFAULT '[]' NOT NULL;--> statement-breakpoint ALTER TABLE `api_keys` ADD `default_profile_id` text;--> statement-breakpoint ALTER TABLE `profiles` ADD `builtin` integer DEFAULT false NOT NULL;--> statement-breakpoint -- 数据迁移:自带的"通用助手"标记为内置(不可删除) UPDATE `profiles` SET `builtin` = 1 WHERE `id` = (SELECT `id` FROM `profiles` ORDER BY (`name` = '通用助手') DESC, `created_at` ASC LIMIT 1);--> statement-breakpoint -- 已有的 API Key 只开放内置 Profile,并设为默认 UPDATE `api_keys` SET `allowed_profile_ids` = json_array((SELECT `id` FROM `profiles` WHERE `builtin` = 1)), `default_profile_id` = (SELECT `id` FROM `profiles` WHERE `builtin` = 1) WHERE EXISTS (SELECT 1 FROM `profiles` WHERE `builtin` = 1);--> statement-breakpoint -- 平台创建的会话:权限模式改为跟随 Profile UPDATE `sessions` SET `permission_mode` = NULL WHERE `source` <> 'admin';--> statement-breakpoint -- 后台会话:与所用 Profile 相同的权限模式也改为跟随 Profile UPDATE `sessions` SET `permission_mode` = NULL WHERE `permission_mode` = (SELECT `p`.`permission_mode` FROM `profiles` `p` WHERE `p`.`id` = `sessions`.`profile_id`);