From 0c37c7e6593b2eff1886a39f0e0de26126fb3909 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Sat, 5 Sep 2026 11:54:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=8E=BB=E9=87=8D=E4=B8=8E?= =?UTF-8?q?=E6=94=B9=E5=8F=B7=EF=BC=9A=E6=B6=88=E9=99=A4=E4=B8=8E=20main?= =?UTF-8?q?=20=E7=9A=84=20000050-053=20=E6=92=9E=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除 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 改为条件加索引,兼容已执行旧编号的历史库 --- .../migrations/000051_user_token_version.sql | 10 --------- ...00053_file_upload_owners_cleanup_index.sql | 10 --------- ... => 000067_order_list_least_privilege.sql} | 0 ...ners.sql => 000068_file_upload_owners.sql} | 2 +- ...00069_file_upload_owners_cleanup_index.sql | 21 +++++++++++++++++++ 5 files changed, 22 insertions(+), 21 deletions(-) delete mode 100644 backend/migrations/000051_user_token_version.sql delete mode 100644 backend/migrations/000053_file_upload_owners_cleanup_index.sql rename backend/migrations/{000050_order_list_least_privilege.sql => 000067_order_list_least_privilege.sql} (100%) rename backend/migrations/{000052_file_upload_owners.sql => 000068_file_upload_owners.sql} (92%) create mode 100644 backend/migrations/000069_file_upload_owners_cleanup_index.sql 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;