OperationsUpgrade

Upgrade

No image is published, so an upgrade is a new build of the repository.

In place

Take a backup first. Then, from the repository:

git pull
cd docker
docker compose build
docker compose up -d

docker compose up -d runs the migrate service first; the server starts only after it exits 0. To run the migrations by hand:

docker compose run --rm migrate

With the production overlay, pass both files:

docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build

Upgrade the server before the web dashboard: the dashboard calls routes that older servers lack.

How migrations run

There are two migration streams, and the migrate service applies both:

  • packages/adapter-postgres/migrations/baseline/: the current stream, 70 migrations.
  • packages/core/migrations/: the older v2 stream.

The runner records each applied file and its checksum in mnemosyne.schema_migrations, holds a session advisory lock while it works, and runs each file in its own transaction unless the file is marked -- migrate:no-transaction. Because of the advisory lock, MNEMO_MIGRATION_DATABASE_URL must point straight at Postgres or at a session-mode pool, never at a transaction pooler.

Rolling back

Migrations only move forward. Some carry a .down.sql file next to them, but the runner never applies those. To go back, check out the previous commit, rebuild, and if a schema change must be reversed, apply the matching .down.sql by hand with psql. Restoring the backup is the safer path.

When a migration fails

migrate exits non-zero and Compose does not start the new server. Read the error, then fix the cause and run it again:

docker compose ps
docker compose logs migrate

What is tested before a release

There is no CI today: GitHub Actions is off for the repository. There is no version-skew test matrix either, so do not assume that two server versions can run side by side during a rolling deploy.

Releases pass a local gate, which needs Docker:

FULL=1 bash scripts/full-sweep.sh

Run pnpm test and pnpm test:integration yourself if you build from a commit that is not a release.

Migrating v2 data to v3 (CUP)

The Cognitive Upgrade Protocol (@mnemo-ai/cup) is a one-time migration of legacy v2 data into the v3 schema. It is beta, and it is an internal package: it is not on npm, so run it from a built checkout (pnpm install && pnpm build).

It reads batches from the v2 public.memories table, maps each row to a v3 primitive with a rule-based mapper, and writes to the v3 database. The source database is only read. Progress is kept as a keyset cursor in the v3 database, so a run can be resumed.

export DATABASE_URL=postgres://user:pass@host:5432/mnemosyne_v2     # source, v2
export DATABASE_URL_V3=postgres://user:pass@host:5432/mnemosyne     # target, v3
 
node packages/cup/dist/migrate.js --workspace <uuid> --dry-run       # print, do not write
node packages/cup/dist/migrate.js --workspace <uuid>                 # migrate
node packages/cup/dist/migrate.js --workspace <uuid> --batch-size 50 # default 100
node packages/cup/dist/migrate.js --workspace <uuid> --run-id <id>   # resume a run
node packages/cup/dist/migrate.js --workspace <uuid> --llm           # reclassify with the model

--llm needs MNEMO_LLM_API_KEY.