Files
rust-imager/migrations/005_cleanup.sql
2026-07-21 01:43:16 +08:00

30 lines
923 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 清理不再使用的扩展列(安全重建方式)
-- 通过重建表来移除列,兼容列已存在或已删除的任意状态
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 只取确定存在的列)
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;