From 18490b07650d77d7fe376970b749af5a8c672fd6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 25 Nov 2020 11:04:18 +0100 Subject: Fix migration and test --- .../migrations/0530-user-feed-token.ts | 40 ----------------- .../migrations/0560-user-feed-token.ts | 51 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 40 deletions(-) delete mode 100644 server/initializers/migrations/0530-user-feed-token.ts create mode 100644 server/initializers/migrations/0560-user-feed-token.ts (limited to 'server/initializers/migrations') diff --git a/server/initializers/migrations/0530-user-feed-token.ts b/server/initializers/migrations/0530-user-feed-token.ts deleted file mode 100644 index 421016b11..000000000 --- a/server/initializers/migrations/0530-user-feed-token.ts +++ /dev/null @@ -1,40 +0,0 @@ -import * as Sequelize from 'sequelize' -import { v4 as uuidv4 } from 'uuid' - -async function up (utils: { - transaction: Sequelize.Transaction - queryInterface: Sequelize.QueryInterface - sequelize: Sequelize.Sequelize - db: any -}): Promise { - const q = utils.queryInterface - - // Create uuid column for users - const userFeedTokenUUID = { - type: Sequelize.UUID, - defaultValue: Sequelize.UUIDV4, - allowNull: true - } - await q.addColumn('user', 'feedToken', userFeedTokenUUID) - - // Set UUID to previous users - { - const query = 'SELECT * FROM "user" WHERE "feedToken" IS NULL' - const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT } - const users = await utils.sequelize.query(query, options) - - for (const user of users) { - const queryUpdate = `UPDATE "user" SET "feedToken" = '${uuidv4()}' WHERE id = ${user.id}` - await utils.sequelize.query(queryUpdate) - } - } -} - -function down (options) { - throw new Error('Not implemented.') -} - -export { - up, - down -} diff --git a/server/initializers/migrations/0560-user-feed-token.ts b/server/initializers/migrations/0560-user-feed-token.ts new file mode 100644 index 000000000..7c61def17 --- /dev/null +++ b/server/initializers/migrations/0560-user-feed-token.ts @@ -0,0 +1,51 @@ +import * as Sequelize from 'sequelize' +import { v4 as uuidv4 } from 'uuid' + +async function up (utils: { + transaction: Sequelize.Transaction + queryInterface: Sequelize.QueryInterface + sequelize: Sequelize.Sequelize + db: any +}): Promise { + const q = utils.queryInterface + + { + // Create uuid column for users + const userFeedTokenUUID = { + type: Sequelize.UUID, + defaultValue: Sequelize.UUIDV4, + allowNull: true + } + await q.addColumn('user', 'feedToken', userFeedTokenUUID) + } + + // Set UUID to previous users + { + const query = 'SELECT * FROM "user" WHERE "feedToken" IS NULL' + const options = { type: Sequelize.QueryTypes.SELECT as Sequelize.QueryTypes.SELECT } + const users = await utils.sequelize.query(query, options) + + for (const user of users) { + const queryUpdate = `UPDATE "user" SET "feedToken" = '${uuidv4()}' WHERE id = ${user.id}` + await utils.sequelize.query(queryUpdate) + } + } + + { + const userFeedTokenUUID = { + type: Sequelize.UUID, + defaultValue: Sequelize.UUIDV4, + allowNull: false + } + await q.changeColumn('user', 'feedToken', userFeedTokenUUID) + } +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3