#Error: "The migration directory is corrupt" - Missing Migration File

15 messages · Page 1 of 1 (latest)

lunar marsh
#

Hello everyone,

I'm encountering an issue with Backstage where it throws the following error:

Unhandled rejection The migration directory is corrupt, the following files are missing: 20240712211735_nullable_next_run.js

The full error stack is:

Unhandled rejection The migration directory is corrupt, the following files are missing: 20240712211735_nullable_next_run.js
    at validateMigrationList (node_modules/knex/lib/migrations/migrate/Migrator.js:567:11)
    at Migrator.latest (node_modules/knex/lib/migrations/migrate/Migrator.js:69:7)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at migrateBackendTasks (node_modules/@backstage/backend-defaults/src/entrypoints/scheduler/database/migrateBackendTasks.ts:27:9)
    at PluginTaskSchedulerImpl.<anonymous> (node_modules/@backstage/backend-defaults/src/entrypoints/scheduler/lib/DefaultSchedulerService.ts:42:9)
It appears that Backstage is unable to find a specific migration file, which results in this error. I would appreciate any advice on how to resolve this issue or pointers on what might be causing it.

I wanted to know why these errors usually occur and how to fix them without having to access the database.

Thanks in advance for your help!

iron geode
#

this means

  • you upgraded a plugin
  • that plugin ran and had new migrations that weren't in the previous version
  • the migration was applied, which permanently modifies your database
  • you tried to start an older version of the plugin (maybe you went back in time) and on startup, it detects that the database is in a state that it cannot possibly know what to do with, and dies
#

You do need access to the database to fix it, if you really want to downgrade. Best is of course to not downgrade, but instead try to move forward and use only the new version that is compatible with your post-migration database state

lunar marsh
#

mmmm, I think that in most of the cases it has been because pulling the thread of some problem going back to previous versions I have dragged some migration.

lunar marsh
iron geode
#

personally i like low level fiddling and tend to apply downgrades by hand e.g. by looking at the migration file (here in this case https://github.com/backstage/backstage/blob/5b317bce172eaaa5288734643302083a02466a42/packages/backend-defaults/migrations/scheduler/20240712211735_nullable_next_run.js#L34) and then deleting the row in the migrations table (backstage_backend_tasks__knex_migrations in this case)

GitHub

Backstage is an open framework for building developer portals - backstage/backstage

lunar marsh
#

ty so much i will try

lunar marsh
lunar marsh
#

i.e. for example i have these bdd, one for each plugin i have, but related to the migrations are tables inside these “logical database i understand”, how can i delete related to the migrations?

lunar marsh
#

ok ready, I managed to fix it with a script thank you very much!

#

🚀

lunar marsh
#

the only question I have left is in a productive environment would it make sense/be logical or possible to do this?