Operations

Migrations

How MemexAI manages its Postgres schema.

MemexAI manages its schema with a lightweight migration runner. Calling migrate() creates and updates the tables it owns.

How it works

const memex = createMemex(process.env.DATABASE_URL!)
await memex.migrate()

migrate() is idempotent:

  1. It creates mx_migration if it does not exist.
  2. It checks each known migration ID.
  3. It runs unapplied SQL in a transaction.
  4. It inserts the applied migration ID.
  5. It skips already applied migrations.

Current tables

TablePurpose
mx_migrationTracks applied migrations
mx_fileStores current memory file content
mx_revisionStores write snapshots
mx_access_logStores lightweight read/write activity
mx_dream_runStores per-user background consolidation state
mx_configStores runtime config, including dream_* settings

When to call migrate

  • Recommended service mode: the service runs migrations on startup.
  • Advanced direct Postgres mode: call migrate() once during startup or deploy.

It is safe to call on every startup. Once migrations are applied, the checks are fast.

On this page