Re_Backend/src/migrations/20251118-add-breach-reason-to-approval-levels.ts

50 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { QueryInterface, DataTypes } from 'sequelize';
/**
* Migration: Add breach_reason column to approval_levels table
* Purpose: Store TAT breach reason directly in approval_levels table
* Date: 2025-11-18
*/
export async function up(queryInterface: QueryInterface): Promise<void> {
// Check if table exists first
const tables = await queryInterface.showAllTables();
if (!tables.includes('approval_levels')) {
// Table doesn't exist yet, skipping
return;
}
// Get existing columns
const tableDescription = await queryInterface.describeTable('approval_levels');
// Add breach_reason column only if it doesn't exist
if (!tableDescription.breach_reason) {
await queryInterface.addColumn('approval_levels', 'breach_reason', {
type: DataTypes.TEXT,
allowNull: true,
comment: 'Reason for TAT breach - can contain paragraph-length text'
});
console.log('✅ Added breach_reason column to approval_levels table');
} else {
console.log(' breach_reason column already exists, skipping');
}
}
export async function down(queryInterface: QueryInterface): Promise<void> {
// Check if table exists
const tables = await queryInterface.showAllTables();
if (!tables.includes('approval_levels')) {
return;
}
// Get existing columns
const tableDescription = await queryInterface.describeTable('approval_levels');
// Remove column only if it exists
if (tableDescription.breach_reason) {
await queryInterface.removeColumn('approval_levels', 'breach_reason');
console.log('✅ Removed breach_reason column from approval_levels table');
}
}