Skip to content

Commit

Permalink
alias warehouse names for columns (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndamania00 authored Dec 10, 2024
1 parent 3d7a366 commit bf81a65
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
19 changes: 17 additions & 2 deletions docs/reference/entity-schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ All Liminal entity schema classes must inherit from one of the mixins in the [mi

> The mixture schema configuration for the entity schema. Must be defined as a [MixtureSchemaConfig](https://github.com/dynotx/liminal-orm/blob/main/liminal/base/properties/base_schema_properties.py) object.
**_archived: bool | None = None**

> Private attribute used to set the archived status of the schema.
!!! tip
When schemas (and fields) are archived, they still existing the Benchling warehouse. Using _archived is useful when you need to access archived data.

## Column: [class](https://github.com/dynotx/liminal-orm/blob/main/liminal/orm/column.py)

!!! warning
Expand Down Expand Up @@ -135,6 +142,10 @@ All Liminal entity schema classes must inherit from one of the mixins in the [mi

> Whether the field is a parent link field. Defaults to False.
**tooltip: str | None = None**

> The tooltip for the field. Defaults to None.
**dropdown: Type[BaseDropdown] | None = None**

> The dropdown object for the field. The dropdown object must inherit from BaseDropdown and the type of the Column must be `BenchlingFieldType.DROPDOWN`. Defaults to None.
Expand All @@ -143,9 +154,13 @@ All Liminal entity schema classes must inherit from one of the mixins in the [mi

> The entity link for the field. The entity link must be the `warehouse_name` as a string of the entity schema that the field is linking to. The type of the Column must be `BenchlingFieldType.ENTITY_LINK` in order to be valid. Defaults to None.
**tooltip: str | None = None**
**_archived: bool = False**

> The tooltip for the field. Defaults to None.
> Private attribute used to set the archived status of the column. Useful when you need to access archived data and want to define archived fields.
**_warehouse_name: str | None = None**

> Private attribute used to set the warehouse name of the column. This is useful when the variable name is not the same as the warehouse name.
## Relationships: [module](https://github.com/dynotx/liminal-orm/blob/main/liminal/orm/relationship.py)

Expand Down
11 changes: 9 additions & 2 deletions liminal/orm/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ class Column(SqlColumn):
Whether the field is a multi-value field.
parent_link : bool = False
Whether the entity link field is a parent of the entity schema.
tooltip : str | None = None
The tooltip text for the field.
dropdown : Type[BaseDropdown] | None = None
The dropdown for the field.
entity_link : str | None = None
The warehouse name of the entity the field links to.
tooltip : str | None = None
The tooltip text for the field.
_warehouse_name : str | None = None
The warehouse name of the column. Necessary when the variable name is not the same as the warehouse name.
_archived : bool = False
Whether the field is archived.
"""

def __init__(
Expand All @@ -44,6 +48,7 @@ def __init__(
tooltip: str | None = None,
dropdown: Type[BaseDropdown] | None = None, # noqa: UP006
entity_link: str | None = None,
_warehouse_name: str | None = None,
_archived: bool = False,
**kwargs: Any,
):
Expand Down Expand Up @@ -82,6 +87,8 @@ def __init__(
foreign_key = None
if type == BenchlingFieldType.ENTITY_LINK and entity_link:
foreign_key = ForeignKey(f"{entity_link}$raw.id")
if _warehouse_name:
kwargs["name"] = _warehouse_name
super().__init__(
self.sqlalchemy_type,
foreign_key,
Expand Down
32 changes: 32 additions & 0 deletions liminal/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,24 @@ def mock_benchling_schema(
tooltip=None,
_archived=False,
),
"archived_field": Props(
name="Archived Field",
type=Type.TEXT,
required=False,
is_multi=False,
_archived=True,
),
"wh_name_field_different": Props(
name="Different Wh Name Field",
type=Type.TEXT,
required=False,
is_multi=False,
parent_link=False,
dropdown_link=None,
entity_link=None,
tooltip=None,
_archived=False,
),
}
return [(schema_props, fields)]

Expand Down Expand Up @@ -369,6 +387,20 @@ class MockEntity(BaseModel):
is_multi=True,
dropdown=mock_benchling_dropdown,
)
archived_field: SqlColumn = Column(
name="Archived Field",
type=Type.TEXT,
required=False,
is_multi=False,
_archived=True,
)
different_wh_name_field: SqlColumn = Column(
name="Different Wh Name Field",
type=Type.TEXT,
required=False,
is_multi=False,
_warehouse_name="wh_name_field_different",
)

def __init__(
self,
Expand Down
11 changes: 11 additions & 0 deletions liminal/tests/test_entity_schema_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,14 @@ def test_compare_benchling_schema_fields( # type: ignore[no-untyped-def]
assert isinstance(
invalid_models["mock_entity"][0].op, ReorderEntitySchemaFields
)

# Test when the Benchling schema archived field becomes unarchived
benchling_rearchived_field = copy.deepcopy(mock_benchling_schema)
benchling_rearchived_field[0][1]["archived_field"].set_archived(False)
mock_get_benchling_entity_schemas.return_value = benchling_rearchived_field
invalid_models = compare_entity_schemas(mock_benchling_sdk)
assert len(invalid_models["mock_entity"]) == 1
assert isinstance(
invalid_models["mock_entity"][0].op, ArchiveEntitySchemaField
)
assert invalid_models["mock_entity"][0].op.wh_field_name == "archived_field"

0 comments on commit bf81a65

Please sign in to comment.