-
Notifications
You must be signed in to change notification settings - Fork 354
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
Use native postgres boolean type instead of integers #2116
Conversation
Converted to draft as this PR has issues with backwards compatibility - databases generated before this PR would not be compatible with the contents of this PR. I'll work on allowing both integer and boolean columns to represent booleans in postgres, and users can migrate simply by changing the column type. |
You mean the generated database code, right? I think this is fine as long we keep the dependency constraints between |
No, I mean the actual database - the column type from before this PR would still be Since postgres accepts |
It would be easy for users to migrate though, simply |
Oh right, of course. Given that our support for postgres is still somewhat experimental, I think that shouldn't be a problem either. I think it's better to just do this right now instead of adding (and testing and maintaining) a build option just to get the broken behavior. |
Can you tell me if we are just starting out, can we use your commite right away? Now the application has grown and we need more control on the backend and we don't want to leave Dart for Java. We already had a nice experience with Moor. We want to try it with Postgres as well. And ideally we will join in on the package. I'd like your opinion @simolus3 - why is this still experimental and what might we encounter? |
Yes, this PR is in a working state. You just need to migrate existing databases, both the actual database contents and the generated database file to use it though. I'll reopen it later, as if backwards compatibility isn't a huge concern then there is no reason for this to be kept as a draft. |
After a bit of experimenting, this is the SQL migration query for old integer columns to the new boolean columns: ALTER TABLE tbl_name DROP CONSTRAINT col_constraint, ALTER COLUMN col_name TYPE boolean USING col_name::boolean; Where:
Run that query in a migration for every boolean column in your database, and that's all the migration done. |
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.
I like the idea and the approach! My only concern is the increased code size, but I think we can fix that.
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.
Thank you for your contribution!
@abitofevrything To reduce the size of the generated code, dialects for which we generate code now need to be enabled (in drift 2.11.0). If you only need postgres support, you can use |
Makes it so that databases connected to postgresql will use the
boolean
type for boolean columns, instead of integers mapped to booleans as they are in sqlite.These changes were made to be non-breaking but could use some cleanup in the next major release - mainly changing the
SqlTypes
methods to get the current dialect from somewhere else than an optional positional parameter.Closes #2113