update code level

This commit is contained in:
lychang
2026-07-21 01:46:57 +08:00
parent 284e610140
commit c8778c0ed1

View File

@@ -1,35 +1,6 @@
-- 清理不再使用的扩展列(安全重建方式)
-- 通过重建表来移除列,兼容列已存在或已删除的任意状态
-- 重建时需要临时关闭外键约束(因为有其他表 REFERENCES albums)
PRAGMA foreign_keys = OFF;
-- 清理不再使用的索引
-- 注意:不重建 albums 表,因为 4 张子表(images/favorites/album_tags/person_albums)
-- 通过 FOREIGN KEY 引用了 albums(id),DROP TABLE 即使关闭外键检查也会失败。
-- 未使用的列(person_name_original/all_words/tags)已由应用层忽略,不影响功能。
DROP INDEX IF EXISTS idx_albums_cleaned;
-- 重建 albums 表,只保留需要的列
CREATE TABLE IF NOT EXISTS albums_v2 (
id TEXT PRIMARY KEY NOT NULL,
title TEXT NOT NULL DEFAULT '',
document TEXT DEFAULT '',
description TEXT,
cover_image_id TEXT,
image_count INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL DEFAULT (datetime('now', 'localtime'))
);
-- 安全复制数据(SELECT 只取确定存在的列,COALESCE 处理 NULL)
INSERT OR IGNORE INTO albums_v2 (id, title, document, description, cover_image_id, image_count, created_at)
SELECT id, title,
COALESCE(document, ''),
description,
cover_image_id,
image_count,
created_at
FROM albums;
-- 替换旧表
DROP TABLE IF EXISTS albums;
ALTER TABLE albums_v2 RENAME TO albums;
-- 恢复外键约束
PRAGMA foreign_keys = ON;