`Session.query()` is the legacy API in SQLAlchemy 2.x.
The addresses with restaurants are now selected with a subquery in one statement.
The `_restaurants_mock` fixture mocks the new call chain.
`Session.query()` is the legacy API in SQLAlchemy 2.x.
Unlike `Query`, `select()` does not deduplicate single entities from a `JOIN`;
so, `Grid.gridify()` calls `.unique()` explicitly.
The `addresses_mock` fixtures mock the new call chain.
The migrations create foreign keys from the `CLEAN_SCHEMA`
into the `ORIGINAL_SCHEMA` to ensure the cleaned data still
refer to the original data.
The ORM models do not know the original tables.
Also, print the `diff` as indented JSON.
Before version 14, PostgreSQL stored `EXTRACT(...)` as `date_part(...)`,
and the rendering of `IN (...)` changed as well.
The checks created in 2021 express the same rules as the ORM models
but render differently. See the docstring of the migration for details.
Earlier migrations named some constraints without `op.f()`,
a column rename did not rename the unique constraint containing the column,
and the "ordered_timestamps_N" checks in "orders" were shifted by one
compared to the ORM.
See the docstring of the migration for details.
`ReplaySimulation`, `ReplayedOrder`, and `Forecast` accessed
relationships in their `.__repr__()`, which emits queries
or fails for detached instances.
They now use the foreign key columns.
The ORM always defined `Grid.side_length` with `nullable=False`,
but the migration that created the "grids" table did not; the
live database contains no `NULL`s.
The "Revision" and "Revises" lines and the revision hashes in `upgrade()`
and `downgrade()` repeated the `revision` and `down_revision` variables;
the creation date is in the file name.
The `unique=True` on `Grid.side_length`
made the side length unique across all cities.
The intended rule is the `UniqueConstraint("city_id", "side_length")`,
which the migrations already implement; so, no migration is needed.
The new "verify-db-objects" session creates the ORM objects
with `.create_all()` in a temporary database and compares
them with the `CLEAN_SCHEMA` of a "live" database using `sqlalchemy-diff`