From e4c255a77a7d49b77670339e5086d5a115b0d873 Mon Sep 17 00:00:00 2001 From: jjaw Date: Fri, 12 Jun 2026 01:38:09 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Aaccount=20expiry=20autopause=20inde?= =?UTF-8?q?x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations_schema_integration_test.go | 1 + .../151_account_autopause_expiry_index_notx.sql | 6 ++++++ ...h_identity_payment_migrations_regression_test.go | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 backend/migrations/151_account_autopause_expiry_index_notx.sql diff --git a/backend/internal/repository/migrations_schema_integration_test.go b/backend/internal/repository/migrations_schema_integration_test.go index 7ef82f0cb3..7d5f66c7f5 100644 --- a/backend/internal/repository/migrations_schema_integration_test.go +++ b/backend/internal/repository/migrations_schema_integration_test.go @@ -32,6 +32,7 @@ func TestMigrationsRunner_IsIdempotent_AndSchemaIsUpToDate(t *testing.T) { requireColumn(t, tx, "accounts", "rate_limit_reset_at", "timestamp with time zone", 0, true) requireColumn(t, tx, "accounts", "overload_until", "timestamp with time zone", 0, true) requireColumn(t, tx, "accounts", "session_window_status", "character varying", 20, true) + requireIndex(t, tx, "accounts", "idx_accounts_autopause_expiry_due") // api_keys: key length should be 128 requireColumn(t, tx, "api_keys", "key", "character varying", 128, false) diff --git a/backend/migrations/151_account_autopause_expiry_index_notx.sql b/backend/migrations/151_account_autopause_expiry_index_notx.sql new file mode 100644 index 0000000000..4fdca30800 --- /dev/null +++ b/backend/migrations/151_account_autopause_expiry_index_notx.sql @@ -0,0 +1,6 @@ +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_accounts_autopause_expiry_due + ON accounts (expires_at) + WHERE deleted_at IS NULL + AND schedulable = TRUE + AND auto_pause_on_expired = TRUE + AND expires_at IS NOT NULL; diff --git a/backend/migrations/auth_identity_payment_migrations_regression_test.go b/backend/migrations/auth_identity_payment_migrations_regression_test.go index d122a3b75a..047ea7de8a 100644 --- a/backend/migrations/auth_identity_payment_migrations_regression_test.go +++ b/backend/migrations/auth_identity_payment_migrations_regression_test.go @@ -155,3 +155,16 @@ func TestMigration135AllowsGitHubAndGoogleAuthProviders(t *testing.T) { require.Contains(t, sql, "'github'") require.Contains(t, sql, "'google'") } + +func TestMigration151AddsAccountAutoPauseExpiryPartialIndex(t *testing.T) { + content, err := FS.ReadFile("151_account_autopause_expiry_index_notx.sql") + require.NoError(t, err) + + sql := string(content) + require.Contains(t, sql, "CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_accounts_autopause_expiry_due") + require.Contains(t, sql, "ON accounts (expires_at)") + require.Contains(t, sql, "WHERE deleted_at IS NULL") + require.Contains(t, sql, "schedulable = TRUE") + require.Contains(t, sql, "auto_pause_on_expired = TRUE") + require.Contains(t, sql, "expires_at IS NOT NULL") +}