From 108c91b3ef94e983a348a31936d89db807c5649b Mon Sep 17 00:00:00 2001 From: Tuan Phan Anh <38557844+fibonacci998@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:06:10 +0700 Subject: [PATCH] fix: use validate after create constraint partition not valid (#505) --- ...te_constraint_in_attr_partition.service.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/services/job/create_constraint_in_attr_partition.service.ts b/src/services/job/create_constraint_in_attr_partition.service.ts index 99ea020a5..eb06f1849 100644 --- a/src/services/job/create_constraint_in_attr_partition.service.ts +++ b/src/services/job/create_constraint_in_attr_partition.service.ts @@ -178,12 +178,17 @@ export default class CreateConstraintInAttrPartitionJob extends BullableService .transacting(trx); await knex .raw( - `alter table ${_payload.name} add constraint ${contraintName} check ${createFullConstraintScript}` + `alter table ${_payload.name} add constraint ${contraintName} check ${createFullConstraintScript} not valid` + ) + .transacting(trx); + await knex + .raw( + `alter table ${_payload.name} validate constraint ${contraintName}` ) .transacting(trx); }); this.logger.info( - `Drop and create new constraint in partition ${_payload.name}` + `Dropped and created new constraint in partition ${_payload.name}` ); } } @@ -192,17 +197,23 @@ export default class CreateConstraintInAttrPartitionJob extends BullableService if (constraintResult.rows.length === 0) { if (_payload.status === this.statusPartition.done) { await knex.raw( - `alter table ${_payload.name} add constraint ${contraintName} check ${createFullConstraintScript}` + `alter table ${_payload.name} add constraint ${contraintName} check ${createFullConstraintScript} not valid` + ); + await knex.raw( + `alter table ${_payload.name} validate constraint ${contraintName}` ); this.logger.info( - `Creating new full constraint in partition ${_payload.name}` + `Created new full constraint in partition ${_payload.name}` ); } else if (_payload.status === this.statusPartition.running) { await knex.raw( - `alter table ${_payload.name} add constraint ${contraintName} check ${createLowerBoundConstraintScript}` + `alter table ${_payload.name} add constraint ${contraintName} check ${createLowerBoundConstraintScript} not valid` + ); + await knex.raw( + `alter table ${_payload.name} validate constraint ${contraintName}` ); this.logger.info( - `Creating new lower bound constraint in partition ${_payload.name}` + `Created new lower bound constraint in partition ${_payload.name}` ); } }