migrate-mongo icon indicating copy to clipboard operation
migrate-mongo copied to clipboard

Multi dotted migration file extension

Open DocAmaroo opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe.

I tried to use a multi dotted extension filename in my config, such as:

migrationFileExtension: '.migration.ts',

But the app couldn't retrieve them when using

migrate-mongo status

why ?

It appears this is due to the filter condition returned in migrationDir.getFilenames().

The condition: path.extname(file) === migrationExt will resolve by '.ts' === '.migration.ts' and return false.

Describe the solution you'd like

Maybe this has not been implemented for some purposes, but it would be great if we want to keep consistency in our project filenames or event custom them. Otherwise, I have to manually rename each of my migration file myself.

Describe alternatives you've considered

The simple way, I guess, will be to use a cute reg expression to test if the filename match the migrationExt.

async getFilenames() {
  ...
  const matchExt = (filename) => new RegExp(`.*${migrationExt}$`).test(filename);
  return files.filter(file => matchExt(file) && path.basename(file) !== sampleMigrationFileName).sort();
}

or in one line (which is uglier)

async getFilenames() {
  ...
  return files.filter(file => new RegExp(`.*${migrationExt}$`).test(filename) && path.basename(file) !== sampleMigrationFileName).sort();
}

Additional context Add any other context or screenshots about the feature request here.

DocAmaroo avatar Dec 15 '22 10:12 DocAmaroo