Rename _*_id
columns into just *_id
This commit is contained in:
parent
078355897a
commit
daa224d041
9 changed files with 38 additions and 58 deletions
|
@ -23,7 +23,7 @@ class Address(meta.Base):
|
||||||
)
|
)
|
||||||
latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
||||||
longitude = 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
|
city_name = sa.Column('city', sa.Unicode(length=25), nullable=False) # noqa:WPS432
|
||||||
zip_code = sa.Column(sa.Integer, nullable=False, index=True)
|
zip_code = sa.Column(sa.Integer, nullable=False, index=True)
|
||||||
street = sa.Column(sa.Unicode(length=80), nullable=False) # noqa:WPS432
|
street = sa.Column(sa.Unicode(length=80), nullable=False) # noqa:WPS432
|
||||||
|
@ -58,12 +58,12 @@ class Address(meta.Base):
|
||||||
orders_picked_up = orm.relationship(
|
orders_picked_up = orm.relationship(
|
||||||
'Order',
|
'Order',
|
||||||
back_populates='pickup_address',
|
back_populates='pickup_address',
|
||||||
foreign_keys='[Order._pickup_address_id]',
|
foreign_keys='[Order.pickup_address_id]',
|
||||||
)
|
)
|
||||||
orders_delivered = orm.relationship(
|
orders_delivered = orm.relationship(
|
||||||
'Order',
|
'Order',
|
||||||
back_populates='delivery_address',
|
back_populates='delivery_address',
|
||||||
foreign_keys='[Order._delivery_address_id]',
|
foreign_keys='[Order.delivery_address_id]',
|
||||||
)
|
)
|
||||||
pixels = orm.relationship('AddressPixelAssociation', back_populates='address')
|
pixels = orm.relationship('AddressPixelAssociation', back_populates='address')
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@ class AddressPixelAssociation(meta.Base):
|
||||||
__tablename__ = 'addresses_pixels'
|
__tablename__ = 'addresses_pixels'
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
_address_id = sa.Column('address_id', sa.Integer, primary_key=True)
|
address_id = sa.Column(sa.Integer, primary_key=True)
|
||||||
_city_id = sa.Column('city_id', sa.SmallInteger, nullable=False)
|
city_id = sa.Column(sa.SmallInteger, nullable=False)
|
||||||
_grid_id = sa.Column('grid_id', sa.SmallInteger, nullable=False)
|
grid_id = sa.Column(sa.SmallInteger, nullable=False)
|
||||||
_pixel_id = sa.Column('pixel_id', sa.Integer, primary_key=True)
|
pixel_id = sa.Column(sa.Integer, primary_key=True)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
@ -22,24 +22,12 @@ class City(meta.Base):
|
||||||
kml = sa.Column(sa.UnicodeText, nullable=False)
|
kml = sa.Column(sa.UnicodeText, nullable=False)
|
||||||
|
|
||||||
# Google Maps related columns
|
# Google Maps related columns
|
||||||
_center_latitude = sa.Column(
|
center_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
||||||
'center_latitude', postgresql.DOUBLE_PRECISION, nullable=False,
|
center_longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
||||||
)
|
northeast_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
||||||
_center_longitude = sa.Column(
|
northeast_longitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
||||||
'center_longitude', postgresql.DOUBLE_PRECISION, nullable=False,
|
southwest_latitude = sa.Column(postgresql.DOUBLE_PRECISION, nullable=False)
|
||||||
)
|
southwest_longitude = sa.Column(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,
|
|
||||||
)
|
|
||||||
initial_zoom = sa.Column(sa.SmallInteger, nullable=False)
|
initial_zoom = sa.Column(sa.SmallInteger, nullable=False)
|
||||||
|
|
||||||
# Relationships
|
# Relationships
|
||||||
|
@ -62,9 +50,7 @@ class City(meta.Base):
|
||||||
underlying attributes to calculate the value are to be changed.
|
underlying attributes to calculate the value are to be changed.
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, '_center'): # noqa:WPS421 note:d334120e
|
if not hasattr(self, '_center'): # noqa:WPS421 note:d334120e
|
||||||
self._center = utils.Location(
|
self._center = utils.Location(self.center_latitude, self.center_longitude)
|
||||||
self._center_latitude, self._center_longitude,
|
|
||||||
)
|
|
||||||
return self._center
|
return self._center
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -76,7 +62,7 @@ class City(meta.Base):
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, '_northeast'): # noqa:WPS421 note:d334120e
|
if not hasattr(self, '_northeast'): # noqa:WPS421 note:d334120e
|
||||||
self._northeast = utils.Location(
|
self._northeast = utils.Location(
|
||||||
self._northeast_latitude, self._northeast_longitude,
|
self.northeast_latitude, self.northeast_longitude,
|
||||||
)
|
)
|
||||||
|
|
||||||
return self._northeast
|
return self._northeast
|
||||||
|
@ -90,7 +76,7 @@ class City(meta.Base):
|
||||||
"""
|
"""
|
||||||
if not hasattr(self, '_southwest'): # noqa:WPS421 note:d334120e
|
if not hasattr(self, '_southwest'): # noqa:WPS421 note:d334120e
|
||||||
self._southwest = utils.Location(
|
self._southwest = utils.Location(
|
||||||
self._southwest_latitude, self._southwest_longitude,
|
self.southwest_latitude, self.southwest_longitude,
|
||||||
)
|
)
|
||||||
|
|
||||||
return self._southwest
|
return self._southwest
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Grid(meta.Base):
|
||||||
id = sa.Column( # noqa:WPS125
|
id = sa.Column( # noqa:WPS125
|
||||||
sa.SmallInteger, primary_key=True, autoincrement=True,
|
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)
|
side_length = sa.Column(sa.SmallInteger, nullable=False, unique=True)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Order(meta.Base): # noqa:WPS214
|
||||||
# Generic columns
|
# Generic columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False) # noqa:WPS125
|
id = sa.Column(sa.Integer, primary_key=True, autoincrement=False) # noqa:WPS125
|
||||||
_delivery_id = sa.Column('delivery_id', sa.Integer, index=True, unique=True)
|
_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)
|
placed_at = sa.Column(sa.DateTime, nullable=False, index=True)
|
||||||
ad_hoc = sa.Column(sa.Boolean, nullable=False)
|
ad_hoc = sa.Column(sa.Boolean, nullable=False)
|
||||||
scheduled_delivery_at = sa.Column(sa.DateTime, index=True)
|
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)
|
total = sa.Column(sa.Integer, nullable=False)
|
||||||
|
|
||||||
# Restaurant-related columns
|
# Restaurant-related columns
|
||||||
_restaurant_id = sa.Column(
|
restaurant_id = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
||||||
'restaurant_id', sa.SmallInteger, nullable=False, index=True,
|
|
||||||
)
|
|
||||||
restaurant_notified_at = sa.Column(sa.DateTime)
|
restaurant_notified_at = sa.Column(sa.DateTime)
|
||||||
restaurant_notified_at_corrected = sa.Column(sa.Boolean, index=True)
|
restaurant_notified_at_corrected = sa.Column(sa.Boolean, index=True)
|
||||||
restaurant_confirmed_at = sa.Column(sa.DateTime)
|
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)
|
estimated_prep_buffer = sa.Column(sa.Integer, nullable=False, index=True)
|
||||||
|
|
||||||
# Dispatch-related columns
|
# 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 = sa.Column(sa.DateTime)
|
||||||
dispatch_at_corrected = sa.Column(sa.Boolean, index=True)
|
dispatch_at_corrected = sa.Column(sa.Boolean, index=True)
|
||||||
courier_notified_at = sa.Column(sa.DateTime)
|
courier_notified_at = sa.Column(sa.DateTime)
|
||||||
|
@ -55,9 +53,7 @@ class Order(meta.Base): # noqa:WPS214
|
||||||
utilization = sa.Column(sa.SmallInteger, nullable=False)
|
utilization = sa.Column(sa.SmallInteger, nullable=False)
|
||||||
|
|
||||||
# Pickup-related columns
|
# Pickup-related columns
|
||||||
_pickup_address_id = sa.Column(
|
pickup_address_id = sa.Column(sa.Integer, nullable=False, index=True)
|
||||||
'pickup_address_id', sa.Integer, nullable=False, index=True,
|
|
||||||
)
|
|
||||||
reached_pickup_at = sa.Column(sa.DateTime)
|
reached_pickup_at = sa.Column(sa.DateTime)
|
||||||
pickup_at = sa.Column(sa.DateTime)
|
pickup_at = sa.Column(sa.DateTime)
|
||||||
pickup_at_corrected = sa.Column(sa.Boolean, index=True)
|
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)
|
left_pickup_at_corrected = sa.Column(sa.Boolean, index=True)
|
||||||
|
|
||||||
# Delivery-related columns
|
# Delivery-related columns
|
||||||
_delivery_address_id = sa.Column(
|
delivery_address_id = sa.Column(sa.Integer, nullable=False, index=True)
|
||||||
'delivery_address_id', sa.Integer, nullable=False, index=True,
|
|
||||||
)
|
|
||||||
reached_delivery_at = sa.Column(sa.DateTime)
|
reached_delivery_at = sa.Column(sa.DateTime)
|
||||||
delivery_at = sa.Column(sa.DateTime)
|
delivery_at = sa.Column(sa.DateTime)
|
||||||
delivery_at_corrected = sa.Column(sa.Boolean, index=True)
|
delivery_at_corrected = sa.Column(sa.Boolean, index=True)
|
||||||
|
@ -313,12 +307,12 @@ class Order(meta.Base): # noqa:WPS214
|
||||||
pickup_address = orm.relationship(
|
pickup_address = orm.relationship(
|
||||||
'Address',
|
'Address',
|
||||||
back_populates='orders_picked_up',
|
back_populates='orders_picked_up',
|
||||||
foreign_keys='[Order._pickup_address_id]',
|
foreign_keys='[Order.pickup_address_id]',
|
||||||
)
|
)
|
||||||
delivery_address = orm.relationship(
|
delivery_address = orm.relationship(
|
||||||
'Address',
|
'Address',
|
||||||
back_populates='orders_delivered',
|
back_populates='orders_delivered',
|
||||||
foreign_keys='[Order._delivery_address_id]',
|
foreign_keys='[Order.delivery_address_id]',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Convenience properties
|
# Convenience properties
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Pixel(meta.Base):
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) # noqa:WPS125
|
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_x = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
||||||
n_y = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
n_y = sa.Column(sa.SmallInteger, nullable=False, index=True)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Restaurant(meta.Base):
|
||||||
)
|
)
|
||||||
created_at = sa.Column(sa.DateTime, nullable=False)
|
created_at = sa.Column(sa.DateTime, nullable=False)
|
||||||
name = sa.Column(sa.Unicode(length=45), nullable=False) # noqa:WPS432
|
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)
|
estimated_prep_duration = sa.Column(sa.SmallInteger, nullable=False)
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
|
|
|
@ -12,12 +12,12 @@ def city_data():
|
||||||
'id': 1,
|
'id': 1,
|
||||||
'name': 'Paris',
|
'name': 'Paris',
|
||||||
'kml': "<?xml version='1.0' encoding='UTF-8'?> ...",
|
'kml': "<?xml version='1.0' encoding='UTF-8'?> ...",
|
||||||
'_center_latitude': 48.856614,
|
'center_latitude': 48.856614,
|
||||||
'_center_longitude': 2.3522219,
|
'center_longitude': 2.3522219,
|
||||||
'_northeast_latitude': 48.9021449,
|
'northeast_latitude': 48.9021449,
|
||||||
'_northeast_longitude': 2.4699208,
|
'northeast_longitude': 2.4699208,
|
||||||
'_southwest_latitude': 48.815573,
|
'southwest_latitude': 48.815573,
|
||||||
'_southwest_longitude': 2.225193,
|
'southwest_longitude': 2.225193,
|
||||||
'initial_zoom': 12,
|
'initial_zoom': 12,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ class TestProperties:
|
||||||
result = city.center
|
result = city.center
|
||||||
|
|
||||||
assert isinstance(result, utils.Location)
|
assert isinstance(result, utils.Location)
|
||||||
assert result.latitude == pytest.approx(city_data['_center_latitude'])
|
assert result.latitude == pytest.approx(city_data['center_latitude'])
|
||||||
assert result.longitude == pytest.approx(city_data['_center_longitude'])
|
assert result.longitude == pytest.approx(city_data['center_longitude'])
|
||||||
|
|
||||||
def test_center_is_cached(self, city):
|
def test_center_is_cached(self, city):
|
||||||
"""Test `City.center` property."""
|
"""Test `City.center` property."""
|
||||||
|
@ -59,8 +59,8 @@ class TestProperties:
|
||||||
result = city.northeast
|
result = city.northeast
|
||||||
|
|
||||||
assert isinstance(result, utils.Location)
|
assert isinstance(result, utils.Location)
|
||||||
assert result.latitude == pytest.approx(city_data['_northeast_latitude'])
|
assert result.latitude == pytest.approx(city_data['northeast_latitude'])
|
||||||
assert result.longitude == pytest.approx(city_data['_northeast_longitude'])
|
assert result.longitude == pytest.approx(city_data['northeast_longitude'])
|
||||||
|
|
||||||
def test_northeast_is_cached(self, city):
|
def test_northeast_is_cached(self, city):
|
||||||
"""Test `City.northeast` property."""
|
"""Test `City.northeast` property."""
|
||||||
|
@ -74,8 +74,8 @@ class TestProperties:
|
||||||
result = city.southwest
|
result = city.southwest
|
||||||
|
|
||||||
assert isinstance(result, utils.Location)
|
assert isinstance(result, utils.Location)
|
||||||
assert result.latitude == pytest.approx(city_data['_southwest_latitude'])
|
assert result.latitude == pytest.approx(city_data['southwest_latitude'])
|
||||||
assert result.longitude == pytest.approx(city_data['_southwest_longitude'])
|
assert result.longitude == pytest.approx(city_data['southwest_longitude'])
|
||||||
|
|
||||||
def test_southwest_is_cached(self, city):
|
def test_southwest_is_cached(self, city):
|
||||||
"""Test `City.southwest` property."""
|
"""Test `City.southwest` property."""
|
||||||
|
|
Loading…
Reference in a new issue