From 8a96e785338ee88d366a5c3658842136a45adcd1 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Fri, 4 Dec 2026 13:05:04 +0100 Subject: [PATCH] Explain the "why" All foreign keys use `RESTRICT`, so cascades can never change the data of finished stages. --- src/velofy/db/addresses.py | 2 ++ src/velofy/db/addresses_addresses.py | 3 +++ src/velofy/db/addresses_pixels.py | 3 +++ src/velofy/db/forecasts.py | 2 ++ src/velofy/db/grids.py | 2 ++ src/velofy/db/orders.py | 2 ++ src/velofy/db/pixels.py | 2 ++ src/velofy/db/replay/orders.py | 2 ++ src/velofy/db/replay/simulations.py | 2 ++ src/velofy/db/restaurants.py | 2 ++ 10 files changed, 22 insertions(+) diff --git a/src/velofy/db/addresses.py b/src/velofy/db/addresses.py index 2c26fe8..adbef87 100644 --- a/src/velofy/db/addresses.py +++ b/src/velofy/db/addresses.py @@ -76,6 +76,8 @@ class Address(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades sa.ForeignKeyConstraint( ["primary_id"], ["addresses.id"], diff --git a/src/velofy/db/addresses_addresses.py b/src/velofy/db/addresses_addresses.py index c85cee9..aa4b38b 100644 --- a/src/velofy/db/addresses_addresses.py +++ b/src/velofy/db/addresses_addresses.py @@ -71,6 +71,9 @@ class Path(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades + # # The two `Address` objects must be in the same `.city` sa.ForeignKeyConstraint( ["first_address_id", "city_id"], diff --git a/src/velofy/db/addresses_pixels.py b/src/velofy/db/addresses_pixels.py index d613766..443e044 100644 --- a/src/velofy/db/addresses_pixels.py +++ b/src/velofy/db/addresses_pixels.py @@ -39,6 +39,9 @@ class AddressPixelAssociation(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades + # # An `Address` can only be on a `Grid` ... sa.ForeignKeyConstraint( ["address_id", "city_id"], diff --git a/src/velofy/db/forecasts.py b/src/velofy/db/forecasts.py index cdd0490..4b1d733 100644 --- a/src/velofy/db/forecasts.py +++ b/src/velofy/db/forecasts.py @@ -82,6 +82,8 @@ class Forecast(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades sa.ForeignKeyConstraint( ["pixel_id"], ["pixels.id"], diff --git a/src/velofy/db/grids.py b/src/velofy/db/grids.py index d9887c9..71bafbf 100644 --- a/src/velofy/db/grids.py +++ b/src/velofy/db/grids.py @@ -36,6 +36,8 @@ class Grid(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades sa.ForeignKeyConstraint( ["city_id"], ["cities.id"], diff --git a/src/velofy/db/orders.py b/src/velofy/db/orders.py index 74ed01d..0adfa21 100644 --- a/src/velofy/db/orders.py +++ b/src/velofy/db/orders.py @@ -243,6 +243,8 @@ class Order(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades sa.ForeignKeyConstraint( ["customer_id"], ["customers.id"], diff --git a/src/velofy/db/pixels.py b/src/velofy/db/pixels.py index b8ce6e7..1d43308 100644 --- a/src/velofy/db/pixels.py +++ b/src/velofy/db/pixels.py @@ -49,6 +49,8 @@ class Pixel(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades sa.ForeignKeyConstraint( ["grid_id"], ["grids.id"], diff --git a/src/velofy/db/replay/orders.py b/src/velofy/db/replay/orders.py index a0656d8..9b50715 100644 --- a/src/velofy/db/replay/orders.py +++ b/src/velofy/db/replay/orders.py @@ -118,6 +118,8 @@ class ReplayedOrder(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades sa.ForeignKeyConstraint( ["simulation_id"], ["replay_simulations.id"], diff --git a/src/velofy/db/replay/simulations.py b/src/velofy/db/replay/simulations.py index 9ccf0c9..76397bb 100644 --- a/src/velofy/db/replay/simulations.py +++ b/src/velofy/db/replay/simulations.py @@ -39,6 +39,8 @@ class ReplaySimulation(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades sa.ForeignKeyConstraint( ["city_id"], ["cities.id"], diff --git a/src/velofy/db/restaurants.py b/src/velofy/db/restaurants.py index 6fcf792..fe66087 100644 --- a/src/velofy/db/restaurants.py +++ b/src/velofy/db/restaurants.py @@ -48,6 +48,8 @@ class Restaurant(meta.Base): # Constraints __table_args__ = ( + # All foreign keys `RESTRICT` + # because data of finished stages must never change through cascades sa.ForeignKeyConstraint( ["address_id"], ["addresses.id"],