49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import pg from 'pg';
|
|
const { Client } = pg;
|
|
|
|
const client = new Client({
|
|
user: 'laxman',
|
|
host: 'localhost',
|
|
database: 'royal_enfield_onboarding',
|
|
password: 'Admin@123',
|
|
port: 5432,
|
|
});
|
|
|
|
async function updateEnums() {
|
|
try {
|
|
await client.connect();
|
|
console.log('Connected to database.');
|
|
|
|
const enums = [
|
|
'Submitted',
|
|
'Questionnaire Pending',
|
|
'Questionnaire Completed',
|
|
'Shortlisted',
|
|
'Level 1 Pending',
|
|
'Level 1 Approved',
|
|
'Level 2 Pending',
|
|
'Level 2 Approved',
|
|
'EOR In Progress'
|
|
];
|
|
|
|
for (const val of enums) {
|
|
try {
|
|
// Quotes around value are crucial for case sensitivity if the enum type was created with quotes,
|
|
// but usually enum values are string literals.
|
|
await client.query(`ALTER TYPE "enum_applications_overallStatus" ADD VALUE IF NOT EXISTS '${val}'`);
|
|
console.log(`Added enum value: ${val}`);
|
|
} catch (e) {
|
|
console.log(`Could not add ${val}:`, e.message);
|
|
}
|
|
}
|
|
|
|
} catch (err) {
|
|
console.error('Connection error:', err);
|
|
} finally {
|
|
await client.end();
|
|
process.exit();
|
|
}
|
|
}
|
|
|
|
updateEnums();
|