import { DataTypes, type QueryInterface } from 'sequelize';

/**
 * Platform-scope internal alerts are owned by the global scope, represented by
 * a null tenant chain. Tenant alerts still carry organization/school/campus ids.
 */
export default {
  up: async (queryInterface: QueryInterface) => {
    await queryInterface.changeColumn('communication_events', 'organizationId', {
      type: DataTypes.UUID,
      allowNull: true,
    });
  },

  down: async (queryInterface: QueryInterface) => {
    await queryInterface.sequelize.query(`
      DELETE FROM "communication_events"
      WHERE "organizationId" IS NULL
    `);
    await queryInterface.changeColumn('communication_events', 'organizationId', {
      type: DataTypes.UUID,
      allowNull: false,
    });
  },
};
