seppevs / migrate-mongo

A database migration tool for MongoDB in Node
MIT License
902 stars 160 forks source link

Multi dotted migration file extension #421

Open DocAmaroo opened 1 year ago

DocAmaroo commented 1 year ago

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.