diff --git a/backend/crates/gateway-store/tests/postgres/proxies.rs b/backend/crates/gateway-store/tests/postgres/proxies.rs index 852c212aa..c81b87d64 100644 --- a/backend/crates/gateway-store/tests/postgres/proxies.rs +++ b/backend/crates/gateway-store/tests/postgres/proxies.rs @@ -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 diff --git a/backend/crates/gateway-store/tests/postgres/runtime_settings.rs b/backend/crates/gateway-store/tests/postgres/runtime_settings.rs index 0daeb0e78..47518906f 100644 --- a/backend/crates/gateway-store/tests/postgres/runtime_settings.rs +++ b/backend/crates/gateway-store/tests/postgres/runtime_settings.rs @@ -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() diff --git a/backend/migrations/.frozen-sha256 b/backend/migrations/.frozen-sha256 index e9b314ae7..5cc72da1a 100644 --- a/backend/migrations/.frozen-sha256 +++ b/backend/migrations/.frozen-sha256 @@ -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 diff --git a/backend/migrations/0010_account_auto_freeze.sql b/backend/migrations/0010_account_auto_freeze.sql index 9abaa3c9d..534afee72 100644 --- a/backend/migrations/0010_account_auto_freeze.sql +++ b/backend/migrations/0010_account_auto_freeze.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 diff --git a/backend/migrations/0011_account_auto_freeze_opt_in.sql b/backend/migrations/0011_account_auto_freeze_opt_in.sql deleted file mode 100644 index 70f0dcb1b..000000000 --- a/backend/migrations/0011_account_auto_freeze_opt_in.sql +++ /dev/null @@ -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[] - ); diff --git a/backend/migrations/0012_proxy_request_location.sql b/backend/migrations/0011_proxy_request_location.sql similarity index 100% rename from backend/migrations/0012_proxy_request_location.sql rename to backend/migrations/0011_proxy_request_location.sql