test(environment): 1058 migration three-state verification on real postgres

- fresh database, legacy upgrade (rows get one-shot access key, online=false),
  repeat startup idempotence
- 1058 revised before any database applied it: drop dead token column,
  provision access_key via temporary default so non-empty legacy tables upgrade
- immutable-migration rule skips PR-local migrations until merged; after merge
  the lock applies again
This commit is contained in:
2026-10-09 08:45:54 +08:00
parent a34ba07d5b
commit 7df8762db3
3 changed files with 104 additions and 1 deletions
@@ -6,7 +6,8 @@ ALTER TABLE gateway
DROP COLUMN health_status,
DROP COLUMN last_check_reason,
DROP COLUMN last_checked_at,
ADD COLUMN access_key text NOT NULL,
DROP COLUMN token,
ADD COLUMN access_key text NOT NULL DEFAULT '',
ADD COLUMN online boolean NOT NULL DEFAULT false,
ADD COLUMN last_seen_at timestamptz,
ADD COLUMN version text NOT NULL DEFAULT '';
@@ -14,6 +15,7 @@ ALTER TABLE gateway
-- 既有网关记录补一个一次性访问密钥(随机 48 位十六进制),新网关由平台生成。
UPDATE gateway SET access_key = encode(sha256(('creator-hub-gateway-' || id::text || random()::text)::bytea), 'hex')
WHERE access_key = '';
ALTER TABLE gateway ALTER COLUMN access_key DROP DEFAULT;
-- 统一任务模型:所有平台→网关通信都是持久化任务;全量任务即执行记录。
CREATE TABLE gateway_task (