-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proofs): New location fields (#338)
- Loading branch information
Showing
8 changed files
with
188 additions
and
12 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
alembic/versions/20240622_2231_cf78049d89b3_add_proof_location_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Add Proof location fields | ||
Revision ID: cf78049d89b3 | ||
Revises: 49a828f10b05 | ||
Create Date: 2024-06-22 22:31:47.195399 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "cf78049d89b3" | ||
down_revision: Union[str, None] = "49a828f10b05" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"proofs", sa.Column("location_osm_id", sa.BigInteger(), nullable=True) | ||
) | ||
op.add_column( | ||
"proofs", sa.Column("location_osm_type", sa.String(length=255), nullable=True) | ||
) | ||
op.add_column("proofs", sa.Column("location_id", sa.Integer(), nullable=True)) | ||
op.create_foreign_key(None, "proofs", "locations", ["location_id"], ["id"]) | ||
# Set the location to the location of the first price for each proof | ||
op.execute( | ||
""" | ||
UPDATE proofs | ||
SET location_osm_id = ( | ||
SELECT location_osm_id | ||
FROM prices | ||
WHERE prices.proof_id = proofs.id | ||
LIMIT 1 | ||
) | ||
WHERE type IN ('PRICE_TAG', 'RECEIPT') | ||
""" | ||
) | ||
op.execute( | ||
""" | ||
UPDATE proofs | ||
SET location_osm_type = ( | ||
SELECT location_osm_type | ||
FROM prices | ||
WHERE prices.proof_id = proofs.id | ||
LIMIT 1 | ||
) | ||
WHERE type IN ('PRICE_TAG', 'RECEIPT') | ||
""" | ||
) | ||
op.execute( | ||
""" | ||
UPDATE proofs | ||
SET location_id = ( | ||
SELECT location_id | ||
FROM prices | ||
WHERE prices.proof_id = proofs.id | ||
LIMIT 1 | ||
) | ||
WHERE type IN ('PRICE_TAG', 'RECEIPT') | ||
""" | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint(None, "proofs", type_="foreignkey") | ||
op.drop_column("proofs", "location_id") | ||
op.drop_column("proofs", "location_osm_type") | ||
op.drop_column("proofs", "location_osm_id") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters