-
-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
beforeMigration option #167
beforeMigration option #167
Conversation
ebc488f
to
20ab166
Compare
readme.md
Outdated
console.log = someLogger.log; | ||
|
||
const mainConfig = new Conf({ | ||
beforeMigration: (store, currentVersion, nextVersion) => { |
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.
I would prefer if it were like this.
beforeMigration: (store, currentVersion, nextVersion) => { | |
beforeMigration: (store, context) => { |
That way we could easily add more metadata properties in the future.
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.
Should the properties maybe be named fromVersion
and toVersion
? currentVersion
makes it sound like it's the current version of the package, not the current version in the migration process.
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.
We could maybe also add the package version and all the migration versions. In case the user wants to know where in the migration process they are.
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.
We could maybe also add the package version and all the migration versions. In case the user wants to know where in the migration process they are.
Added context.migrationProcess
with finalVersion
and migrations
not sure how to name them properly probably they can be flattened and lay in context
but proper naming required
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.
I would prefer to keep them top-level in context
(no nesting).
readme.md
Outdated
|
||
You can use `beforeMigration` callback for logging purposes, preparing migration data, etc. | ||
|
||
`beforeMigration` callback will be called before the migration is executed. |
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 ambiguous. Before the whole process or before each step.
test/index.ts
Outdated
cwd: tempy.directory(), | ||
projectVersion: '2.0.0', | ||
beforeMigration: (store, currentVersion, nextVersion) => { | ||
store.set(`beforeMigration ${currentVersion} -> ${nextVersion}`, true); |
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.
store.set(`beforeMigration ${currentVersion} -> ${nextVersion}`, true); | |
store.set(`beforeMigration ${currentVersion} → ${nextVersion}`, true); |
I think it should be called |
source/types.ts
Outdated
|
||
*/ |
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.
*/ | |
*/ |
test/index.test-d.ts
Outdated
@@ -135,6 +135,11 @@ expectError<number>(config.get('unicorn', 1)); | |||
|
|||
// -- Migrations -- | |||
new Conf({ | |||
beforeEachMigration: (store, context) => { | |||
console.log(`[main-config] migrate from ${context.fromVersion} → ${context.toVersion}`); | |||
console.log(`[main-config] final migration verison ${context.migrationProcess.finalVersion}, all migrations that were run or will be runned: ${context.migrationProcess.versions.toString()}`); |
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.
console.log(`[main-config] final migration verison ${context.migrationProcess.finalVersion}, all migrations that were run or will be runned: ${context.migrationProcess.versions.toString()}`); | |
console.log(`[main-config] final migration version ${context.migrationProcess.finalVersion}, all migrations that were run or will be ran: ${context.migrationProcess.versions.toString()}`); |
test/index.ts
Outdated
} | ||
}); | ||
|
||
t.is(conf.get('beforeEachMigration 0.0.0 → 1.0.0'), true); |
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.
Use t.true
5375e6d
to
90da4f5
Compare
You can use
beforeMigration
callback for logging purposes, preparing migration data, etc.beforeMigration
callback will be called before the migration is executed.It could be useful when u have multiple configs and you want to log the migration data for each config.
My example - I use multiple
electron-store
's and its usefull to log all migrations viaelectron-log
in single file for debugging purposes, its easier to understand what can cause issue. Probably its can be usefull for others