Skip to content

Commit

Permalink
fix: use validate after create constraint partition not valid (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
fibonacci998 authored Nov 29, 2023
1 parent 886a4d9 commit 108c91b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/services/job/create_constraint_in_attr_partition.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
}
}
Expand All @@ -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}`
);
}
}
Expand Down

0 comments on commit 108c91b

Please sign in to comment.