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:
- It creates
mx_migrationif it does not exist. - It checks each known migration ID.
- It runs unapplied SQL in a transaction.
- It inserts the applied migration ID.
- It skips already applied migrations.
Current tables
| Table | Purpose |
|---|---|
mx_migration | Tracks applied migrations |
mx_file | Stores current memory file content |
mx_revision | Stores write snapshots |
mx_access_log | Stores lightweight read/write activity |
mx_dream_run | Stores per-user background consolidation state |
mx_config | Stores 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.