Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

s3lase
Copy link
Contributor

@s3lase s3lase commented May 28, 2025

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.

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.
@s3lase s3lase requested a review from a team as a code owner May 28, 2025 17:45
@github-actions github-actions bot added the migrations-tooling PR which includes changes to migrations tooling label May 28, 2025
@s3lase s3lase requested a review from gschlager May 28, 2025 18:40
Copy link
Member

@gschlager gschlager left a 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,
Copy link
Member

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?
Copy link
Member

Choose a reason for hiding this comment

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

It could be simplified

Suggested change
return modified_column[:nullable] unless modified_column&.dig(:nullable).nil?
return modified_column[:nullable] if modified_column&.key?(:nullable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migrations-tooling PR which includes changes to migrations tooling
Development

Successfully merging this pull request may close these issues.

2 participants