Skip to content

Commit 2bf2dcf

Browse files
committed
Run remove-user-token migration in a transaction
In the case where there are empty passwords the `changeColumn` command for the `password` column would fail, but the `token` column would be deleted causing `column "token" of relation "user" does not exist` errors on new migration runs.
1 parent d9402ce commit 2bf2dcf

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

server/shared/database/migrations/20190717151916-remove-user-token.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ const TABLE = 'user';
66

77
module.exports = {
88
up: async qi => {
9-
await qi.removeColumn(TABLE, 'token');
10-
await qi.changeColumn(TABLE, 'password', {
11-
type: Sequelize.STRING,
12-
allowNull: false
9+
return qi.sequelize.transaction(async transaction => {
10+
await qi.removeColumn(TABLE, 'token', { transaction });
11+
await qi.changeColumn(TABLE, 'password', {
12+
type: Sequelize.STRING,
13+
allowNull: false
14+
}, { transaction });
1315
});
1416
},
1517
down: async qi => {
16-
await qi.addColumn(TABLE, 'token', { type: Sequelize.STRING, unique: true });
17-
await qi.changeColumn(TABLE, 'password', {
18-
type: Sequelize.STRING,
19-
allowNull: true
18+
return qi.sequelize.transaction(async transaction => {
19+
await qi.addColumn(TABLE, 'token', { type: Sequelize.STRING, unique: true }, { transaction });
20+
await qi.changeColumn(TABLE, 'password', {
21+
type: Sequelize.STRING,
22+
allowNull: true
23+
}, { transaction });
2024
});
2125
}
2226
};

0 commit comments

Comments
 (0)