db-migrate/node-db-migrate

Problem with migration down using plugin

maherma-adg opened this issue · 1 comments

I'm submitting a...

  • Bug report
  • Feature request
  • Question

Current behavior

I developed a plugin db-migrate-plugin-es6cjs to enable use of db-migrate on ESM projects looking for '.cjs' files instead of '.js', basically I clone the typescript & coffee plugin versions.
All work like a charm when migrate up, files are detected and executed without problems.
Error happens on migrate down, I got a "[ERROR] Error: Cannot find module /........./migrationName". Tracing error show a try to import migration script with require function from a synthetic path without extension, as require function use ".js" by default, it can't find the module.

Expected behavior

Migration down must find the file the same way as migration up does.

Minimal reproduction of the problem with instructions

  • Create a project with type=module
  • Install db-migrate
  • Install db-migrate-plugin-es6cjs
  • Create a migration file
  • Rename migration file from .js to .cjs
  • Execute db-migrate up
  • Execute db-migrate down

What is the motivation / use case for changing the behavior?

Enable the full potential of plugin mechanism.

I see two possible solutions:

  • Use the same mechanisms working on "migration up" to locate migration file and use the full path including extension
  • Delegate to plugin the mapping from migration name to script full path ( or return a already loaded module to allow transcoding o alternative storage)

Environment


db-migrate version: 0.11.13 & 1.0.0-beta.8
plugins with versions: db-migrate-plugin-es6cjs@0.0.1
db-migrate driver with versions: db-migrate-pg@1.2.2

Additional information:
- Node version: v16.15.1
- Platform:  Mac

Others:

please use the search before opening a ticket: #784