DASPRiD/mikro-orm-6-6-8-migrator-issue

★ 0Forks 0JavaScriptGitHub ↗Compare

README

mikro-orm-6-6-8-migrator-issue

Reproduction case for a MikroORM 6.6.8 migrator snapshot issue.

The Bug

In MikroORM 6.6.8, the migrator was changed to always write a snapshot file after running migrations (snapshot: true is the default). This causes failures in read-only environments such as production Docker images, because the snapshot file cannot be written to the migrations directory.

Error observed:

EACCES: permission denied, open '/app/migrations/.snapshot-db.json'

Reproduction

npm install
node src/reproduce.js

Expected output demonstrating the bug:

Migrations directory is now read-only: .../src/migrations
Running with snapshot: true (default, demonstrates bug)
---
[migrator] Processing 'Migration20240101000000'
[migrator] Applied 'Migration20240101000000'
❌ Migration failed with error:
EACCES: permission denied, open '.../src/migrations/.snapshot-db.sqlite3.json'

The Fix

Set snapshot: false in your MikroORM migrations config when running in production (or any environment where the migrations directory is read-only):

migrations: {
    snapshot: process.env.NODE_ENV !== 'production',
}

To see the fix in action:

node src/reproduce.js --fixed

Expected output:

Migrations directory is now read-only: .../src/migrations
Running with snapshot: false (fix applied)
---
[migrator] Processing 'Migration20240101000000'
[migrator] Applied 'Migration20240101000000'
✅ Migrations ran successfully.

Contributors

DASPRiDCopilot

Issues