Fix migration: add OVERRIDING SYSTEM VALUE and reset sequence before Archer insert
The Jira tickets preserve their original IDs via OVERRIDING SYSTEM VALUE, then the sequence is reset to max(id) before Archer rows auto-increment. Without this, Archer inserts collide with Jira IDs on the primary key.
This commit is contained in:
@@ -98,10 +98,15 @@ async function run() {
|
||||
|
||||
const { rowCount: jiraCount } = await client.query(`
|
||||
INSERT INTO tickets (id, ticket_type, ticket_key, cve_id, vendor, url, summary, status, jira_id, jira_status, last_synced_at, source_context, created_by, created_at, updated_at)
|
||||
OVERRIDING SYSTEM VALUE
|
||||
${jiraSelect}
|
||||
ON CONFLICT (ticket_key) DO NOTHING
|
||||
`);
|
||||
console.log(`✓ Migrated ${jiraCount} Jira ticket(s) into unified table`);
|
||||
|
||||
// Reset sequence after Jira insert so Archer auto-increment doesn't collide
|
||||
const { rows: maxAfterJira } = await client.query(`SELECT COALESCE(MAX(id), 0) AS max_id FROM tickets`);
|
||||
await client.query(`SELECT setval('tickets_id_seq', $1, true)`, [maxAfterJira[0].max_id]);
|
||||
} else {
|
||||
console.log('⊘ jira_tickets table not found (already renamed or does not exist)');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user