diff --git a/backend/migrations/000051_user_token_version.sql b/backend/migrations/000051_user_token_version.sql deleted file mode 100644 index 2febaf3..0000000 --- a/backend/migrations/000051_user_token_version.sql +++ /dev/null @@ -1,10 +0,0 @@ --- +goose Up - --- 用户会话版本:冻结、改密和退出时递增,立即撤销旧 access/refresh token。 -ALTER TABLE users - ADD COLUMN token_version BIGINT NOT NULL DEFAULT 1 COMMENT '用户令牌版本'; - --- +goose Down - -ALTER TABLE users - DROP COLUMN token_version; diff --git a/backend/migrations/000053_file_upload_owners_cleanup_index.sql b/backend/migrations/000053_file_upload_owners_cleanup_index.sql deleted file mode 100644 index 9ac010a..0000000 --- a/backend/migrations/000053_file_upload_owners_cleanup_index.sql +++ /dev/null @@ -1,10 +0,0 @@ --- +goose Up - --- 为长期未关联上传归属记录的定时清理提供索引。 -ALTER TABLE file_upload_owners - ADD KEY idx_file_upload_owners_created_at (created_at); - --- +goose Down - -ALTER TABLE file_upload_owners - DROP INDEX idx_file_upload_owners_created_at; diff --git a/backend/migrations/000050_order_list_least_privilege.sql b/backend/migrations/000067_order_list_least_privilege.sql similarity index 100% rename from backend/migrations/000050_order_list_least_privilege.sql rename to backend/migrations/000067_order_list_least_privilege.sql diff --git a/backend/migrations/000052_file_upload_owners.sql b/backend/migrations/000068_file_upload_owners.sql similarity index 92% rename from backend/migrations/000052_file_upload_owners.sql rename to backend/migrations/000068_file_upload_owners.sql index 51f5cfe..f340093 100644 --- a/backend/migrations/000052_file_upload_owners.sql +++ b/backend/migrations/000068_file_upload_owners.sql @@ -1,7 +1,7 @@ -- +goose Up -- 私有文件上传归属:在业务记录写入前,仅允许上传者预览自己的临时文件。 -CREATE TABLE file_upload_owners ( +CREATE TABLE IF NOT EXISTS file_upload_owners ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT UNSIGNED NOT NULL, object_key VARCHAR(512) NOT NULL, diff --git a/backend/migrations/000069_file_upload_owners_cleanup_index.sql b/backend/migrations/000069_file_upload_owners_cleanup_index.sql new file mode 100644 index 0000000..3f5b6c1 --- /dev/null +++ b/backend/migrations/000069_file_upload_owners_cleanup_index.sql @@ -0,0 +1,21 @@ +-- +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;