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

DM-43753: Make columns nullable by default in the data model #58

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 2 additions & 7 deletions python/felis/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,8 @@ class Column(BaseObject):
length: int | None = None
"""The length of the column."""

nullable: bool | None = None
"""Whether the column can be ``NULL``.

If `None`, this value was not set explicitly in the YAML data. In this
case, it will be set to `False` for columns with numeric types and `True`
otherwise.
"""
nullable: bool = True
"""Whether the column can be ``NULL``."""

value: Any = None
"""The default value of the column."""
Expand Down
12 changes: 3 additions & 9 deletions python/felis/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
ForeignKeyConstraint,
Index,
MetaData,
Numeric,
PrimaryKeyConstraint,
ResultProxy,
Table,
Expand Down Expand Up @@ -265,17 +264,12 @@ def build_column(self, column_obj: datamodel.Column) -> Column:
id = column_obj.id
description = column_obj.description
default = column_obj.value
nullable = column_obj.nullable

# Handle variant overrides for the column (e.g., "mysql:datatype").
# Get datatype, handling variant overrides such as "mysql:datatype".
datatype = get_datatype_with_variants(column_obj)

# Set default value of nullable based on column type and then whether
# it was explicitly provided in the schema data.
nullable = column_obj.nullable
if nullable is None:
nullable = False if isinstance(datatype, Numeric) else True

# Set autoincrement depending on if it was provided explicitly.
# Set autoincrement, depending on if it was provided explicitly.
autoincrement: Literal["auto"] | bool = (
column_obj.autoincrement if column_obj.autoincrement is not None else "auto"
)
Expand Down