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. |
theory
left a comment
There was a problem hiding this comment.
Thank you for the submission. However, this PR doesn't quite follow pgTAP's patterns. To whit, we already have has_*() functions for every type of constraint except constraint trigger and exclusion constraint. If you just want the ability to also specify the constraint name, just add alternatives.
I suggest making two PRs: One to add alternate signatures for the existing constraint functions to test constraint names, and a second to add the missing has_*() constraint functions.
Other general comments:
- All changes must be made to
pgtap.sql.in; it's the only script run most of the time. Duplicate anything that is added or changed insql/pgtap--1.3.4--1.3.5.sql. - Add tests for all changes, not just new functions. This PR doesn't test the new signatures for the
has_*()functions. - Document the new functions and function signatures in
doc/pgtap.md - List the changes in
Changes
Kind of but it's not symmetrical at all and constraint names aren't supported.
Agreed, I got carried away and probably 3 PRs might be the better call, because there's 3 pending issues:
Can you confirm that's a better way to go?
Got it.
I was waiting for feedback before getting into all that. All this being said, your thoughts on the overlap problems? |
Yes.
Overlap problems?
I'm fine to keep chatting here if it's helpful until you've made the other PRs. |
The ones clearly indicated in the source code and linked here: But regardless, part 1 (#369) and 2 (#370) are out, I'll wait for those to get resolved and merged before going forward with the |
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.