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

schema: remove sequence management for serial fields #98

Merged
merged 1 commit into from
Nov 26, 2019

Conversation

timgraham
Copy link
Collaborator

This is a copy of the method from the postgresql backend with
the sequence delete/create/set statements removed.

fix #83

@timgraham timgraham force-pushed the no-sequence-change branch 3 times, most recently from adf186f to 8427f64 Compare November 19, 2019 18:44
This is a copy of the method from the postgresql backend with
the sequence delete/create/set statements removed.

fix cockroachdb#83
col_type = "integer" if new_type.lower() == "serial" else "bigint"
return (
(
self.sql_alter_column_type % {
Copy link
Contributor

Choose a reason for hiding this comment

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

just a question -- shouldn't the new column also have DEFAULT unique_rowid() in order to get the desired behavior?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The test where I saw an error is this one which changes AutoField to BigAutoField: https://github.com/django/django/blob/7552de7866dcd270a0f353b007b4aceaa7f3ff3e/tests/schema/tests.py#L659-L676
I verified that the primary keys at the end of the migration are randomly generated. I also tested the reverse (BigAutoField to AutoField) and the IDs are as expected. I'm not sure about the inner workings of cockraockdb but maybe the default expression isn't affected by the ALTER statement?

Incidentally, only AutoField has DEFAULT unique_rowid() right now:

AutoField='DEFAULT unique_rowid()',

AutoField='integer',

However, I removed those lines and behavior remains the same... without them, Django uses serial, so I guess cockroachdb treats serial equivalent to integer DEFAULT unique_rowid().

BigAutoField uses bigserial from PostgreSQL but perhaps it should be made more explicit like AutoField. The docs say, "SERIAL is provided only for compatibility with PostgreSQL. New applications should use real data types and a suitable DEFAULT expression".

smallserial also uses unique_rowid() which seems broken as described in #84.

Copy link
Contributor

@rafiss rafiss Nov 26, 2019

Choose a reason for hiding this comment

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

so I guess cockroachdb treats serial equivalent to integer DEFAULT unique_rowid()

Yeah that is correct. So altering to a SERIAL type should be OK.

Copy link
Contributor

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

lgtm!

col_type = "integer" if new_type.lower() == "serial" else "bigint"
return (
(
self.sql_alter_column_type % {
Copy link
Contributor

@rafiss rafiss Nov 26, 2019

Choose a reason for hiding this comment

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

so I guess cockroachdb treats serial equivalent to integer DEFAULT unique_rowid()

Yeah that is correct. So altering to a SERIAL type should be OK.

@timgraham timgraham merged commit 2a67782 into cockroachdb:master Nov 26, 2019
@timgraham timgraham deleted the no-sequence-change branch November 26, 2019 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unsupported query: ALTER SEQUENCE ... OWNED BY ...
2 participants