fix(core): Metadata inserts using existing IDs and failing with postgres (#10108)

This commit is contained in:
Danny Martini 2024-07-23 10:31:04 +02:00 committed by GitHub
parent 6209ac6824
commit 4547a49db1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 0 deletions

View file

@ -108,5 +108,15 @@ export class AddConstraintToExecutionMetadata1720101653148 implements Reversible
await context.runQuery(
`ALTER TABLE ${executionMetadataTableTemp} RENAME TO ${executionMetadataTable};`,
);
if (context.dbType === 'postgresdb') {
// Update sequence so that inserts continue with the next highest id.
const tableName = escape.tableName('execution_metadata');
const sequenceName = escape.tableName('execution_metadata_temp_id_seq1');
await context.runQuery(
`SELECT setval('${sequenceName}', (SELECT MAX(id) FROM ${tableName}));`,
);
}
}
}

View file

@ -0,0 +1,12 @@
import type { IrreversibleMigration, MigrationContext } from '@db/types';
export class FixExecutionMetadataSequence1721377157740 implements IrreversibleMigration {
async up({ queryRunner, escape }: MigrationContext) {
const tableName = escape.tableName('execution_metadata');
const sequenceName = escape.tableName('execution_metadata_temp_id_seq');
await queryRunner.query(
`SELECT setval('${sequenceName}', (SELECT MAX(id) FROM ${tableName}));`,
);
}
}

View file

@ -58,6 +58,7 @@ import { RemoveNodesAccess1712044305787 } from '../common/1712044305787-RemoveNo
import { MakeExecutionStatusNonNullable1714133768521 } from '../common/1714133768521-MakeExecutionStatusNonNullable';
import { AddActivatedAtUserSetting1717498465931 } from './1717498465931-AddActivatedAtUserSetting';
import { AddConstraintToExecutionMetadata1720101653148 } from '../common/1720101653148-AddConstraintToExecutionMetadata';
import { FixExecutionMetadataSequence1721377157740 } from './1721377157740-FixExecutionMetadataSequence';
export const postgresMigrations: Migration[] = [
InitialMigration1587669153312,
@ -119,4 +120,5 @@ export const postgresMigrations: Migration[] = [
MakeExecutionStatusNonNullable1714133768521,
AddActivatedAtUserSetting1717498465931,
AddConstraintToExecutionMetadata1720101653148,
FixExecutionMetadataSequence1721377157740,
];