-
Notifications
You must be signed in to change notification settings - Fork 8.5k
DEV: Support nullable
column property modification
#32978
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
base: main
Are you sure you want to change the base?
Conversation
By default, rails makes timestamp columns (`created_at` and `updated_at`) non-nullable, we also have some required core and plugins columns we wouldn't necessarily want to enforce in the intermediate DB schema. It'll be better to set the default values for these during import instead of enforcing these at the converter level. This change adds support for globally modifying a column’s `nullable` state, defaulting all `created_at` columns to be `nullable` while allowing for table level overrides.
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 this change, and I suppose you assume that more than half of created_at
columns should be nullable. I'm open to that, but we need to ensure that it is required for critical data like users.
@@ -80,7 +80,7 @@ CREATE TABLE users | |||
approved BOOLEAN, | |||
approved_at DATETIME, | |||
approved_by_id NUMERIC, | |||
created_at DATETIME NOT NULL, | |||
created_at DATETIME, |
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 feel like we should require created_at
for users. That's crucial information for users.
@@ -102,6 +102,16 @@ def datatype_for(column) | |||
end | |||
end | |||
|
|||
def nullable_for(column, config) | |||
modified_column = config.dig(:columns, :modify)&.find { |col| col[:name] == column.name } | |||
return modified_column[:nullable] unless modified_column&.dig(:nullable).nil? |
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 simplified
return modified_column[:nullable] unless modified_column&.dig(:nullable).nil? | |
return modified_column[:nullable] if modified_column&.key?(:nullable) |
By default, rails makes timestamp columns (
created_at
andupdated_at
) non-nullable, we also have some required core and plugins columns we wouldn't necessarily want to enforce in the intermediate DB schema. It'll be better to set the default values for these during import instead of enforcing these at the converter level.This change adds support for globally modifying a column’s
nullable
state, defaulting allcreated_at
columns to benullable
while allowing for table level overrides.