Skip to content
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

fix migrate:up for migrations disabling transactions #4550

Conversation

michaelbrewerdavis
Copy link
Contributor

knex migrate:up <migration>

does not respect configuration

export const config = { transaction: false }

due to treating the return value of getMigration as a value rather than a promise.

I could use advice on where to add tests for this behavior.

@jeff-permiso
Copy link

Bump

@kibertoad
Copy link
Collaborator

@jeff-permiso Sorry for the delay.
Mixing promise chain with an async/await is not the best solution. Could you please rewrite the whole block to use async/await?
Also this change is missing a test.

- also add tests for migrate:up, migrate:down when
  transactions are disabled
@michaelbrewerdavis
Copy link
Contributor Author

@kibertoad Sorry for the delay -- I've added tests around single up/down migrations without transactions, and refactored the method as requested.

@michaelbrewerdavis
Copy link
Contributor Author

@kibertoad Any feedback on the tests or refactoring?

Thanks much.

exports.up = async function () {};

exports.down = async function (knex) {
if (isPostgreSQL(knex)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem to be the right place for skipping the test, could you move it into a test itself? there are plenty of examples of how db-specific tests are handled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to test

);
});

it('should run', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this test those migrations to simply not fail with an error? can we also assert that they actually did what we expect them to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migrations don't actually do anything other than throw an error if called within a transaction. Added a comment to that effect.

});

it('should not error if all migrations have already been undone', function () {
return knex.migrate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be rewritten into async/await?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor Author

@michaelbrewerdavis michaelbrewerdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated PR with requests

);
});

it('should run', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migrations don't actually do anything other than throw an error if called within a transaction. Added a comment to that effect.

exports.up = async function () {};

exports.down = async function (knex) {
if (isPostgreSQL(knex)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to test

});

it('should not error if all migrations have already been undone', function () {
return knex.migrate
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@kibertoad
Copy link
Collaborator

What is PostgreSQL-specific for these tests, btw? Aren't transactions pretty universal?

@michaelbrewerdavis
Copy link
Contributor Author

What is PostgreSQL-specific for these tests, btw? Aren't transactions pretty universal?

The method I was using to test being in a transaction wasn't. Rewrote to make more universal.

@kibertoad kibertoad merged commit b522517 into knex:master Aug 31, 2021
@kibertoad
Copy link
Collaborator

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants