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

feat: update transaction documentation #419

Merged
merged 6 commits into from Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions docs/cli.md
Expand Up @@ -158,29 +158,30 @@ module.exports = {
};
```

The following is an example of a migration that performs two changes in the database, using an automatically-managed transaction to ensure that all instructions are successfully executed or rolled back in case of failure:
The following is an example of a migration that performs two changes in the database,
using an automatically-managed transaction to ensure that all instructions are successfully executed or rolled back in case of failure:

```js
const { DataTypes } = require('@sequelize/core');

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(t => {
return queryInterface.sequelize.transaction(transaction => {
return Promise.all([
queryInterface.addColumn('Person', 'petName', {
type: DataTypes.STRING
}, { transaction: t }),
}, { transaction }),
queryInterface.addColumn('Person', 'favoriteColor', {
type: DataTypes.STRING,
}, { transaction: t })
}, { transaction })
]);
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(t => {
return queryInterface.sequelize.transaction(transaction => {
return Promise.all([
queryInterface.removeColumn('Person', 'petName', { transaction: t }),
queryInterface.removeColumn('Person', 'favoriteColor', { transaction: t })
queryInterface.removeColumn('Person', 'petName', { transaction }),
queryInterface.removeColumn('Person', 'favoriteColor', { transaction })
]);
});
}
Expand Down Expand Up @@ -227,7 +228,7 @@ const { DataTypes } = require('@sequelize/core');

module.exports = {
async up(queryInterface) {
const transaction = await queryInterface.sequelize.transaction();
const transaction = await queryInterface.sequelize.startUnmanagedTransaction();
try {
await queryInterface.addColumn(
'Person',
Expand All @@ -253,7 +254,7 @@ module.exports = {
}
},
async down(queryInterface) {
const transaction = await queryInterface.sequelize.transaction();
const transaction = await queryInterface.sequelize.startUnmanagedTransaction();
try {
await queryInterface.removeColumn('Person', 'petName', { transaction });
await transaction.commit();
Expand Down
2 changes: 1 addition & 1 deletion docs/other-topics/aws-lambda.md
Expand Up @@ -579,7 +579,7 @@ a simplification of the method's logic for queries without transactions:
class Sequelize {
// (...)

query(sql, options) {
async query(sql, options) {
// (...)

const connection = await this.connectionManager.getConnection(options);
Expand Down
10 changes: 9 additions & 1 deletion docs/other-topics/upgrade.md
Expand Up @@ -68,14 +68,22 @@ If you do that, we recommend pinning the Sequelize version your project uses as

:::info

[CLS Transactions](../querying/transactions.md#automatically-pass-transactions-to-all-queries) are now enabled by default.
[CLS Transactions](../querying/transactions.md#disabling-cls) are now enabled by default.
You can use the [`disableClsTransactions`](pathname:///api/v7/interfaces/_sequelize_core.index.Options.html#disableClsTransactions) global option to disable them.

:::

Sequelize's CLS implementation has been migrated to use Node's built-in AsyncLocalStorage. This means you do not need to install the `continuation-local-storage` or `cls-hooked` packages anymore,
and that the `Sequelize.useCLS` method has been removed.

### Unmanaged transactions

*Pull Request [#15292](https://github.com/sequelize/sequelize/pull/15292)*

In order to discourage [unmanaged transactions](../querying/transactions.md#unmanaged-transactions), which we consider to be error-prone, `sequelize.transaction()` cannot be used to create unmanaged transactions anymore.
You must use `sequelize.startUnmanagedTransaction()` for that.
[Managed transactions](../querying/transactions.md#managed-transactions-recommended) continue to use `sequelize.transaction()`.

### `$bind` parameters in strings must not be escaped anymore

*Pull Request [#14447]*
Expand Down