Skip to content

Fixing #11 (enum name harmony) and #12 (pass down transaction) #13

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

Merged
merged 2 commits into from
Nov 23, 2020

Conversation

cyrilchapon
Copy link

Fixing #11
Fixing #12

Transaction passing down require additional manual testing

TheOptimisticFactory pushed a commit to TheOptimisticFactory/sequelize_replace_enum_postgres that referenced this pull request Jun 28, 2019
Temporary until abelosorio#13 gets merged
@TheOptimisticFactory
Copy link

I've taken the liberty of publishing your changeset under "@joethefkingfrypan/sequelize-replace-enum-postgres": "^1.6.0-rc1" until your PR gets merged 😃

@cyrilchapon
Copy link
Author

Great news dude :)

@cyrilchapon
Copy link
Author

(I'll close issues when merged into release ?)

@cyrilchapon
Copy link
Author

cyrilchapon commented Jun 28, 2019

NB: One thing to note is that I'm using a not-very-documented sequelize Feature : when you pass a sequelizeOptions to sequelize.transaction(sequelizeOptions (before the callback); and that sequelizeOptions contain a transaction; then the created transaction is kind of a "sub-transaction" (in postgres, it actually creates a savepoint).

NB2: I'm not .catching anything on the promise neither on the sub-transaction, and letting the error bubble up intentionnaly. This will defer the handling of the error to the calling context. For example :

intentionally fail the parent transaction also

await sequelizeTransaction(async parentTransaction => {
  await replaceEnum({ transaction: parentTransaction })
  // any reject on replaceEnum
  // will chain reject parent function
  // and rollback parentTransaction
})

intentionally handle the error, and resolve parent transaction

await sequelizeTransaction(async parentTransaction => {
  try {
    await replaceEnum({ transaction: parentTransaction })
  } catch (err) {
    console.error('non important error')

    // Here, catching will cause
    // parent function to resolve
    // and parentTransaction to commit
    // but keeping the replaceEnum "sub-transaction"
    // to rollback
  }
})

@abelosorio
Copy link
Owner

Hi @cyrilchapon @TheOptimisticFactory, have you guys tested this PR? Currently, I don't have time for this project, so I'm relying on you for this. Let me know if this is fully tested and I'll merge it.

@cyrilchapon
Copy link
Author

Hey @abelosorio

I wrote a couple of unit tests, but that's the kind of features I usually test with "side effects tests" (against a real database instead of a mocked one).

@cyrilchapon
Copy link
Author

To be perfectly honest I would not be 100% confident deploying it on production (though, I did). I think this is so specific that it needs to be unit tested agasint a real database

@cyrilchapon
Copy link
Author

To override explicitly null / 0 / "" passed values, but this is overkill indeed ☺️

@abelosorio
Copy link
Owner

To override explicitly null / 0 / "" passed values, but this is overkill indeed

Yeah, I think so as well. Can you remove it so I can merge this?

Thanks

@abelosorio abelosorio merged commit 0212ca9 into abelosorio:master Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants