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") +}