Repository navigation
Add soft-delete columns and erase-path indexes - #1331
Conversation
Replace the boot-time DDL loop in PostgresStore.migrate with pressly/goose v3. Version 1 is the 255 statements the loop ran, unchanged and in order, outside a transaction. Versions 2 to 5 are the retired-backfill guard and the three concurrent index builds, with their code unchanged. Goose records each version in goose_db_version and holds a session advisory lock, so a second coordinator applies nothing. The migration session sets lock_timeout 3s and statement_timeout 10min, and migrate retries a lock timeout up to three times. Check in the pg_dump of the pre-goose schema as coordinator/store/schema/schema.sql. Tests prove that goose builds that schema on a fresh database, leaves a legacy database unchanged apart from goose_db_version, applies once under two concurrent runners, and retries a lock timeout. goose v3.28.0 needs Go 1.26 and the coordinator image builds with Go 1.25, so this pins v3.27.3 and raises the go directive to 1.25.7. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs-check treats an inline-code repo path as a citation; the placeholder file name failed Docs Lint. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add sqlc v1.31.1 (pinned through go run in the Makefile; a go.mod tool directive would need Go 1.26). sqlc reads coordinator/store/schema/schema.sql and generates coordinator/store/storedb from queries/api_keys.sql. The api_keys methods of PostgresStore move to postgres_api_keys.go and call the generated queries; the Store interface, MemoryStore and CachedStore do not change. make sqlc-generate regenerates the code. make sqlc-check fails when the schema file or the generated code is stale; CI runs it in the Coordinator Tests job, whose Postgres service moves to 17 to match production. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New goose migrations 6 to 17, no change to the baseline: - 6-12: one CREATE INDEX CONCURRENTLY per file on the account columns that account erasure filters by; each drops an invalid leftover first and waits up to 1 min for older snapshots. - 13: deleted_at TIMESTAMPTZ on users, api_keys, providers, provider_tokens. - 14-16: users.privy_user_id is unique among live users only. - 17: referrals.referrer_code foreign key with ON UPDATE CASCADE, added NOT VALID and validated. Every read that returns a live user, key, provider record or provider token now filters deleted_at IS NULL, including GetProviderForRestore. MemoryStore mirrors this with DeletedAt fields. Nothing sets deleted_at yet; tests set it and prove each read hides the row on both stores. Regenerate schema.sql and the sqlc code; keep the pre-goose dump as testdata for the upgrade test. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Deployment failed for project d-inference with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
With -v the CI log shows PASS (or SKIP) for TestMigrationsBuildCheckedInSchema instead of only the package line. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Deployment failed for project eigen-homepages-darkbloom with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
|
Deployment failed for project d-inference-console-ui-dev with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
|
Deployment failed for project d-inference-landing with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
…chema Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5c09f50 to
1475925
Compare
Moving it to 17 is outside this change. The schema check compares catalog snapshots, so it does not depend on the server version. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…chema Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A CREATE INDEX CONCURRENTLY in an SQL migration that fails (for example on the 3 s lock_timeout) leaves an invalid index; with IF NOT EXISTS the next attempt skips it and goose records the version. The how-to now shows index builds as Go migrations through ensureConcurrentIndex, and TestSQLMigrationsDoNotBuildIndexesConcurrently fails on an SQL file that builds one. Docs: destructive migrations must wait until no pre-goose fallback image can start; migrations and the baseline repairs run once; the startup diagram shows the unlocked pending check before the advisory lock; the 5 min lock wait and the fail-safe first deploy under long reads. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Versions 6-12 and 14 were SQL files with DROP ... IF EXISTS and CREATE INDEX CONCURRENTLY. They move to indexMigrations, which build each index through buildConcurrentIndex on a connection of its own with a 1 min lock_timeout: a valid index returns at once, an invalid leftover is dropped and built again, and the migration fails unless the result is valid, so goose never records a broken index. Tests: an invalid leftover of the same name (made by a build that times out behind an older snapshot) is rebuilt and the version recorded; a unique build that cannot succeed fails migrate and leaves its version unrecorded. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…chema Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # coordinator/store/postgres_migrations_test.go # docs/architecture/storage.md # docs/developer/database-migrations.md # docs/operations/coordinator-deploy.md
Add docs/architecture/schema-lifecycle.md as the explanation of how the schema changes: the startup path from NewPostgres through goose, the migration kinds, the locks and timeouts, the retired-backfill guard, invariants, failure modes and a code map. storage.md now links to it instead of holding the migration mechanism. Rewrite docs/developer/database-migrations.md around a decision table, steps for each migration kind, expand and contract in two releases, and the pre-goose fallback rule. Add docs/operations/schema-migration.md: scope, Cloud SQL backup, long query check, --migrate-only with its real log lines, verification queries, troubleshooting, rollback rules and the first cut-over checklist. coordinator-deploy.md links to it. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in the schema lifecycle page, the rewritten migration how-to and the schema migration runbook. storage.md and database-migrations.md conflicted: the migration mechanism moved to schema-lifecycle.md, so this keeps the new structure and carries over the sqlc code-map row, the sqlc-generate step and the sqlc-check verification. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docs/developer/sqlc.md: add a query, convert a hand-written store domain with api_keys as the worked example, naming and parameter conventions, make sqlc-generate and sqlc-check, and troubleshooting for a stale schema, DO-block columns, uncast expressions and reused parameters. Add docs/reference/sqlc-type-mapping.md, written from sqlc.yaml and the generated storedb code: the flags that change types, every mapping the current queries use with its store conversion, the query commands, and the schema types that no query reads yet. schema-lifecycle.md gains the schema.sql to sqlc to storedb to PostgresStore flow with a diagram, an invariant and code-map rows. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…chema Brings in the schema lifecycle page, the migration how-to, the schema migration runbook and the sqlc pages. storage.md, database-migrations.md and coordinator-deploy.md conflicted because the migration mechanism moved to schema-lifecycle.md. This keeps the new structure and carries over the soft-delete section, its invariant and failure mode, the indexMigrations recipe and the pre-goose rollback rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add docs/reference/soft-delete.md: the tables with deleted_at, every store read that hides a soft-deleted row in PostgresStore and MemoryStore, the paths that do not filter, the indexes, and what a soft delete changes. schema-lifecycle.md gains versions 6 to 17, the indexMigrations kind with its 1 min lock_timeout and leftover repair, the soft-delete model with a diagram, and the matching invariants and failure modes. The migration how-to gains real examples for each kind, the new tests and an "add soft delete to a table" procedure. The runbook gains the soft-delete rollback rules and a checklist for the soft-delete release; coordinator-deploy.md links to them instead of repeating them. Refs DBLM-552 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the copied row-scan loops in TestMigrationsLeaveLegacyDatabaseUnchanged with queryLines, and rename assertSameSchema to assertSameLines because it also compares row lists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Threat model review — advisoryReviewed head Review not completed for this head. Previous findings are superseded, not confirmed resolved. Models: budgeted Sonnet / selective Opus / selective Sol 6.1. Findings require human validation; this review never requests changes or blocks merging. Coverage: 0/0 source units; cross-file integration pending. 0 selected depth batch(es) pending. All threat definitions indexed; relevant full definitions selected. Unchanged callers are not scanned. Cost this run: $0.0000 reported, $0.0000 reserved with unknown cost; 0 paid request(s), 0 reused batch(es), 0 provider cache-hit tokens. Saved findings and earlier report · Historical findings are not confirmed resolved. |
|
Found 1 test failure on Blacksmith runners: Failure
|
Summary
Hide soft-deleted users, API keys, providers, and provider tokens from live store reads, permit a new live account to reuse an erased account’s Privy ID, and add indexes for account erasure. This layer supplies schema and read behavior; #1332 supplies the erasure writer and cache invalidation.
Targets
master; #1329 is already merged and is no longer a pending dependency. The branch incorporates its SQLC changes and the merged Goose implementation. Existing migrations 1–9 and the frozen legacy fixture remain intact. Linear: DBLM-552.Before
flowchart TD A["Account, contact, or provider lookup"] --> B["Store reads every matching row"] B --> C["Deleted identity can remain visible or restorable"] D["Sign up again"] --> E[("Global Privy-ID uniqueness")] E --> F["Old row prevents a new live account"] G["Future account scrub"] --> H["Account-linked history scans"] classDef process fill:#dbeafe,stroke:#2563eb,color:#172554 classDef risk fill:#fee2e2,stroke:#dc2626,color:#450a0a class A,B,D,E,G process class C,F,H riskAfter
flowchart TD M["Goose migrations 10–21"] --> S[("deleted_at + account indexes + live Privy uniqueness")] A["Account, contact, or provider lookup"] --> P["Postgres and memory domain reads"] P --> Q["Filter deleted_at, including provider restore"] --> R["Only live records returned"] D["Sign up again"] --> S --> U["One live account per Privy ID"] M --> I["Concurrent index build: repair leftovers and verify validity"] S --> F["Initial MDM cohort: only live users and providers"] classDef process fill:#dbeafe,stroke:#2563eb,color:#172554 classDef schema fill:#ede9fe,stroke:#7c3aed,color:#2e1065 classDef checked fill:#dcfce7,stroke:#16a34a,color:#052e16 class A,P,D process class M,S schema class Q,R,U,I,F checkedBlue shows callers and domain ownership, purple the schema, and green the enforced behavior.
Schema and compatibility
deleted_atonusers,api_keys,providers, andprovider_tokens, without defaults.ON UPDATE CASCADEbefore removing the old constraint.Each concurrent build uses a dedicated connection with a one-minute lock timeout, repairs an invalid leftover, and verifies validity before Goose records success. It does not add a statement timeout; an explicit database-URL setting still applies. Ordinary schema changes retain the runner’s three-second lock timeout.
Deploy Goose before this layer. Once deleted and live users share a Privy ID, a pre-Goose image cannot recreate its global unique index. Rollbacks must retain Goose; use the updated schema-migration runbook. No baseline rewrite or automatic down migration is introduced.
Implementation
DeletedAtfields. Existing mutation behavior is preserved until the writer layer introduces account-state guards.Squash-safe stack tooling
AGENTS.md(Stacked PRs) anddocs/developer/pull-requests.mddocument the reusablescripts/restack-after-squash.pyworkflow. Seven local Git fixture tests cover the tooling. It verifies the original parent/squash tree and ancestry, creates signed same-treegit commit-treecommits, and supports an atomic non-force push with optional retargeting. Divergent trees are refused rather than manually resolved or silently overwritten.Before: stack tooling
After: stack tooling
flowchart TD A["restack-after-squash.py --check"] --> B{"Original/squash tree<br/>and ancestry verified?"} B -- "no" --> X["Refuse divergence"] B -- "yes; authorized --push" --> C["Signed same-tree git commit-tree"] C --> D["Atomic non-force push"] D --> E["Optional --retarget; recheck CI and approvals"] classDef process fill:#dbeafe,stroke:#2563eb,color:#172554 classDef gate fill:#fef3c7,stroke:#d97706,color:#451a03 classDef checked fill:#dcfce7,stroke:#16a34a,color:#052e16 classDef risk fill:#fee2e2,stroke:#dc2626,color:#450a0a class A process class B gate class C,D,E checked class X riskBlue identifies workflow entry points, amber verification, green content-preserving updates, and red refused or risky paths.
Validation
Final pushed heads: #1331
cd29e84d4, #133269cb0eb87, #1333eef27a3d9. GitHub signatures are verified; all three PRs are currentlyMERGEABLEagainst their existing parents. This is not a claim that remote CI or approval gates are complete.All affected tests passed on the prior integrated head (
88a19948a), not rerun on the newest heads, withCGO_ENABLED=0andDATABASE_URLpointing to disposable PostgreSQL 16:go test ./coordinator/tests/store/... ./coordinator/tests/api/accounts/contracts ./coordinator/tests/provideremail/... ./coordinator/tests/datadog -count=1. Store contracts completed in 100.555 seconds.SQLC/schema checks passed at each schema layer. Host build passed on the prior integrated head
88a19948a; Linux build passed before the preceding test/documentation-only edits. Neither build is claimed as rerun on the newest heads.make docs-checkandmake docs-impact-checkagainst each PR's actual parent passed for all three layers.Dedicated fresh refactor passes were performed, including the new restacking tooling. No code cleanup was warranted; one Resend public-field documentation correction was made. Negative controls reproduced the stale-location, referral-credit, and raw-error-logging failures.
The full coordinator run passed 40 API shards and 90 other packages, but was NOT fully green: five preexisting routing tests also fail on clean
masterat470a86d47, independently verified. Release Integrity'stest-integration-ci-workflow.pyalso has a baseline failure involving newer coverage arguments.Integration failures introduced by the Resend counts and billing referral fixture were fixed; the affected test command above passed afterward on
88a19948a.The final code-quality cleanup removes one unused
subprocessimport from a script test; there are no product-code differences from the prior tested stack. All seven script tests were rerun and passed after cleanup.make docs-checkandmake docs-impact-checkagainst the actual parents passed again for all three layers. The code-quality thread was replied to and resolved.Remote CI remains pending/subject to the known baseline blockers; required approvals remain outstanding. A human explicitly authorized bypassing the local pre-push hook only after baseline reproduction. Remote CI remains enabled; that authorization does not waive remote checks or approvals.
Squash landing order
#1329 is already merged. Current bases remain #1331 ->
master, #1332 ->feat/store-soft-delete-schema, and #1333 ->feat/account-erasure.masteris squash-only: land #1331, then #1332, then #1333.One-time parent merges do not guarantee clean child PRs after a squash. The helper's exact same-tree graph simulations verify that matching parent trees can be restacked without manual conflict resolution; divergence is refused.
python3 scripts/restack-after-squash.py --check 1331 1332 1333.python3 scripts/restack-after-squash.py --push --retarget 1331 1332 1333. Add--skip-hookonly with explicit human authorization. Recheck child diffs, remote checks, and approvals; branch updates can dismiss approvals.python3 scripts/restack-after-squash.py --check 1332 1333and, when authorized,python3 scripts/restack-after-squash.py --push --retarget 1332 1333, with the same hook and review requirements.Retarget each child to
masteronly after its parent is merged. These are future landing steps, not operations performed by this description update.