Skip to content

Add soft-delete columns and erase-path indexes - #1331

Merged
Gajesh2007 merged 34 commits into
masterfrom
feat/store-soft-delete-schema
Oct 6, 2026
Merged

Gajesh2007 merged 34 commits into
masterfrom
feat/store-soft-delete-schema

Conversation

@davidtai

@davidtai davidtai commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

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 risk
Loading

After

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 checked
Loading

Blue shows callers and domain ownership, purple the schema, and green the enforced behavior.

Schema and compatibility

Versions Change
10–16 Concurrent account or consumer-hash indexes on provider sessions, logs, device codes, machine sessions, token reservations, routes, and rejections.
17 Nullable deleted_at on users, api_keys, providers, and provider_tokens, without defaults.
18 Concurrent partial unique Privy-ID index for live users.
19–20 Remove the superseded global unique constraint and index.
21 Validate the referral-code foreign key with ON UPDATE CASCADE before 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

  • Memory usage-flow location overrides check the provider tombstone first, preventing an override from restoring a deleted provider's location.
  • Soft-delete filters cover authentication, user lookup, provider tokens, restoration, continuity, inventory backfill, promotion eligibility, and provider locations in usage-flow reads. SQLC bindings and the current schema snapshot are regenerated.
  • Contact exports filter deleted users before pagination. Initial legacy MDM qualification excludes deleted users and providers; subsequent reads preserve the frozen snapshot. Regressions reproduce both missed filters on memory and PostgreSQL before the fix, then verify live controls, pagination, both evidence paths, and snapshot preservation.
  • Domain records carry internal DeletedAt fields. Existing mutation behavior is preserved until the writer layer introduces account-state guards.
  • Migration tests preserve the merged baseline failure checks and legacy/Goose upgrade cases. The refund-index recovery fixture now rewinds version 9 and its descendants before replay, so it remains valid when this layer adds later versions.
  • Documentation-impact checks cover the specific soft-delete owners, including the newer contact and MDM domains, and the concurrent-index migration owner. Regression tests verify the required canonical documentation without broadening unrelated store matches.

Squash-safe stack tooling

AGENTS.md (Stacked PRs) and docs/developer/pull-requests.md document the reusable scripts/restack-after-squash.py workflow. Seven local Git fixture tests cover the tooling. It verifies the original parent/squash tree and ancestry, creates signed same-tree git commit-tree commits, and supports an atomic non-force push with optional retargeting. Divergent trees are refused rather than manually resolved or silently overwritten.

Before: stack tooling

flowchart LR
  A["Parent PR squash-merged"] --> B["Original ancestry no longer matches master"]
  B --> C["Manual child merges and conflict resolution"]
  C --> D["Risk of changed child content"]
  classDef process fill:#dbeafe,stroke:#2563eb,color:#172554
  classDef risk fill:#fee2e2,stroke:#dc2626,color:#450a0a
  class A process
  class B,C,D risk
Loading

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 risk
Loading

Blue identifies workflow entry points, amber verification, green content-preserving updates, and red refused or risky paths.

Validation

Final pushed heads: #1331 cd29e84d4, #1332 69cb0eb87, #1333 eef27a3d9. GitHub signatures are verified; all three PRs are currently MERGEABLE against 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, with CGO_ENABLED=0 and DATABASE_URL pointing 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-check and make docs-impact-check against 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 master at 470a86d47, independently verified. Release Integrity's test-integration-ci-workflow.py also 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 subprocess import 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-check and make docs-impact-check against 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. master is 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.

  1. Squash-merge Add soft-delete columns and erase-path indexes #1331, then run python3 scripts/restack-after-squash.py --check 1331 1332 1333.
  2. When authorized, run python3 scripts/restack-after-squash.py --push --retarget 1331 1332 1333. Add --skip-hook only with explicit human authorization. Recheck child diffs, remote checks, and approvals; branch updates can dismiss approvals.
  3. Squash-merge Add GDPR account erasure: plan, soft delete, grace, scrub #1332, then run python3 scripts/restack-after-squash.py --check 1332 1333 and, when authorized, python3 scripts/restack-after-squash.py --push --retarget 1332 1333, with the same hook and review requirements.
  4. After checks and required approvals, squash-merge Deliver the account erasure outbox to Stripe and Datadog #1333.

Retarget each child to master only after its parent is merged. These are future landing steps, not operations performed by this description update.

davidtai and others added 4 commits October 3, 2026 07:59
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>
@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference.

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>
@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Deployment failed for project eigen-homepages-darkbloom with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: eigen-homepages-darkbloom.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-console-ui-dev with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-console-ui-dev.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 3, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-landing with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-landing.

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>
@davidtai
davidtai force-pushed the feat/store-soft-delete-schema branch from 5c09f50 to 1475925 Compare October 3, 2026 13:34
davidtai and others added 2 commits October 3, 2026 08:51
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>
davidtai and others added 4 commits October 3, 2026 09:29
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
davidtai and others added 5 commits October 4, 2026 13:12
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>
0xkydo
0xkydo previously approved these changes Oct 6, 2026
@Gajesh2007
Gajesh2007 changed the base branch from feat/store-sqlc-api-keys to master October 6, 2026 19:23
@Gajesh2007
Gajesh2007 dismissed 0xkydo’s stale review October 6, 2026 19:23

The base branch was changed.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Threat model review — advisory

Reviewed head cd29e84d433d against base 470a86d47f44.

Review not completed for this head. Previous findings are superseded, not confirmed resolved.
Ten-PR pilot complete; maintainer evaluation required

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.

@Gajesh2007
Gajesh2007 merged commit 829730b into master Oct 6, 2026
35 of 40 checks passed
@Gajesh2007
Gajesh2007 deleted the feat/store-soft-delete-schema branch October 6, 2026 21:45
@blacksmith-sh

blacksmith-sh Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Found 1 test failure on Blacksmith runners:

Failure

Test View Logs
test_all_integration_gates_and_flags_remain (main.IntegrationWorkflowTests.test_all
_integration_gates_and_flags_remain)/
test_all_integration_gates_and_flags_remain (main.IntegrationWorkflowTests.test_all
_integration_gates_and_flags_remain)
View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

This branch was successfully deployed

4 active deployments
Preview – d-inference — cd29e84d Deployed Oct 6, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — cd29e84d Deployed Oct 6, 2026 by vercel[bot]
Preview – d-inference-landing — cd29e84d Deployed Oct 6, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — cd29e84d Deployed Oct 6, 2026 by vercel[bot]
benchmarks — cd29e84d Deployed Oct 6, 2026 by Gajesh2007 via E2E Benchmarks #2347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants