gancio-upstream/server/migrations/20240817203545-sortIndexCollection.js
2024-08-21 10:46:23 +02:00

24 lines
810 B
JavaScript

'use strict';
const Collection = require('../api/models/collection')
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up (queryInterface, Sequelize) {
const transaction = await queryInterface.sequelize.transaction()
try {
await queryInterface.addColumn('collections', 'sortIndex', { type: Sequelize.INTEGER })
const collection = Collection(queryInterface.sequelize, Sequelize.DataTypes)
await collection.update({ sortIndex: Sequelize.col('id')}, { where: {}, transaction })
return transaction.commit()
} catch (e) {
if (transaction) {
await transaction.rollback()
}
return Promise.reject(e)
}
},
async down (queryInterface, Sequelize) {
return queryInterface.removeColumn('collections', 'sortIndex')
}
}