From daa224d04105daf817cb791783861407b64d8d4e Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Tue, 5 Jan 2021 22:37:12 +0100 Subject: [PATCH] Rename `_*_id` columns into just `*_id` --- src/urban_meal_delivery/db/addresses.py | 6 ++-- .../db/addresses_pixels.py | 8 ++--- src/urban_meal_delivery/db/cities.py | 32 ++++++------------- src/urban_meal_delivery/db/grids.py | 2 +- src/urban_meal_delivery/db/orders.py | 20 ++++-------- src/urban_meal_delivery/db/pixels.py | 2 +- src/urban_meal_delivery/db/restaurants.py | 2 +- tests/db/fake_data/static_fixtures.py | 12 +++---- tests/db/test_cities.py | 12 +++---- 9 files changed, 38 insertions(+), 58 deletions(-) diff --git a/src/urban_meal_delivery/db/addresses.py b/src/urban_meal_delivery/db/addresses.py index 10c07ea..d97b09c 100644 --- a/src/urban_meal_delivery/db/addresses.py +++ b/src/urban_meal_delivery/db/addresses.py @@ -23,7 +23,7 @@ class Address(meta.Base): ) latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False) longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False) - _city_id = sa.Column('city_id', sa.SmallInteger, nullable=False, index=True) + city_id = sa.Column(sa.SmallInteger, nullable=False, index=True) city_name = sa.Column('city', sa.Unicode(length=25), nullable=False) # noqa:WPS432 zip_code = sa.Column(sa.Integer, nullable=False, index=True) street = sa.Column(sa.Unicode(length=80), nullable=False) # noqa:WPS432 @@ -58,12 +58,12 @@ class Address(meta.Base): orders_picked_up = orm.relationship( 'Order', back_populates='pickup_address', - foreign_keys='[Order._pickup_address_id]', + foreign_keys='[Order.pickup_address_id]', ) orders_delivered = orm.relationship( 'Order', back_populates='delivery_address', - foreign_keys='[Order._delivery_address_id]', + foreign_keys='[Order.delivery_address_id]', ) pixels = orm.relationship('AddressPixelAssociation', back_populates='address') diff --git a/src/urban_meal_delivery/db/addresses_pixels.py b/src/urban_meal_delivery/db/addresses_pixels.py index 3ba198f..293bde7 100644 --- a/src/urban_meal_delivery/db/addresses_pixels.py +++ b/src/urban_meal_delivery/db/addresses_pixels.py @@ -19,10 +19,10 @@ class AddressPixelAssociation(meta.Base): __tablename__ = 'addresses_pixels' # Columns - _address_id = sa.Column('address_id', sa.Integer, primary_key=True) - _city_id = sa.Column('city_id', sa.SmallInteger, nullable=False) - _grid_id = sa.Column('grid_id', sa.SmallInteger, nullable=False) - _pixel_id = sa.Column('pixel_id', sa.Integer, primary_key=True) + address_id = sa.Column(sa.Integer, primary_key=True) + city_id = sa.Column(sa.SmallInteger, nullable=False) + grid_id = sa.Column(sa.SmallInteger, nullable=False) + pixel_id = sa.Column(sa.Integer, primary_key=True) # Constraints __table_args__ = ( diff --git a/src/urban_meal_delivery/db/cities.py b/src/urban_meal_delivery/db/cities.py index 20367aa..dea5f5f 100644 --- a/src/urban_meal_delivery/db/cities.py +++ b/src/urban_meal_delivery/db/cities.py @@ -22,24 +22,12 @@ class City(meta.Base): kml = sa.Column(sa.UnicodeText, nullable=False) # Google Maps related columns - _center_latitude = sa.Column( - 'center_latitude', postgresql.DOUBLE_PRECISION, nullable=False, - ) - _center_longitude = sa.Column( - 'center_longitude', postgresql.DOUBLE_PRECISION, nullable=False, - ) - _northeast_latitude = sa.Column( - 'northeast_latitude', postgresql.DOUBLE_PRECISION, nullable=False, - ) - _northeast_longitude = sa.Column( - 'northeast_longitude', postgresql.DOUBLE_PRECISION, nullable=False, - ) - _southwest_latitude = sa.Column( - 'southwest_latitude', postgresql.DOUBLE_PRECISION, nullable=False, - ) - _southwest_longitude = sa.Column( - 'southwest_longitude', postgresql.DOUBLE_PRECISION, nullable=False, - ) + center_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False) + center_longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False) + northeast_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False) + northeast_longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False) + southwest_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False) + southwest_longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False) initial_zoom = sa.Column(sa.SmallInteger, nullable=False) # Relationships @@ -62,9 +50,7 @@ class City(meta.Base): underlying attributes to calculate the value are to be changed. """ if not hasattr(self, '_center'): # noqa:WPS421 note:d334120e - self._center = utils.Location( - self._center_latitude, self._center_longitude, - ) + self._center = utils.Location(self.center_latitude, self.center_longitude) return self._center @property @@ -76,7 +62,7 @@ class City(meta.Base): """ if not hasattr(self, '_northeast'): # noqa:WPS421 note:d334120e self._northeast = utils.Location( - self._northeast_latitude, self._northeast_longitude, + self.northeast_latitude, self.northeast_longitude, ) return self._northeast @@ -90,7 +76,7 @@ class City(meta.Base): """ if not hasattr(self, '_southwest'): # noqa:WPS421 note:d334120e self._southwest = utils.Location( - self._southwest_latitude, self._southwest_longitude, + self.southwest_latitude, self.southwest_longitude, ) return self._southwest diff --git a/src/urban_meal_delivery/db/grids.py b/src/urban_meal_delivery/db/grids.py index 3f7039b..389bd5f 100644 --- a/src/urban_meal_delivery/db/grids.py +++ b/src/urban_meal_delivery/db/grids.py @@ -22,7 +22,7 @@ class Grid(meta.Base): id = sa.Column( # noqa:WPS125 sa.SmallInteger, primary_key=True, autoincrement=True, ) - _city_id = sa.Column('city_id', sa.SmallInteger, nullable=False) + city_id = sa.Column(sa.SmallInteger, nullable=False) side_length = sa.Column(sa.SmallInteger, nullable=False, unique=True) # Constraints diff --git a/src/urban_meal_delivery/db/orders.py b/src/urban_meal_delivery/db/orders.py index d3adcdf..244e4c1 100644 --- a/src/urban_meal_delivery/db/orders.py +++ b/src/urban_meal_delivery/db/orders.py @@ -17,7 +17,7 @@ class Order(meta.Base): # noqa:WPS214 # Generic columns id = sa.Column(sa.Integer, primary_key=True, autoincrement=False) # noqa:WPS125 _delivery_id = sa.Column('delivery_id', sa.Integer, index=True, unique=True) - _customer_id = sa.Column('customer_id', sa.Integer, nullable=False, index=True) + customer_id = sa.Column(sa.Integer, nullable=False, index=True) placed_at = sa.Column(sa.DateTime, nullable=False, index=True) ad_hoc = sa.Column(sa.Boolean, nullable=False) scheduled_delivery_at = sa.Column(sa.DateTime, index=True) @@ -33,9 +33,7 @@ class Order(meta.Base): # noqa:WPS214 total = sa.Column(sa.Integer, nullable=False) # Restaurant-related columns - _restaurant_id = sa.Column( - 'restaurant_id', sa.SmallInteger, nullable=False, index=True, - ) + restaurant_id = sa.Column(sa.SmallInteger, nullable=False, index=True) restaurant_notified_at = sa.Column(sa.DateTime) restaurant_notified_at_corrected = sa.Column(sa.Boolean, index=True) restaurant_confirmed_at = sa.Column(sa.DateTime) @@ -45,7 +43,7 @@ class Order(meta.Base): # noqa:WPS214 estimated_prep_buffer = sa.Column(sa.Integer, nullable=False, index=True) # Dispatch-related columns - _courier_id = sa.Column('courier_id', sa.Integer, index=True) + courier_id = sa.Column(sa.Integer, index=True) dispatch_at = sa.Column(sa.DateTime) dispatch_at_corrected = sa.Column(sa.Boolean, index=True) courier_notified_at = sa.Column(sa.DateTime) @@ -55,9 +53,7 @@ class Order(meta.Base): # noqa:WPS214 utilization = sa.Column(sa.SmallInteger, nullable=False) # Pickup-related columns - _pickup_address_id = sa.Column( - 'pickup_address_id', sa.Integer, nullable=False, index=True, - ) + pickup_address_id = sa.Column(sa.Integer, nullable=False, index=True) reached_pickup_at = sa.Column(sa.DateTime) pickup_at = sa.Column(sa.DateTime) pickup_at_corrected = sa.Column(sa.Boolean, index=True) @@ -66,9 +62,7 @@ class Order(meta.Base): # noqa:WPS214 left_pickup_at_corrected = sa.Column(sa.Boolean, index=True) # Delivery-related columns - _delivery_address_id = sa.Column( - 'delivery_address_id', sa.Integer, nullable=False, index=True, - ) + delivery_address_id = sa.Column(sa.Integer, nullable=False, index=True) reached_delivery_at = sa.Column(sa.DateTime) delivery_at = sa.Column(sa.DateTime) delivery_at_corrected = sa.Column(sa.Boolean, index=True) @@ -313,12 +307,12 @@ class Order(meta.Base): # noqa:WPS214 pickup_address = orm.relationship( 'Address', back_populates='orders_picked_up', - foreign_keys='[Order._pickup_address_id]', + foreign_keys='[Order.pickup_address_id]', ) delivery_address = orm.relationship( 'Address', back_populates='orders_delivered', - foreign_keys='[Order._delivery_address_id]', + foreign_keys='[Order.delivery_address_id]', ) # Convenience properties diff --git a/src/urban_meal_delivery/db/pixels.py b/src/urban_meal_delivery/db/pixels.py index 6d28227..5b3f4f3 100644 --- a/src/urban_meal_delivery/db/pixels.py +++ b/src/urban_meal_delivery/db/pixels.py @@ -19,7 +19,7 @@ class Pixel(meta.Base): # Columns id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) # noqa:WPS125 - _grid_id = sa.Column('grid_id', sa.SmallInteger, nullable=False, index=True) + grid_id = sa.Column(sa.SmallInteger, nullable=False, index=True) n_x = sa.Column(sa.SmallInteger, nullable=False, index=True) n_y = sa.Column(sa.SmallInteger, nullable=False, index=True) diff --git a/src/urban_meal_delivery/db/restaurants.py b/src/urban_meal_delivery/db/restaurants.py index 1319b56..d427540 100644 --- a/src/urban_meal_delivery/db/restaurants.py +++ b/src/urban_meal_delivery/db/restaurants.py @@ -22,7 +22,7 @@ class Restaurant(meta.Base): ) created_at = sa.Column(sa.DateTime, nullable=False) name = sa.Column(sa.Unicode(length=45), nullable=False) # noqa:WPS432 - _address_id = sa.Column('address_id', sa.Integer, nullable=False, index=True) + address_id = sa.Column(sa.Integer, nullable=False, index=True) estimated_prep_duration = sa.Column(sa.SmallInteger, nullable=False) # Constraints diff --git a/tests/db/fake_data/static_fixtures.py b/tests/db/fake_data/static_fixtures.py index ee6682d..6a386de 100644 --- a/tests/db/fake_data/static_fixtures.py +++ b/tests/db/fake_data/static_fixtures.py @@ -12,12 +12,12 @@ def city_data(): 'id': 1, 'name': 'Paris', 'kml': " ...", - '_center_latitude': 48.856614, - '_center_longitude': 2.3522219, - '_northeast_latitude': 48.9021449, - '_northeast_longitude': 2.4699208, - '_southwest_latitude': 48.815573, - '_southwest_longitude': 2.225193, + 'center_latitude': 48.856614, + 'center_longitude': 2.3522219, + 'northeast_latitude': 48.9021449, + 'northeast_longitude': 2.4699208, + 'southwest_latitude': 48.815573, + 'southwest_longitude': 2.225193, 'initial_zoom': 12, } diff --git a/tests/db/test_cities.py b/tests/db/test_cities.py index d3ae5af..73a0cdb 100644 --- a/tests/db/test_cities.py +++ b/tests/db/test_cities.py @@ -44,8 +44,8 @@ class TestProperties: result = city.center assert isinstance(result, utils.Location) - assert result.latitude == pytest.approx(city_data['_center_latitude']) - assert result.longitude == pytest.approx(city_data['_center_longitude']) + assert result.latitude == pytest.approx(city_data['center_latitude']) + assert result.longitude == pytest.approx(city_data['center_longitude']) def test_center_is_cached(self, city): """Test `City.center` property.""" @@ -59,8 +59,8 @@ class TestProperties: result = city.northeast assert isinstance(result, utils.Location) - assert result.latitude == pytest.approx(city_data['_northeast_latitude']) - assert result.longitude == pytest.approx(city_data['_northeast_longitude']) + assert result.latitude == pytest.approx(city_data['northeast_latitude']) + assert result.longitude == pytest.approx(city_data['northeast_longitude']) def test_northeast_is_cached(self, city): """Test `City.northeast` property.""" @@ -74,8 +74,8 @@ class TestProperties: result = city.southwest assert isinstance(result, utils.Location) - assert result.latitude == pytest.approx(city_data['_southwest_latitude']) - assert result.longitude == pytest.approx(city_data['_southwest_longitude']) + assert result.latitude == pytest.approx(city_data['southwest_latitude']) + assert result.longitude == pytest.approx(city_data['southwest_longitude']) def test_southwest_is_cached(self, city): """Test `City.southwest` property."""