Files
hfb_sys/backend/migrations/000069_file_upload_owners_cleanup_index.sql
T
yml2213 0c37c7e659 迁移去重与改号:消除与 main 的 000050-053 撞号
- 删除 dev 的 000051_user_token_version(main 的 000052_user_token_version 已实现同列)
- order_list_least_privilege / file_upload_owners / cleanup_index 改号为 000067-000069
- 000068 改为 CREATE TABLE IF NOT EXISTS、000069 改为条件加索引,兼容已执行旧编号的历史库
2026-09-05 11:54:53 +08:00

22 lines
682 B
SQL

-- +goose Up
-- 为长期未关联上传归属记录的定时清理提供索引。
-- 兼容历史上已按旧编号执行过该索引的数据库,重复执行时跳过。
SET @idx_exists := (
SELECT COUNT(*) FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'file_upload_owners'
AND index_name = 'idx_file_upload_owners_created_at'
);
SET @ddl := IF(@idx_exists > 0,
'SELECT 1',
'ALTER TABLE file_upload_owners ADD KEY idx_file_upload_owners_created_at (created_at)');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- +goose Down
ALTER TABLE file_upload_owners
DROP INDEX idx_file_upload_owners_created_at;