diff --git a/backend/migrations/20250716085710-add-parent-task-id-to-tasks.js b/backend/migrations/20250716085710-add-parent-task-id-to-tasks.js index ba0d067..3899cb3 100644 --- a/backend/migrations/20250716085710-add-parent-task-id-to-tasks.js +++ b/backend/migrations/20250716085710-add-parent-task-id-to-tasks.js @@ -1,20 +1,27 @@ 'use strict'; +const { safeAddColumns, safeAddIndex } = require('../utils/migration-utils'); + /** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface, Sequelize) { - await queryInterface.addColumn('tasks', 'parent_task_id', { - type: Sequelize.INTEGER, - allowNull: true, - references: { - model: 'tasks', - key: 'id', + await safeAddColumns(queryInterface, 'tasks', [ + { + name: 'parent_task_id', + definition: { + type: Sequelize.INTEGER, + allowNull: true, + references: { + model: 'tasks', + key: 'id', + }, + onUpdate: 'CASCADE', + onDelete: 'CASCADE', + }, }, - onUpdate: 'CASCADE', - onDelete: 'CASCADE', - }); + ]); - await queryInterface.addIndex('tasks', ['parent_task_id']); + await safeAddIndex(queryInterface, 'tasks', ['parent_task_id']); }, async down(queryInterface) {