vincbeck commented on code in PR #43666:
URL: https://github.com/apache/airflow/pull/43666#discussion_r1831167396


##########
airflow/models/asset.py:
##########
@@ -284,6 +285,46 @@ def for_asset(cls, asset: AssetModel) -> AssetActive:
         return cls(name=asset.name, uri=asset.uri)
 
 
+class TriggerAssetReference(Base):
+    """References from a trigger to an asset of which it is sending updates."""
+
+    trigger_id = Column(Integer, primary_key=True, nullable=False)
+    asset_id = Column(Integer, primary_key=True, nullable=False)
+
+    trigger = relationship("Trigger", back_populates="assets")
+    asset = relationship("AssetModel", back_populates="triggers")
+
+    __tablename__ = "trigger_asset_reference"
+    __table_args__ = (
+        PrimaryKeyConstraint(trigger_id, asset_id),
+        ForeignKeyConstraint(
+            columns=(trigger_id,),
+            refcolumns=["trigger.id"],
+            ondelete="CASCADE",
+        ),
+        ForeignKeyConstraint(
+            (asset_id,),
+            ["asset.id"],
+            ondelete="CASCADE",
+        ),
+    )
+
+    def __eq__(self, other):
+        if isinstance(other, self.__class__):
+            return self.trigger_id == other.trigger_id and self.asset_id == 
other.asset_id
+        else:
+            return NotImplemented

Review Comment:
   Sure



##########
airflow/models/asset.py:
##########
@@ -284,6 +285,46 @@ def for_asset(cls, asset: AssetModel) -> AssetActive:
         return cls(name=asset.name, uri=asset.uri)
 
 
+class TriggerAssetReference(Base):
+    """References from a trigger to an asset of which it is sending updates."""
+
+    trigger_id = Column(Integer, primary_key=True, nullable=False)
+    asset_id = Column(Integer, primary_key=True, nullable=False)
+
+    trigger = relationship("Trigger", back_populates="assets")
+    asset = relationship("AssetModel", back_populates="triggers")
+
+    __tablename__ = "trigger_asset_reference"
+    __table_args__ = (
+        PrimaryKeyConstraint(trigger_id, asset_id),
+        ForeignKeyConstraint(
+            columns=(trigger_id,),
+            refcolumns=["trigger.id"],
+            ondelete="CASCADE",
+        ),
+        ForeignKeyConstraint(
+            (asset_id,),
+            ["asset.id"],
+            ondelete="CASCADE",
+        ),
+    )
+
+    def __eq__(self, other):
+        if isinstance(other, self.__class__):
+            return self.trigger_id == other.trigger_id and self.asset_id == 
other.asset_id
+        else:
+            return NotImplemented
+
+    def __hash__(self):
+        return hash(self.__mapper__.primary_key)
+
+    def __repr__(self):
+        args = []
+        for attr in [x.name for x in self.__mapper__.primary_key]:
+            args.append(f"{attr}={getattr(self, attr)!r}")

Review Comment:
   Sure



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to