// Migration: Add DECOM to workflow_type CHECK constraint on ivanti_todo_queue
// Run from backend/: node migrations/add_decom_workflow_type.js

const pool = require('../db');

async function migrate() {
    console.log('Starting add_decom_workflow_type migration...');

    try {
        // Drop the existing constraint and add the updated one
        await pool.query(`
            ALTER TABLE ivanti_todo_queue
            DROP CONSTRAINT IF EXISTS ivanti_todo_queue_workflow_type_check
        `);
        console.log('✓ Dropped old workflow_type constraint');

        await pool.query(`
            ALTER TABLE ivanti_todo_queue
            ADD CONSTRAINT ivanti_todo_queue_workflow_type_check
            CHECK (workflow_type IN ('FP', 'Archer', 'CARD', 'GRANITE', 'DECOM'))
        `);
        console.log('✓ Added updated workflow_type constraint (includes DECOM)');

        console.log('Migration complete!');
    } catch (err) {
        console.error('Migration failed:', err.message);
        process.exit(1);
    } finally {
        await pool.end();
    }
}

migrate();
