icefoganalytics / travel-authorization

0 stars 0 forks source link

Fix Mixing of Knex and Sequelize Transactions #190

Closed klondikemarlen closed 1 month ago

klondikemarlen commented 2 months ago

Relates to:

Context

Is your feature request related to a problem? Please describe. I had thought that mixing Knex and Sequelize transactions would work, but had not tested it. It does not work, as identified in https://github.com/icefoganalytics/wrap/pull/16

Describe the solution you'd like Switch to only using Sequelize code when running in a transaction. Use https://github.com/icefoganalytics/wrap/pull/16/commits/ec6cae86f72f7af0342396513da057628ccf1c22.

Describe alternatives you've considered Removing all transaction related code during migration to Sequelize. I don't like this solution because the transaction code might never be added back in.

Additional context

const knexTransaction = await knex.transaction()
const [newPlayer] = await knexTransaction("workflow_players").insert(player).returning<WorkflowPlayer[]>("*")
knexTransaction.comit()

becomes

sequelize.transaction(async () => {
  // other code

  const [newPlayer] = await knexQueryToSequelizeSelect<WorkflowPlayer>(
    knex("workflow_players").insert(player).returning<WorkflowPlayer[]>("*")
  )
})

// other code