Make legacy Jira migrations skip gracefully when tickets table exists

After the unify_tickets_table migration runs, jira_tickets is renamed to
jira_tickets_legacy. The four earlier Jira migrations now detect the unified
tickets table and exit cleanly instead of failing with 'table does not exist'.
This commit is contained in:
Jordan Ramos
2026-08-18 14:26:05 -06:00
parent 04d96730e2
commit a178e5e772
4 changed files with 48 additions and 0 deletions

View File

@@ -15,6 +15,16 @@ async function run() {
WHERE table_schema = 'public' AND table_name = 'jira_tickets'
`);
if (rows.length === 0) {
// Check if unified tickets table exists (post-unification)
const { rows: unified } = await pool.query(`
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = 'tickets'
`);
if (unified.length > 0) {
console.log('✓ Skipped — jira_tickets unified into tickets table');
await pool.end();
process.exit(0);
}
console.error('✗ jira_tickets table does not exist. Cannot proceed.');
process.exit(1);
}

View File

@@ -13,6 +13,16 @@ async function run() {
WHERE table_schema = 'public' AND table_name = 'jira_tickets'
`);
if (rows.length === 0) {
// Check if unified tickets table exists (post-unification)
const { rows: unified } = await pool.query(`
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = 'tickets'
`);
if (unified.length > 0) {
console.log('✓ Skipped — jira_tickets unified into tickets table');
await pool.end();
process.exit(0);
}
console.error('✗ jira_tickets table does not exist. Cannot proceed.');
process.exit(1);
}

View File

@@ -14,6 +14,16 @@ async function run() {
WHERE table_schema = 'public' AND table_name = 'jira_tickets'
`);
if (jiraTable.length === 0) {
// Check if unified tickets table exists (post-unification)
const { rows: unified } = await pool.query(`
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = 'tickets'
`);
if (unified.length > 0) {
console.log('✓ Skipped — jira_tickets unified into tickets table');
await pool.end();
process.exit(0);
}
console.error('✗ jira_tickets table does not exist. Cannot proceed.');
process.exit(1);
}

View File

@@ -7,6 +7,24 @@ const pool = require('../db');
async function run() {
console.log('[Migration] Dropping jira_tickets_status_check constraint...');
// Check if jira_tickets still exists (may have been unified into tickets table)
const { rows } = await pool.query(`
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = 'jira_tickets'
`);
if (rows.length === 0) {
const { rows: unified } = await pool.query(`
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = 'tickets'
`);
if (unified.length > 0) {
console.log('✓ Skipped — jira_tickets unified into tickets table');
await pool.end();
return;
}
}
await pool.query(`ALTER TABLE jira_tickets DROP CONSTRAINT IF EXISTS jira_tickets_status_check`);
console.log('✓ jira_tickets status CHECK constraint dropped (or did not exist)');
await pool.end();