-
Notifications
You must be signed in to change notification settings - Fork 86
Conversation
Upgrading to new versions of code often requires changes to an existing database. Currently, we've made the code to automate migration in the `boot/database.js` file. The size of this file is growing and will become unmaintainable as we add migration code for future versions. This commit expresses a proposed way of formalizing migrations. With this strategy, we'll be able to add a new module that handles migration for each new version. In addition, separating the migration code in this way makes it testable in isolation.
This code is not ready to merge. It's here in draft form for review and discussion. |
|
||
module.exports = function (version) { | ||
return function migration_0_0_0 (next) { | ||
if (semver.satisfies(version, '<=0.0.0')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is different behaviour than what we currently have. With this check, inserting roles, scopes, and assigning permissions only happens if there is no existing data. Currently, this is all run regardless of the version of the data in the database, to alleviate concerns of users moving up from earlier versions where this logic was run solely by nv migrate
.
It looks like this should either
- Always run, which also helps in the case an admin accidentally deletes any of these entries from the database, or
- Be a migration defined for the latest version of Connect that did not yet run these scripts automatically at boot-time.
I'm vouching for 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Secondly, if this is to always run, I'm not sure it belongs in a migration script. This is less of a migration script and more of a case where we're ensuring something is in the database. A related migration would be converting the data if the existing data in the database is old and in a different format.
boot/database.js
may still have some use for those kinds of scenarios. It would run after (or before?) the migration scripts are finished.
So we have the migrations:
This is inconsistent and confusing. The migration version numbers should match up. Either the names become consistent with the semver checks, or the semver checks become consistent with the names. i.e., either 0.1.55 and 0.1.56 get named 0.1.54 and 0.1.55, or the semver checks for them become |
I'm not completely sold on |
I've renamed @vsimonian Please review and merge (assuming everything works correctly). Thanks. |
context:
|
Upgrading to new versions of code often requires changes to an existing database. Currently, we've made the code to automate migration in the
boot/database.js
file. The size of this file is growing and will become unmaintainable as we add migration code for future versions. This commit expresses a proposed way of formalizing migrations. With this strategy, we'll be able to add a new module that handles migration for each new version. In addition, separating the migration code in this way makes it testable in isolation.