refactor(store): consolidate unreleased account migrations

Default account auto-freeze to off in its initial migration and renumber request location to 0011. Update checksum entries and migration tests.

These migrations were not included in v3.8.0. Existing PR freeze rules remain unchanged.

Validation: 18 gateway-store tests with isolated PostgreSQL, upgrade from the v3.8.0 schema, migration checksums and numbering, and Rustfmt.

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Zyy
2026-09-17 03:47:53 +08:00
co-authored by Codex
parent bd61e0391a
commit 1e7ea8d46f
6 changed files with 8 additions and 43 deletions
@@ -834,7 +834,7 @@ async fn migration_backfills_shared_proxies_without_changing_credentials() {
.await
.unwrap();
sqlx::raw_sql(include_str!(
"../../../../migrations/0012_proxy_request_location.sql"
"../../../../migrations/0011_proxy_request_location.sql"
))
.execute(&database.pool)
.await
@@ -355,7 +355,7 @@ async fn request_location_defaults_and_updates_reach_the_runtime_snapshot() {
}
#[tokio::test]
async fn auto_freeze_defaults_off_and_migration_preserves_explicit_opt_in() {
async fn auto_freeze_defaults_off_and_explicit_opt_in_round_trips() {
let Some(database) = TestDatabase::create("freeze_opt_in").await else {
return;
};
@@ -367,32 +367,10 @@ async fn auto_freeze_defaults_off_and_migration_preserves_explicit_opt_in() {
.expect("default settings")
.account_auto_freeze_enabled
);
sqlx::query("update runtime_settings set account_auto_freeze_enabled = true where id = 1")
.execute(&database.pool)
.await
.expect("old default");
let migration = include_str!("../../../../migrations/0011_account_auto_freeze_opt_in.sql");
sqlx::raw_sql(migration)
.execute(&database.pool)
.await
.expect("migrate untouched default");
assert!(
!repository
.load_runtime_settings()
.await
.expect("settings")
.account_auto_freeze_enabled
);
sqlx::query("update runtime_settings set account_auto_freeze_enabled = true where id = 1")
.execute(&database.pool)
repository
.update_runtime_settings(settings_with_margin(3_600))
.await
.expect("explicit opt-in");
sqlx::query("insert into admin_audit_events (id, actor_kind, actor_ref, action, entity_kind, entity_ref, changed_fields, created_at) values ('freeze-opt-in', 'system', 'test', 'settings.replace', 'runtime_settings', '1', array['account_auto_freeze'], now())")
.execute(&database.pool).await.expect("saved settings audit");
sqlx::raw_sql(migration)
.execute(&database.pool)
.await
.expect("preserve opt-in");
assert!(
repository
.load_runtime_settings()
+2 -3
View File
@@ -7,6 +7,5 @@ b7d3df7b48d835a00a3b74cbefc958a039d38fea5529cdad04bfbc703dca72aa 0001_initial.s
18e8c1b71c896a9d576d9e4ef9701506f654f55383af908898195b9eb2980fde 0007_account_notes.sql
36b720c9d3e6bf0bdb799b9b6a89b81638c642ac866992a880bd82357012a208 0008_concurrency_queues.sql
161df9ae43da34d51b340bbf95d71c61a8c1a2aa142382f693a9d127c834630d 0009_account_model_access.sql
dd4aa34e9bcf1698bb9688421964bbf410314d8e905448b8229460b972cff2f6 0010_account_auto_freeze.sql
9bd261b7e94872126754eb7f749c56187264a47c567b0bef5c394d6776b4f463 0011_account_auto_freeze_opt_in.sql
ae7f7acb3014f0a60d979dd9c04b3065322b206e42eb6256505baf78caf9dd22 0012_proxy_request_location.sql
3751a802e80b5d538abc5619a2397aa4bf13f52076068a489892f664907adf49 0010_account_auto_freeze.sql
ae7f7acb3014f0a60d979dd9c04b3065322b206e42eb6256505baf78caf9dd22 0011_proxy_request_location.sql
@@ -1,8 +1,8 @@
-- 账号容量熔断:统计窗口内高频出现容量类上游错误时自动冻结账号一段时间;
-- 恢复前可选执行一次探测调用验证上游已恢复;冻结期间按观测到的在途并发峰值
-- 下调账号并发上限,让账号带着更安全的并发配置自愈。默认启用,已有实例可关闭。
-- 下调账号并发上限,让账号带着更安全的并发配置自愈。默认关闭,需在设置页显式启用。
alter table runtime_settings
add column account_auto_freeze_enabled boolean not null default true,
add column account_auto_freeze_enabled boolean not null default false,
add column account_auto_freeze_threshold bigint not null default 12
check (account_auto_freeze_threshold between 2 and 1000),
add column account_auto_freeze_window_seconds bigint not null default 600
@@ -1,12 +0,0 @@
-- 自动冻结默认关闭;保留已经通过设置页显式保存的冻结配置。
alter table runtime_settings
alter column account_auto_freeze_enabled set default false;
update runtime_settings
set account_auto_freeze_enabled = false
where account_auto_freeze_enabled = true
and not exists (
select 1 from admin_audit_events
where action = 'settings.replace'
and changed_fields @> array['account_auto_freeze']::text[]
);