Dealer_Onboarding_Backend/scripts/fix_constitutional_enum.ts

31 lines
1.1 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 db from '../src/database/models/index.js';
async function fixEnum() {
const enumName = 'enum_constitutional_changes_changeType';
const newValues = ['Proprietorship', 'Partnership', 'LLP', 'Private Limited'];
console.log(`--- Patching DB ENUM: ${enumName} ---`);
for (const val of newValues) {
try {
// Sequelize does not have a direct method for ADD VALUE to ENUM in all dialects, using raw query
// Using check to avoid "already exists" error
await db.sequelize.query(`ALTER TYPE "${enumName}" ADD VALUE IF NOT EXISTS '${val}'`);
console.log(`✅ Added '${val}' to ${enumName}`);
} catch (err: any) {
if (err.message.includes('already exists')) {
console.log(` '${val}' already exists in ${enumName}`);
} else {
console.log(`❌ Failed to add '${val}':`, err.message);
}
}
}
console.log('--- ENUM Patching Complete ---');
}
fixEnum().catch(err => {
console.error('Migration failed:', err);
process.exit(1);
}).then(() => process.exit(0));