cli icon indicating copy to clipboard operation
cli copied to clipboard

include non-migration files in the migrations folder

Open sergiycheck opened this issue 2 years ago • 3 comments

Issue Creation Checklist

  • [x ] I understand that my issue will be automatically closed if I don't fill in the requested information
  • [x] I have read the contribution guidelines

Feature Description

I get such error: ERROR: Could not find migration method: up. I have three migration files all with up and down methods. I have .sequelizerc and config.js files. I am running my migration with this command

npx sequelize-cli db:migrate --env development 

The migrations are displayed in postgres and tables are created, but error is thrown at the end.

I've debugged migration script and found out that every file in migration folder must be actual migration and not something else, but I had there a shared file with table names that migration tool thought to be migration. By removing that file bug resolved.

Maybe I we could somehow include non-migration files in migration folder or highlight that info in docs if not already present that every file file in migration folder is must be migration and not something else.

Describe the feature you'd like to see implemented

Describe why you would like this feature to be added to Sequelize

More programmatic access to migrations with .sequelizerc

Is this feature dialect-specific?

  • [ x] No. This feature is relevant to Sequelize as a whole.

Would you be willing to resolve this issue by submitting a Pull Request?

  • [ ] Yes, I have the time and I know how to start.
  • [ ] Yes, I have the time but I will need guidance.
  • [ ] No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • [x ] No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.

Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.

sergiycheck avatar Jun 15 '22 13:06 sergiycheck

Hi! I tried to reproduce this with a random non-migration file in #1114 but the tests that we use pass on that. Could you elaborate more on the error message or provide us with a failing PR?

WikiRik avatar Jun 15 '22 14:06 WikiRik

I would expect it to throw, just in case the up and down methods were not exported

I think we should look into adding an extensions glob option, and only treat files that match the glob as migrations. It would give the ability to skip files by setting it to something like *.migration.js.

(it would also solve the issue we have with .ts file extensions)

ephys avatar Jun 15 '22 15:06 ephys

Hi! I tried to reproduce this with a random non-migration file in #1114 but the tests that we use pass on that. Could you elaborate more on the error message or provide us with a failing PR?

Try to export that sum function. Migrator uses exported functions. My file that failed migrations was exported like other migrations. I used it to provided names for the tables. I couldn't generate my migraiton because I use nestjs and typescript. And I didn't find a way to generate it from cli. Maybe there any ways to do it that I didn't find. I attach the content of the file that make to throw error.

const TableNames = {
  Users: 'Users',
  PublicFiles: 'PublicFiles',
};

module.exports = {
  TableNames,
};

sergiycheck avatar Jun 15 '22 16:06 sergiycheck

Closing this in favour of #756

WikiRik avatar Apr 02 '24 06:04 WikiRik