0

A project in question contains migration files with following names:

1-addCityToCompany.js
2-addPhonesToCompanies.js
3-addEmailsToCompanies.js
4-addSocialUrlsToCompanies.js
5-addWebstiesToCompanies.js
…
79…

Starting from migration 79, we have created a big fork and development was in separate branch.

It's time to merge and deploy ;)

Now we have 239 migrations and want to apply them all to production database.

The problem is that Sequelize reads migration files, sorted by alphabetical order and it tries to execute migration 100, skipping migration from 80 to 99.

This is a sequence of reading, I suppose Sequelize using ls for that:

$ ls -1 migrations/
1-addCityToCompany.js
10-addConfirmedAtToUsers.js
100-createPgcryptoExtension.js
101-createRegisterUserFunction.js
102-setupPostgraphileRoles.js
103-createJwtTokenType.js
104-createAuthenticateFunction.js
105-createCurrentUserFunction.js
106-grantPrivileges.js
107-addAvatarFileIdToUsers.js
108-copy_attachments_to_users_avatarFileId_column_where_attachment_name_is_avatar.js
109-createArticleAttachmentTable.js
11-addHeadCompanyIdToCompanies.js
110-copy_attachment_to_articleAttachment.js
111-drop_attachments_table.js
112-grant_privilegies_for_articleAttachments_table.js
113-create_current_user_id_function.js
114-create_createArticle_function.js
115-set_default_values_for_article_timestamps.js
116-add_primary_key_to_articleAttachments.js
117-create_updateArticle_function.js
118-grant_privilegies_on_DELETE_for_articleAttachment_table.js
119-add_country_id_to_jwtToken_type.js
12-addDepartmentsToCompanies.js
120-create_currentCountry_function.js
121-rename_table_articlesComments_to_articleComments.js
122-set_default_values_for_articleComment_timestamps.js
123-create_createArticleComment_function.js
124-enable_rls_for_articleComment_table.js
125-create_policies_for_articleComment.js
126-create_updateArticleComment_function.js
127-create_country_latest_companies_function.js
128-rename_companiesComments_table.js
129-create_country_latest_company_comments_function.js
13-addDepartmentToCompanyCategory.js
130-rename_companiesInfoRequests_table.js
131-create_country_latest_company_info_request_function.js
132-create_country_regions_with_companies_function.js
133-create_region_cities_with_companies_function.js
134-create_country_cities_function.js
135-create_type_department_as_enum.js
136-change_companies_departments_column_type_from_string_to_enum.js
137-change_companyCategories_department_column_type_from_string_to_enum.js
138-create_type_stock_temperature_as_enum.js
139-change_companies_stockTemperatures_column_type_from_string_to_enum.js
14-addDepartmentToPrimaryKeyOfCompanyCategories.js
…

How to control input order of files with Sequelize?

AntonAL
  • 16,692
  • 21
  • 80
  • 114
  • I know, I can rename migration files with padding zeros, like 080, 081… But maybe Is it possible to overcome this monkey job… – AntonAL Feb 26 '19 at 10:57
  • I also cannot execute `sequelize db:migrate --to 80-…`, because cli starts reading file list from the beginning and tries to execute migration 100. – AntonAL Feb 26 '19 at 11:08
  • I don't see any way to customize the order of the files in the sequelize-cli docs. I believe mass renaming may be the best option. There are programmatic ways to pad zeros in your file names. – NeonD Feb 26 '19 at 20:17
  • Suddenly, yes, already done it https://stackoverflow.com/questions/55754/how-to-zero-pad-numbers-in-file-names-in-bash/54888706#54888706 – AntonAL Feb 27 '19 at 10:47

0 Answers0