fix: transaction error (#1162)

This commit is contained in:
ChengLei Shao 2022-11-30 11:37:59 +08:00 committed by GitHub
parent 7cfa939f63
commit dea9655573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 13 deletions

View File

@ -90,20 +90,29 @@ export class SyncRunner {
const sequenceTables = [...parentsDeep, tableName]; const sequenceTables = [...parentsDeep, tableName];
for (const sequenceTable of sequenceTables) { for (const sequenceTable of sequenceTables) {
try { const idColumnQuery = await queryInterface.sequelize.query(
await queryInterface.sequelize.query( `
`alter table "${sequenceTable}" alter column id set default nextval('${maxSequenceName}')`, SELECT true
{ FROM pg_attribute
transaction, WHERE attrelid = '${sequenceTable}'::regclass -- cast to a registered class (table)
}, AND attname = 'id'
); AND NOT attisdropped
} catch (err) { `,
if (err.message.match(/column "id" of relation "\w+" does not exist/)) { {
continue; transaction,
} },
);
throw err; if (idColumnQuery[0].length == 0) {
continue;
} }
await queryInterface.sequelize.query(
`alter table "${sequenceTable}" alter column id set default nextval('${maxSequenceName}')`,
{
transaction,
},
);
} }
} }

@ -1 +1 @@
Subproject commit cf44c47ff9b5ef41e8becde3f1c8b5b1c2af6cda Subproject commit 5a5fba41ae1cecaf3b073fcb610e9dc68dad0b85