Add Grid.gridify() constructor

- the purpose of this constructor method is to generate all `Pixel`s
  for a `Grid` that have at least one `Address` assigned to them
- fix missing `UniqueConstraint` in `Grid` class => it was not possible
  to create two `Grid`s with the same `.side_length` in different cities
- change the `City.viewport` property into two separate `City.southwest`
  and `City.northeast` properties; also add `City.total_x` and
  `City.total_y` properties for convenience
This commit is contained in:
Alexander Hess 2021-01-05 18:58:48 +01:00
commit 776112d609
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
10 changed files with 224 additions and 57 deletions

View file

@ -36,7 +36,11 @@ def upgrade():
onupdate='RESTRICT',
ondelete='RESTRICT',
),
sa.UniqueConstraint('side_length', name=op.f('uq_grids_on_side_length')),
sa.UniqueConstraint(
'city_id', 'side_length', name=op.f('uq_grids_on_city_id_side_length'),
),
# This `UniqueConstraint` is needed by the `addresses_pixels` table below.
sa.UniqueConstraint('id', 'city_id', name=op.f('uq_grids_on_id_city_id')),
schema=config.CLEAN_SCHEMA,
)
@ -85,19 +89,13 @@ def upgrade():
schema=config.CLEAN_SCHEMA,
)
# These `UniqueConstraints`s are needed by the `addresses_pixels` table below.
# This `UniqueConstraint` is needed by the `addresses_pixels` table below.
op.create_unique_constraint(
'uq_addresses_on_id_city_id',
'addresses',
['id', 'city_id'],
schema=config.CLEAN_SCHEMA,
)
op.create_unique_constraint(
'uq_grids_on_id_city_id',
'grids',
['id', 'city_id'],
schema=config.CLEAN_SCHEMA,
)
op.create_table(
'addresses_pixels',