Add constraint checking functions and tests#363
Conversation
Implemented new functions for checking the existence of constraints in PostgreSQL: `_has_constraint`, `has_constraint`, and `hasnt_constraint`. These functions support both schema-qualified and unqualified table names, along with type and description parameters. Additionally, added comprehensive tests for these functions in `constraint.sql`, ensuring they handle various scenarios correctly, including existence checks and type validation. Created expected output for the tests in `constraint.out` to verify functionality. This update enhances the constraint validation capabilities of pgTAP, providing users with more robust testing options.
|
@theory |
|
I'm a little confused. We already have It also recreates the functions in the tests, which should not be necessary. This looks like a bot-created change. Please don't submit machine-generated code. If there is a feature you need, please implement it or ask for it in an issue. |
I didn't know it existed, it's undocumented... And in any case, it doesn't cover my use-case, which is: ok(
EXISTS(
SELECT FROM pg_constraint
INNER JOIN pg_class ON pg_constraint.conrelid = pg_class.oid
INNER JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
WHERE
pg_namespace.nspname = 'schema'
AND pg_class.relname = 'table'
AND pg_constraint.conname = 'ck__something__something'
AND pg_constraint.contype = 'c'
AND pg_constraint.coninhcount = 0
),
'Constraint ck__something__something' should exist'::TEXT
),The
I can fix that.
I can redo the PR to build on top of |
|
@theory I also added And speaking of symmetry, I notice there wasnt any Finally I also noted overlap problems which I suppose I'll need to resolve assuming you think this addition as a place in your project. Which didn't really seem to be the case from your first response, hopefully this fix changes that. |
|
Since we have the other constraint-checking functions, I don't think you need add public functions [Reads some more] Oh, I see you have those in the upgrade script. They need to be in I guess I have no objection to also adding a generic Please also add documentation to |
Appended at the bottom, or alongside next of kin (to maintain structure)? IE: |
…uss which variation is of higher value
…another issue with github
|
Okay this is ready for another round of feedback / review.
|
|
@theory Any news? |
|
I'm traveling, so only working on stuff like this occasionally. Might be a few weeks before I get back to it. Apologies. |
Implemented new functions for checking the existence of constraints in PostgreSQL:
_has_constraint,has_constraint, andhasnt_constraint. These functions support both schema-qualified and unqualified table names, along with type and description parameters.Additionally, added comprehensive tests for these functions in
constraint.sql, ensuring they handle various scenarios correctly, including existence checks and type validation. Created expected output for the tests inconstraint.outto verify functionality.This update enhances the constraint validation capabilities of pgTAP, providing users with more robust testing options.