Skip to content

Commit

Permalink
Canonicalize nat domain foreign keys
Browse files Browse the repository at this point in the history
This in particular relates to setting correct cascades.

Refs #330
  • Loading branch information
lukasjuhrich committed Sep 6, 2023
1 parent 033ec40 commit 64f79a1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pycroft/model/nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ class NATDomain(IntegerIdModel):
name = Column(String, nullable=False)


def nat_domain_fkey():
return ForeignKey(NATDomain.id, ondelete="CASCADE", onupdate="CASCADE")


class DHCPHostReservation(ModelBase):
nat_domain_id = Column(Integer, ForeignKey(NATDomain.id),
nat_domain_id = Column(Integer, nat_domain_fkey(),
primary_key=True, nullable=False)
nat_domain = relationship(NATDomain)

Expand All @@ -30,7 +34,7 @@ class DHCPHostReservation(ModelBase):


class InsideNetwork(ModelBase):
nat_domain_id = Column(Integer, ForeignKey(NATDomain.id),
nat_domain_id = Column(Integer, nat_domain_fkey(),
primary_key=True, nullable=False)
nat_domain = relationship(NATDomain)

Expand All @@ -39,20 +43,20 @@ class InsideNetwork(ModelBase):


class OutsideIPAddress(ModelBase):
nat_domain_id = Column(Integer, ForeignKey(NATDomain.id),
nat_domain_id = Column(Integer, nat_domain_fkey(),
primary_key=True, nullable=False)
nat_domain = relationship(NATDomain)

ip_address = Column(IPAddress, primary_key=True, nullable=False)
owner = Column(Integer)
owner = Column(Integer, ForeignKey(User))

__table_args__ = (
single_ipv4_constraint(col=ip_address),
)


class Translation(ModelBase):
nat_domain_id = Column(Integer, ForeignKey(NATDomain.id),
nat_domain_id = Column(Integer, nat_domain_fkey(),
primary_key=True, nullable=False)
nat_domain = relationship(NATDomain)

Expand All @@ -70,10 +74,9 @@ class Translation(ModelBase):


class Forwarding(ModelBase):
nat_domain_id = Column(Integer, ForeignKey(NATDomain.id, ondelete="CASCADE"),
nat_domain_id = Column(Integer, nat_domain_fkey(),
nullable=False)
nat_domain = relationship(NATDomain, backref=backref("forwardings",
cascade="all, delete-orphan"))
nat_domain = relationship(NATDomain)

outside_address = Column(IPAddress, nullable=False)
outside_port = Column(Integer)
Expand Down

0 comments on commit 64f79a1

Please sign in to comment.