-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
adf186f
to
8427f64
Compare
This is a copy of the method from the postgresql backend with the sequence delete/create/set statements removed. fix cockroachdb#83
8427f64
to
bbff400
Compare
col_type = "integer" if new_type.lower() == "serial" else "bigint" | ||
return ( | ||
( | ||
self.sql_alter_column_type % { |
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.
just a question -- shouldn't the new column also have DEFAULT unique_rowid()
in order to get the desired behavior?
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.
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.
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.
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.
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!
col_type = "integer" if new_type.lower() == "serial" else "bigint" | ||
return ( | ||
( | ||
self.sql_alter_column_type % { |
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.
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.
This is a copy of the method from the postgresql backend with
the sequence delete/create/set statements removed.
fix #83