-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 3 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,26 @@ function initContext(knexFn) { | |
return this.client.ref(ref); | ||
}, | ||
|
||
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; | ||
}, | ||
|
||
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 +123,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 |
---|---|---|
|
@@ -8,17 +8,22 @@ describe('Migrator', () => { | |
describe('does not use postProcessResponse for internal queries', (done) => { | ||
let migrationSource; | ||
let knex; | ||
before(() => { | ||
beforeEach(() => { | ||
migrationSource = new FsMigrations('test/unit/migrate/migrations/'); | ||
knex = Knex({ | ||
...sqliteConfig, | ||
connection: ':memory:', | ||
migrationSource, | ||
postProcessResponse: () => { | ||
throw new Error('Response was processed'); | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
knex.destroy(); | ||
}); | ||
|
||
it('latest', (done) => { | ||
expect(() => { | ||
knex.migrate | ||
|
@@ -31,4 +36,35 @@ describe('Migrator', () => { | |
}).not.to.throw(); | ||
}); | ||
}); | ||
|
||
describe('uses postProcessResponse for migrations', (done) => { | ||
let migrationSource; | ||
let knex; | ||
before(() => { | ||
migrationSource = new FsMigrations( | ||
'test/unit/migrate/processed-migrations/' | ||
); | ||
}); | ||
|
||
after(() => { | ||
knex.destroy(); | ||
}); | ||
|
||
it('latest', (done) => { | ||
knex = Knex({ | ||
...sqliteConfig, | ||
connection: ':memory:', | ||
migrationSource, | ||
postProcessResponse: () => { | ||
done(); | ||
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. This test actually calls done, before execution of migrations has ended. Because that is separate inmemory database, it probably won't cause any problems. Except test might have been ended already before the expectation below has finished execution. |
||
}, | ||
}); | ||
|
||
expect(() => { | ||
knex.migrate.latest({ | ||
directory: 'test/unit/migrate/processed-migrations', | ||
}); | ||
}).not.to.throw(); | ||
}); | ||
}); | ||
}); |
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