Sindbad~EG File Manager

Current Path : /home/infinitibizsol/.trash/migrations/
Upload File :
Current File : /home/infinitibizsol/.trash/migrations/20240207064453-addforiegnkey.js

'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  
  
  async up(queryInterface, Sequelize) {
    /* await queryInterface.sequelize.query(`ALTER TABLE tblVehicleRunFees
    DROP FOREIGN KEY tblVehicleRunFees_ibfk_1;
    `);
    await queryInterface.sequelize
      .query(`ALTER TABLE tblVehicleRunFees CHANGE COLUMN vehicle_id vehicle_run_id INT;

    `);

    await queryInterface.sequelize.query(`ALTER TABLE tblVehicleRunFees
    ADD CONSTRAINT vehicle_run_id
    FOREIGN KEY (vehicle_run_id) REFERENCES tblVehicleRuns(vehicle_run_id);
    `); */

    await queryInterface.removeConstraint(
      "tblVehicleRunFees",
      "vehicle_id" // Use the constraint name given during the up migration
    );

    // Change the column name and its data type if necessary
    await queryInterface.renameColumn(
      "tblVehicleRunFees",
      "vehicle_id",
      "vehicle_run_id"
    );

   
    // Add the new foreign key constraint
    await queryInterface.addConstraint("tblVehicleRunFees", {
      fields: ["vehicle_run_id"],
      type: "foreign key",
      name: "vehicle_run_id",
      references: {
        table: "tblVehicleRuns",
        field: "vehicle_run_id",
      },
      onDelete: "CASCADE",
      onUpdate: "CASCADE",
    });
  },

  async down(queryInterface, Sequelize) {
    // Drop the new foreign key constraint first
    await queryInterface.removeConstraint(
      "tblVehicleRunFees",
      "vehicle_run_id" // Use the constraint name given during the up migration
    );

    // Rename the column back to vehicle_id
    await queryInterface.renameColumn(
      "tblVehicleRunFees",
      "vehicle_run_id",
      "vehicle_id"
    );

    // Re-add the original foreign key constraint
    await queryInterface.sequelize.query(`
  ALTER TABLE tblVehicleRunFees
    ADD CONSTRAINT vehicle_id
    FOREIGN KEY (vehicle_id) REFERENCES tblVehicles(vehicle_id)
    ON DELETE CASCADE
    ON UPDATE CASCADE;
`);
  },

    
};

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists