Skip to content

Pass down transaction #12

Closed
Closed
@cyrilchapon

Description

@cyrilchapon

The strategy taken in "unitary" function (dropEnum for example) to accept a passed down transaction (and even sequelizeOptions more generaly) should be replicated to the main function.

Why ?

For example, in here we're managing some migrations inside a whole transaction, because that make sense to create, for example, an enum + a table + some index in a single migration. We want it to success-all or fail-all, thus we wrap it inside a transaction

For example, in the up :

    return sqlQueryInterface.sequelize.transaction(t => {
      return createEnum({
        // ... Omitted for example
        name: 'my_enum_type',
        sequelizeOptions: { transaction: t }
      })
        .then(() => {
          return sqlQueryInterface.createTable('my_table', {
            // ... Omitted for example
            myEnumColumn: {
              field: 'my_enum_column',
              type: 'my_enum_type',
              allowNull: false
            },
          }, {
            transaction: t
          })
            .then(() => {
              return Promise.all([
                sqlQueryInterface.addIndex('my_index', {
                  // ... omitted for example
                  transaction: t
                }),
                sqlQueryInterface.addIndex('my_second_index', {
                  // ... Omitted for example
                  transaction: t
                })
              ])
            })
        })
    })

Notice how we pass-down sequelizeOptions with transaction to createEnum

This is currently impossible with default function (changeEnum).

I'm going to PR it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions