From 549236f2db2e7afc743cee49e08b6b84a0b5e2be Mon Sep 17 00:00:00 2001 From: antanst <> Date: Thu, 31 Jul 2025 10:21:52 +0300 Subject: [PATCH] Fix migration for duplicate column, fixes #202 --- ...50716085710-add-parent-task-id-to-tasks.js | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) 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) {