Dealer_Onboarding_Backend/scripts/update_enum.ts

34 lines
1.3 KiB
TypeScript
Raw Permalink 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 { APPLICATION_STATUS } from '../src/common/config/constants.js';
import db from '../src/database/models/index.js';
async function updateEnum() {
try {
console.log('🔄 Syncing all APPLICATION_STATUS values with DB Enum...');
const statuses = Object.values(APPLICATION_STATUS);
for (const status of statuses) {
try {
// Posgres doesn't support IF NOT EXISTS for ADD VALUE in 9.5 and below
// so we do it one by one and ignore "already exists" errors.
await db.sequelize.query(`ALTER TYPE "enum_applications_overallStatus" ADD VALUE '${status}'`);
console.log(`✅ Added: ${status}`);
} catch (e: any) {
if (e.message.includes('already exists')) {
// console.log(` Already exists: ${status}`);
} else {
console.error(`❌ Error adding ${status}:`, e.message);
}
}
}
console.log('\n✅ Database Enum successfully synchronized with constants.');
} catch (error: any) {
console.error('❌ Critical failure during sync:', error.message);
} finally {
process.exit(0);
}
}
updateEnum();