Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cols_is_pk variants #178

Closed
wants to merge 11 commits into from
Closed

Conversation

fluca1978
Copy link
Contributor

This is a potential implementation of #133, in particular col_is_pk(name, name, name).
I'm not sure this is something really required, because there is a potential clash with a textual overloaded function: col_is_pk( name, name, name) requires explicit cast to not clahs with col_is_pk( name, name, description).
I'm not able to decide which is best approach, but sounds to me that col_is_pk( 'public', 'foo', 'id' ) is simpler than col_is_pk( 'public', 'foo', 'id'::name ). Therefore I'm not sure this pull request is the right implementation, and before digging into 'isnt_col_pk' set of functions I would like comments.

This allows for the automatic overloading of the function, implementing
therefore the col_is_pk( name, name, name[] ) as requested in issue theory#133.

See issue theory#133.
format() has been introduced with 9.1 or so, and using it to easiliy
compose messages produces errors in compatibility with older versions.
Due to the addition of variants methods the output of the test has changed.
Copy link
Owner

@theory theory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if it is likely to break existing tests that don't have a cast, I'm not sure adding a new test function makes sense. I like supporting as many variants as possible, and am sad that I missed some when I originally wrote this thing.

OTOH, if it's the new variant that would require casting, and the old variant continued to work, that would be just fine. We have to decide what to do about DEFAULT and older versions of Postgres, though.

@@ -1952,41 +1952,44 @@ RETURNS NAME[] AS $$
$$ LANGUAGE sql;

-- col_is_pk( schema, table, column, description )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT )
-- col_is_pk( schema, table, column )
CREATE OR REPLACE FUNCTION col_is_pk ( NAME, NAME, NAME[], TEXT DEFAULT NULL )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit DEFAULT until support for 8.3 is dropped.

RETURNS TEXT AS $$
SELECT is( _ckeys( $1, $2, 'p' ), $3, $4 );
SELECT is( _ckeys( $1, $2, 'p' ), $3,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without support for DEFAULT, the pattern up to now has been to create separate functions for each signature. Unless @decibel or someone finishes the update to remove support for 9.0 and earlier, I think we need to stick to that pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, I'll try to refactor as soon as I've time.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master is no longer testing < 9.1, so I think DEFAULT is ok now. It'd be good to merge master though since it now has much more extensive automated testing.

);

SELECT * FROM check_test(
col_is_pk( 'sometab', 'id'::name, 'sometab.id should be a pk' ),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the name cast needed here? AFAICT requiring users to add that would break backwards compatibility, which I don't think we can do :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, https://travis-ci.org/theory/pgtap/jobs/614184912 shows that we have a problem when removing this cast. :(

One possible way to handle this would be C code, since we could then use one of the polymorphic pseudotypes. I'm not sure this feature is worth that though.

We could possibly have a config option to make to provide the old behavior.

Another possibility would be a version of the function that checked the first argument to see if it was a schema vs a table and acted accordingly (as well as throwing the correct error if neither existed). Before trying to code that we'd want to make sure we have full test cases for all the possible "does not exist" cases, both with and without a description provided. This would be unfortunately complex, but I think it's doable.

Well, or we could just tell people we're breaking backwards compatibility... but if we wanted to do that I think we'd need to do a 2.0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still an issue as well.

nasbyj and others added 4 commits November 19, 2019 13:53
@fluca1978
Copy link
Contributor Author

I've done some moneky typing merging the master branch, and make installcheck passes all the tests right now, at least against version 12.
Since it has passed a lot of time, please advice if there is some more work to be done.

@nasbyj
Copy link
Collaborator

nasbyj commented Nov 22, 2019

Looks like the ALTER EXTENSION UPDATE tests are failing (https://travis-ci.org/theory/pgtap/builds/615528764); is your latest code in sql/pgtap--1.0.0--1.1.0.sql?

@fluca1978
Copy link
Contributor Author

Seems to me my branch is updated as commit 950c170 which does me the pktap test passing:

% pg_prove test/sql/pktap.sql 
test/sql/pktap.sql .. ok     
All tests successful.
Files=1, Tests=87,  1 wallclock secs ( 0.04 usr  0.00 sys +  0.01 cusr  0.00 csys =  0.05 CPU)
Result: PASS

I always get confused about travis, so I'm probably doing something wrong in my development platform, but I cannot see what.

@nasbyj
Copy link
Collaborator

nasbyj commented Nov 23, 2019

Ahh, I understand your confusion then. You're showing the results of running a single test (essentially, what make test does). The Travis suite runs that plus many more tests. With the latest set of results (https://travis-ci.org/theory/pgtap/builds/615528764), by looking at that PGVERSION is set to you can see that your branch is failing on Postgres 9.3-11. Click on the first failure on that page (UPGRADE_TO=9.4 PGVERSION=9.3), and then scroll to the very bottom and you'll see there's 3 tests that are failing. However, that's not the entire story: Line 1044 of the results is this:

Makefile:329: recipe for target 'updatecheck' failed

That means that the failure happened while running make updatecheck. That test works by downloading an old version of pgTap (by default, 0.95.0), installing it, doing ALTER EXTENSION UPDATE, and then running the test suite. This test is designed to catch problems with the upgrade script. This makes me think that the code that you have in pgtap.sql.in is out of sync with what's in pgtap--1.0.0--1.1.0.sql.

All that said, there's a bigger issue: your change will force users to add a cast in col_is_pk(table, column, description) case, which breaks backwards compatibility, which I don't think we can do.

@fluca1978
Copy link
Contributor Author

I'm having quite an hard time in finding resources to work on this.
If someone would like to continue this work, because at the moment I don't know when I will be able to finish it.

@theory
Copy link
Owner

theory commented May 21, 2022

I pushed 8f4a881, an updated variant of #199, and then noticed this PR implementing the same feature, so I added thanks in ff4a30b. Super appreciate your work on this, @fluca1978!

@theory theory closed this May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants