Repository navigation
Conversation
…nabled NOT NULL Co-Authored-By: Claude Fable 5 <[email protected]>
Adds the two partial-index-only FK indexes the audit rule now requires, documents the partition-aware audit count, and adds contract tests pinning ON DELETE actions, orphan sweeps, backfills, and the index list. Co-Authored-By: Claude Fable 5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 920513712b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| UPDATE public.users SET role = 'user' WHERE role IS NULL; | ||
| UPDATE public.users SET enabled = true WHERE enabled IS NULL; | ||
|
|
||
| ALTER TABLE public.users ALTER COLUMN role SET NOT NULL; |
There was a problem hiding this comment.
Supply a role in the plan-store fixture
When SILO_TEST_DATABASE_URL points to a database with this migration applied, newPlanstoreFixture still executes INSERT INTO users (username) VALUES ($1) in internal/playback/planstore/postgres_test.go:95. Because role deliberately has no default, setting it NOT NULL makes fixture creation fail with a not-null violation, so TestPostgresPlanStore can no longer run against the current schema; update the fixture to provide a role rather than relying on the environment-dependent skip.
AGENTS.md reference: AGENTS.md:L147-L150
Useful? React with 👍 / 👎.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
users.role is NOT NULL after the integrity migration and deliberately has no default, so the fixture must provide one. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Verified the Codex P2: |
|
Closing as superseded by the merged schema-hygiene replacement. |
Problem
Related issue: #135 (schema workstream: #888)
Account deletion is a bare
DELETE FROM users WHERE id=$1, but 17 user-referencing columns had no foreign key — every deletion leaks rows (live push routes, webhooks, notification prefs, cached recommendations, in-flight Discord link state, and more). Separately, 46 FK leading columns had no usable index (so FK cascade checks sequential-scan child tables, worst onauth_sessions.user_idanddownloads.media_file_id), andusers.role/users.enabledallowed NULL that no code path writes or handles. The 1.0 squashed baseline should not inherit any of this.Base branch:
schema/hygiene-drop-dead-tables(PR #879) — second PR in the schema-hygiene stack; only the last two commits are new here.Approach
Three migrations, all derived from an empirical audit of the migrated schema (audit queries are committed in the migration comments):
20260901161657_fk_leading_indexes.sql— 57CREATE INDEX CONCURRENTLY(-- +goose NO TRANSACTION), covering the 46 audited unindexed FK leading columns, 10 newly constrained columns, and 2 columns whose only leading index is partial with a predicate on a different column (watch_provider_scrobble_sessions.connection_id,page_sections.library_id). The audit rule is strict: partial indexes never count as FK coverage unless their predicate is<column> IS NOT NULL(nine such documented exceptions, argued in the migration).20260901161700_user_fk_integrity.sql— 17 FKs tousers(id): 14ON DELETE CASCADE(row belongs to the account) and 3ON DELETE SET NULL(attribution on records that outlive the account:activity_log.impersonator_user_id,subtitle_ai_jobs.requested_by,metadata_translation_jobs.requested_by).auth_sessions.impersonator_user_idis deliberately CASCADE — SET NULL would silently convert a live impersonation session into an ordinary session for the impersonated user. EachADD CONSTRAINTis preceded by an orphan sweep scoped exactly to rows whose parent no longer exists (targetedDELETE, orUPDATE … SET NULLfor the attribution columns). Documented exclusions:policy_decisions*(per program plan: hottest write path, rows are historical evidence),notification_server_channels.created_by_user_id(informational-only by that table's recorded convention), foreign-system identity columns, and two text-typed Silo user-id columns that need a retype first (noted in Schema workstream: 1.0 hygiene and migration reset (umbrella) #888).20260901161702_users_role_enabled_not_null.sql— backfillsrole='user'/enabled=true(the code-side defaults), thenSET NOT NULL.migrations/schema_integrity_test.go(new, in the established migrations contract-test style) pins the 17 exactON DELETEactions, each paired orphan sweep, the backfill values, the 57 index names, and that noCREATE INDEXstatement gains aWHEREpredicate (case-insensitive) — mutation-tested: flipping a CASCADE or lowercasing a predicate fails the test.Validation
role/enabled; migration sweeps exactly the orphans, constraints then hold. Independently reproduced by the destructive-safety reviewer with its own seed data (parents/children/orphans) — only orphans touched.EXPLAINconfirms the prioritized indexes are present and usable.make migrate-validate,make embed-stub,go build ./...,gofmt(empty),go vet: pass.golangci-lint run --new-from-merge-base="origin/main": 0 issues.make test-go: all packages ok (includes the new contract tests).make verify-settings-bindings-all,verify-playback-fixtures,verify-local-paths: pass.Risks
SHARE ROW EXCLUSIVEonusersand each child during validation — on large tables that blocks writes for the duration. Accepted as documented maintenance-window behavior per the program's upgrade posture (aNOT VALID/VALIDATEsplit was considered and declined for pre-1.0 simplicity; the migration comments note it).CONCURRENTLYoutside a transaction; the Up includes recovery handling for invalid leftover indexes if a run is interrupted.Checklist
AI Disclosure
watch_provider_scrobble_sessions.connection_idwas uncovered on an unboundedly-growing table) and three minors; all fixed. Round 2 verified closure and mutation-tested the new contract tests, yielding two minor prescriptions (partition-aware audit-count comment; case-insensitive predicate guard), both applied. TheNOT VALIDlock-window suggestion was declined with a written reason (documented maintenance-window posture).