Skip to content

Commit

Permalink
Add unique check to v2_manhole.connection_node_id (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw authored Nov 14, 2022
1 parent 0fb79ff commit bcf134a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Changelog of threedi-modelchecker
- Migration to schema version 210 also fixes errors 421, 424, 425, 426, 427 by
replacing negative values with NULL.

- Added a unique check on v2_manhole.connection_node_id.


0.31 (2022-11-02)
-----------------
Expand Down
3 changes: 2 additions & 1 deletion tests/test_checks_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def test_gen_foreign_key_checks():

def test_gen_not_unique_checks():
not_unique_checks = generate_unique_checks(models.Manhole.__table__)
assert len(not_unique_checks) == 1
assert len(not_unique_checks) == 2
assert models.Manhole.id == not_unique_checks[0].column
assert models.Manhole.connection_node_id == not_unique_checks[1].column


def test_gen_not_null_checks():
Expand Down
5 changes: 4 additions & 1 deletion threedi_modelchecker/threedi_model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,10 @@ class Manhole(Base):
calculation_type = Column(IntegerEnum(constants.CalculationTypeNode))

connection_node_id = Column(
Integer, ForeignKey(ConnectionNode.__tablename__ + ".id"), nullable=False
Integer,
ForeignKey(ConnectionNode.__tablename__ + ".id"),
nullable=False,
unique=True,
)
connection_node = relationship(ConnectionNode, back_populates="manholes")

Expand Down

0 comments on commit bcf134a

Please sign in to comment.