From db1e6955a6d9030a2ecb7a27c8b90d26f483da4f Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Fri, 22 Nov 2024 11:05:17 -0700 Subject: [PATCH] CASCADE on delete --- buildingmotif/database/tables.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/buildingmotif/database/tables.py b/buildingmotif/database/tables.py index 6d442d12..2b6fc523 100644 --- a/buildingmotif/database/tables.py +++ b/buildingmotif/database/tables.py @@ -26,7 +26,7 @@ class DBModel(Base): description: Mapped[str] = Column(Text(), default="", nullable=False) graph_id: Mapped[str] = Column(String()) manifest_id: Mapped[int] = Column( - Integer, ForeignKey("shape_collection.id"), nullable=False + Integer, ForeignKey("shape_collection.id", ondelete="CASCADE"), nullable=False ) manifest: "DBShapeCollection" = relationship( "DBShapeCollection", @@ -57,7 +57,7 @@ class DBLibrary(Base): ) shape_collection_id = Column( - Integer, ForeignKey("shape_collection.id"), nullable=False + Integer, ForeignKey("shape_collection.id", ondelete="CASCADE"), nullable=False ) shape_collection: DBShapeCollection = relationship( "DBShapeCollection", @@ -72,8 +72,8 @@ class DepsAssociation(Base): __tablename__ = "deps_association_table" id: Mapped[int] = Column(Integer, primary_key=True) - dependant_id: Mapped[int] = Column(ForeignKey("template.id")) - dependee_id: Mapped[int] = Column(ForeignKey("template.id")) + dependant_id: Mapped[int] = Column(ForeignKey("template.id", ondelete="CASCADE")) + dependee_id: Mapped[int] = Column(ForeignKey("template.id", ondelete="CASCADE")) # args are a mapping of dependee args to dependant args args: Mapped[Dict[str, str]] = Column(JSONType) # type: ignore @@ -97,7 +97,7 @@ class DBTemplate(Base): body_id: Mapped[str] = Column(String()) optional_args: Mapped[List[str]] = Column(JSONType) # type: ignore - library_id: Mapped[int] = Column(Integer, ForeignKey("library.id"), nullable=False) + library_id: Mapped[int] = Column(Integer, ForeignKey("library.id", ondelete="CASCADE"), nullable=False) library: Mapped[DBLibrary] = relationship("DBLibrary", back_populates="templates") dependencies: Mapped[List["DBTemplate"]] = relationship( "DBTemplate",