Skip to content

feat(migrations)!: align runMemoryMigrations with runMigrations - #54

Merged
TheGreatAxios merged 1 commit into
cl-9061-memory-remove-duplicate-creatememory-declarationfrom
cl-9138-memory-align-runmemorymigrations-to-runmigrationsconfig
Sep 27, 2026
Merged

TheGreatAxios merged 1 commit into
cl-9061-memory-remove-duplicate-creatememory-declarationfrom
cl-9138-memory-align-runmemorymigrations-to-runmigrationsconfig

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #53; merge that first.

  • runMemoryMigrations(config, { schema, ftsLanguage }) takes the same DBConfig and schema as Interchange runMigrations. schema is the host schema holding the tenant and principal tables; the "public". foreign-key references are rewritten to it. Memory's own tables stay in the memory schema.
  • There is no ledger: every file is idempotent and replayed on each run, and a new migration drops memory._migrations. Foreign keys and CHECK constraints are added only when missing. A foreign key that points at a different host schema fails the replay. The temporal_class backfill runs only in the replay that adds the column.
  • The whole replay runs in one transaction behind pg_advisory_xact_lock, the same approach as @corbits/artifacts, so replicas that boot together run it one at a time instead of racing CREATE ... IF NOT EXISTS or deadlocking. There is no lock_timeout, matching artifacts: a replay waits behind a long reader instead of failing boot, and a failed replay rolls back whole and releases the lock.
  • ftsLanguage is required, with no default. The runner no longer reads FTS_LANGUAGE from the environment.
  • config is checked by type only: @intx/db 0.4.0 exports DBConfig as a type, not a validator. @intx/db is a required peer because DBConfig is part of the signature.
  • CONTRIBUTING states the migration rule: never change a shipped file's effect; widening goes in a new file.
  • The README migration snippet is one call.

Verification

  • bun run typecheck and bun test ./src pass (457 tests).
  • Migrations run twice on fresh databases on a local pgvector Postgres 16 with host schemas public, hub and a quoted name. The foreign keys target <schema>.tenant/principal. A database migrated by the 0.1.0 runner upgrades cleanly and loses its ledger.
  • The end-to-end suite in test: add a real-Postgres e2e suite with add and search tests #56 tests the idempotent replay, the host schema, waiting behind a long reader, and three concurrent runners.

Closes CL-9138
Closes CL-9143
Closes CL-9180

@TheGreatAxios TheGreatAxios left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review, four passes over the stacked range.

Verdict: ready for review.

  • Replays are idempotent on real Postgres, including a database migrated by the old runner.
  • The host-schema rewrite matches Interchange's regex, and a foreign key into a different host schema fails the replay.
  • Waivers and the type-only DBConfig note are in the description.

@TheGreatAxios
TheGreatAxios force-pushed the cl-9138-memory-align-runmemorymigrations-to-runmigrationsconfig branch from f46acf8 to c005288 Compare September 25, 2026 07:02
@TheGreatAxios
TheGreatAxios force-pushed the cl-9138-memory-align-runmemorymigrations-to-runmigrationsconfig branch from c005288 to 31a6be6 Compare September 25, 2026 18:31
@TheGreatAxios
TheGreatAxios force-pushed the cl-9138-memory-align-runmemorymigrations-to-runmigrationsconfig branch from 31a6be6 to 3cb8b97 Compare September 26, 2026 01:32
@TheGreatAxios TheGreatAxios changed the title Align runMemoryMigrations with Interchange runMigrations feat(migrations)!: align runMemoryMigrations with runMigrations Sep 26, 2026
@TheGreatAxios
TheGreatAxios force-pushed the cl-9138-memory-align-runmemorymigrations-to-runmigrationsconfig branch from 3cb8b97 to 63abc3d Compare September 26, 2026 01:36
@TheGreatAxios
TheGreatAxios added this pull request to stack #61 September 26, 2026 01:57
runMemoryMigrations(config, { schema, ftsLanguage }) takes the same
DBConfig and schema as Interchange runMigrations. schema names the host
schema holding the tenant and principal tables, and the foreign-key
references in the SQL are rewritten to it; memory's own tables stay in
the memory schema. The runner replays every migration file on each run
instead of keeping a memory._migrations ledger, which a new migration
drops. Foreign keys and CHECK constraints are added only when missing,
so a replay does not re-validate tables, a lock timeout keeps a replay
from stalling readers, and the one-time temporal_class backfill runs
only in the replay that adds the column. ftsLanguage is required, with
no default, and the runner no longer reads FTS_LANGUAGE from the
environment.
@TheGreatAxios
TheGreatAxios force-pushed the cl-9138-memory-align-runmemorymigrations-to-runmigrationsconfig branch from 63abc3d to a867f83 Compare September 27, 2026 00:32
@TheGreatAxios
TheGreatAxios merged commit 94736ea into main Sep 27, 2026
2 checks passed
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