-
Notifications
You must be signed in to change notification settings - Fork 52
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
fix(schema_statements): add unique_rowid to pk_and_sequence_for #311
Conversation
# First try looking for a sequence with a dependency on the | ||
# given table's primary key. | ||
result = query(<<~SQL, "SCHEMA")[0] | ||
SELECT attr.attname, nsp.nspname, seq.relname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafiss does this query make sense for CRDB ? All the tests I'm working with until now are giving a void result...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this looks correct
if you are getting no results, it's probably because CRDB defaults to not using sequences for SERIAL types. this can be changed with the serial_normalization setting: https://www.cockroachlabs.com/docs/stable/serial#modes-of-operation
dd54d68
to
c6e953e
Compare
c6e953e
to
e8431c4
Compare
Somehow the test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gives the error:
user root does not have DELETE privilege on relation pg_depend
The bug is not related to the code, but just to the tests. @rafiss could we give a user this privilege ? I didn't see it skimming the doc... (show grants gives f for is_grantable on pg_depend...):
Unfortunately, pg_depend is view-only in CRDB, unlike PG. In CRDB there is no way to "artificially break" the dependency that the sequence has on the table.
# First try looking for a sequence with a dependency on the | ||
# given table's primary key. | ||
result = query(<<~SQL, "SCHEMA")[0] | ||
SELECT attr.attname, nsp.nspname, seq.relname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this looks correct
if you are getting no results, it's probably because CRDB defaults to not using sequences for SERIAL types. this can be changed with the serial_normalization setting: https://www.cockroachlabs.com/docs/stable/serial#modes-of-operation
Allow to get the primary key in the default case.
e8431c4
to
5139382
Compare
About
This line is the one that is failing us... |
@@ -68,14 +68,19 @@ def pk_and_sequence_for(table) # :nodoc: | |||
pg_attribute attr, | |||
pg_depend dep, | |||
pg_constraint cons, | |||
pg_namespace nsp | |||
pg_namespace nsp, | |||
-- TODO: use the pg_catalog.pg_attribute(attishidden) column when it's added instead of joining on crdb_internal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it could be useful to link to cockroachdb/cockroach#126397 in the TODO, so we can easily see when the new column is in a CRDB release.
8ca8157
to
dd6b1a0
Compare
dd6b1a0
to
dd4d16b
Compare
It should be good for merging now! I think I'll work on the transaction related issues next, and then we'll almost be done with those red tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Allow to get the primary key in the default case.
This fixes two of the four failing
test_pk_and_sequence_for*
. The two still failing are:test_pk_and_sequence_for_returns_nil_if_no_pk
the example table creation query:
The second query of
#pk_and_sequence_for
returns["rowid", "public", nil]
. And theSHOW CREATE TABLE ex
confirms it:test_pk_and_sequence_for_with_collision_pg_class_oid
Gives the error:
The bug is not related to the code, but just to the tests. @rafiss could we give a user this privilege ? I didn't see it skimming the doc... (
show grants
givesf
foris_grantable
onpg_depend
...):On meta-testing. This took me longer than expected. I'm a bit unsure about the return on investment for simple tests, as manipulating AST can feel a bit tricky. I still pursued it because it seems that the gems (parser and unparser) are quite stable, and if we could use this not only in tests, that would be tremendous. We would need more guaranties though. And we'd need to verify the performances..
I was thinking about checking the hash of the method to be changed against a saved hash (which would be stored in an argument). If there is a change we warn. So:
I think this is the way to go, but there are definitely some tweaks to make it easier.