refactor(db): use version string as primary key for ConfigVersion

-transition `of_config_versions` primary key from `id` to `version` string.
-add database migration files `202606270001_make_version_primary_key.sql` for PostgreSQL and SQLite.
-introduce AfterFind/AfterCreate GORM hooks to preserve JSON backward compatibility.
-refactor API controllers, logics, and front-end typescript definitions to receive `string` parameter.
This commit is contained in:
ryan
2026-06-27 13:23:30 +08:00
parent b48414e1fe
commit 13d6966cb5
11 changed files with 132 additions and 39 deletions
@@ -0,0 +1,19 @@
-- +goose Up
-- Remove old PRIMARY KEY on id, set version as PRIMARY KEY, drop id column
-- 1. 移除旧主键约束
ALTER TABLE of_config_versions DROP CONSTRAINT IF EXISTS of_config_versions_pkey;
-- 2. 移除原先在 version 字段的唯一索引(因为 version 变成主键,主键隐含唯一性)
DROP INDEX IF EXISTS idx_of_config_versions_version;
-- 3. 将 version 设为新主键
ALTER TABLE of_config_versions ADD PRIMARY KEY (version);
-- 4. 彻底删除 id 列
ALTER TABLE of_config_versions DROP COLUMN IF EXISTS id;
-- +goose Down
ALTER TABLE of_config_versions DROP CONSTRAINT IF EXISTS of_config_versions_pkey;
ALTER TABLE of_config_versions ADD COLUMN IF NOT EXISTS id BIGSERIAL PRIMARY KEY;
CREATE UNIQUE INDEX IF NOT EXISTS idx_of_config_versions_version ON of_config_versions (version);