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
Apply postprocessing in migrations #2934
Changes from all commits
895274a
fd7a07a
2216646
565c537
d54ca63
05d306b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,30 @@ function initContext(knexFn) { | |
return this.client.ref(ref); | ||
}, | ||
|
||
// Do not document this as public API until naming and API is improved for general consumption | ||
// This method exists to disable processing of internal queries in migrations | ||
disableProcessing() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to add some comment that these should not be added documentation to be a part to knex public API before we have designed better API names and parameters for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And also to mention why these exist (that it was needed for migrations to be able to run those internal queries, with consistent identifier naming). |
||
if (this.userParams.isProcessingDisabled) { | ||
return; | ||
} | ||
this.userParams.wrapIdentifier = this.client.config.wrapIdentifier; | ||
this.userParams.postProcessResponse = this.client.config.postProcessResponse; | ||
this.client.config.wrapIdentifier = null; | ||
this.client.config.postProcessResponse = null; | ||
this.userParams.isProcessingDisabled = true; | ||
}, | ||
|
||
// Do not document this as public API until naming and API is improved for general consumption | ||
// This method exists to enable execution of non-internal queries with consistent identifier naming in migrations | ||
enableProcessing() { | ||
if (!this.userParams.isProcessingDisabled) { | ||
return; | ||
} | ||
this.client.config.wrapIdentifier = this.userParams.wrapIdentifier; | ||
this.client.config.postProcessResponse = this.userParams.postProcessResponse; | ||
this.userParams.isProcessingDisabled = false; | ||
}, | ||
|
||
withUserParams(params) { | ||
const knexClone = shallowCloneFunction(knexFn); // We need to include getters in our clone | ||
if (this.client) { | ||
|
@@ -103,6 +127,8 @@ function redefineProperties(knex, client) { | |
knex.ref = context.ref; | ||
knex.withUserParams = context.withUserParams; | ||
knex.queryBuilder = context.queryBuilder; | ||
knex.disableProcessing = context.disableProcessing; | ||
knex.enableProcessing = context.enableProcessing; | ||
}, | ||
configurable: true, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
exports.up = (knex) => { | ||
return knex.schema.createTable('old_users', (table) => { | ||
table.string('name'); | ||
}); | ||
}; | ||
|
||
exports.down = (knex) => { | ||
return knex.schema.dropTable('old_users'); | ||
}; |
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.
prettier picked this one up for some reason