Skip to content

db: restore and extend gateway usage migrations - #5135

Draft
OmarMcAdam wants to merge 1 commit into
devfrom
gateway-usage-migrations
Draft

OmarMcAdam wants to merge 1 commit into
devfrom
gateway-usage-migrations

Conversation

@OmarMcAdam

Copy link
Copy Markdown
Collaborator

Scope — database migrations only

Split from #5133 so the database changes can land before the incremental Gateway usage implementation.

This PR changes only ee/packages/den-db:

  • Migration SQL, Drizzle snapshots, and journal entries 0102–0107.
  • Matching declarative schema and its export, required to keep current-schema.sql and fresh database bootstraps consistent with the migration journal.
  • The small migration-validation normalization change needed to recognize MySQL's serialization of these CHECK constraints.

No API routes, UI, Gateway enforcement, accounting workers, request-path locking, connection-pool changes, or feature activation. All migration assets are identical to their versions in #5133 at aa8223dbb.

Migration history

  • 0102–0104 restore the exact original migration SQL/snapshots removed from Git by Revert "feat(gateway): add per-member usage limit policies (#5056)" #5124. Their SQL bytes and receipt identities are unchanged from 9b0adb849.
  • 0105 adds incremental accounting counters and lookup indexes.
  • 0106 adds tracking/lifecycle state and incomplete-history counters.
  • 0107 adds durable request attribution, pending-count ownership, capture versions, and the pending-event lookup index. Existing tracking rows default to capture-disabled; enabling new capture belongs to the later implementation rollout.

A database with valid receipts through 0104 should apply only 0105–0107. Tables without matching receipts or partially applied DDL require explicit investigation—do not re-baseline or rewrite old receipts.

Merge order and operational effect

  1. Review and merge this PR first.
  2. Confirm the repository's Den DB Migrate workflow completes successfully. Merging migration files to dev triggers that workflow; this task did not invoke it or access production.
  3. Rebase fix(gateway): restore spend limits with incremental member accounting #5133 onto updated origin/dev, removing these database changes from its remaining diff.
  4. Review/deploy the application and perform its documented capture cutover separately.

Auto-merge on #5133 has been paused to preserve this order. This PR is not configured to auto-merge.

Validation

Validated on isolated, pinned MySQL 8.4.10, never production:

  • Real fresh replay through 0001–0107 passed.
  • Populated 0104 → 0107 upgrade preserved 24 rows across 10 tables, all 104 existing migration receipts, and appended exactly three receipts.
  • Re-running migrations preserved receipts, schema, and data unchanged.
  • Source schema, final Drizzle snapshot, and built bootstrap SQL matched across 122 tables.
  • @openwork/types build, @openwork-ee/den-db build, database TypeScript check, and db:generate passed; generation reported no changes.
  • Schema-parity tests: 13 passed.
  • Readiness tests: 34 passed, 1 failed. The sole failure is the CI-path assertion at migration-readiness.test.ts:572, expecting a path filter removed by chore(ci): keep non-PR automation and remove review triggers #5126. The identical selected test failed on a clean detached d80494a19 control with the same Node/tsx versions and frozen dependencies. No workflow or application changes were added to work around it.

The large diff is almost entirely generated schema snapshots. No live records, credentials, or diagnostic logs are included.

@OmarMcAdam
OmarMcAdam requested a review from a team September 18, 2026 00:31
@vercel

vercel Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated
openwork-app Skipped Skipped Sep 18, 2026 12:32am UTC
openwork-den Skipped Skipped Sep 18, 2026 12:32am UTC
openwork-diagnostics Skipped Skipped Sep 18, 2026 12:32am UTC
openwork-landing Skipped Skipped v0 Sep 18, 2026 12:32am UTC

This branch was previously deployed

4 inactive deployments
Preview – openwork-landing — a5f77630 Deployed Sep 18, 2026 by vercel[bot]
Preview – openwork-den — a5f77630 Deployed Sep 18, 2026 by vercel[bot]
Preview – openwork-app — a5f77630 Deployed Sep 18, 2026 by vercel[bot]
Preview – openwork-diagnostics — a5f77630 Deployed Sep 18, 2026 by vercel[bot]
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.

1 participant