-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix river basin names and improve errors in hierarchy (#98)
Co-authored-by: @20cents @JulienCorny @edelclaux
- Loading branch information
1 parent
13955a4
commit 44677c1
Showing
21 changed files
with
269 additions
and
151 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
backend/gn_module_zh/migrations/58ab8aba8512_add_main_id_rb_column.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,38 @@ | ||
"""add_main_id_rb_column | ||
Revision ID: 58ab8aba8512 | ||
Revises: 76e89c793961 | ||
Create Date: 2024-09-11 15:14:12.546662 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy import Column, Integer | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "58ab8aba8512" | ||
down_revision = "76e89c793961" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.add_column( | ||
schema="pr_zh", | ||
table_name="t_zh", | ||
column=Column( | ||
"main_id_rb", | ||
Integer, | ||
nullable=True, | ||
), | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column( | ||
schema="pr_zh", | ||
table_name="t_zh", | ||
column_name="main_id_rb", | ||
) |
51 changes: 51 additions & 0 deletions
51
backend/gn_module_zh/migrations/72a8378567pa_update_main_id_rb.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,51 @@ | ||
"""update_main_id_rb | ||
Revision ID: 72a8378567pa | ||
Revises: 58ab8aba8512 | ||
Create Date: 2024-09-11 17:18:21.165324 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "72a8378567pa" | ||
down_revision = "58ab8aba8512" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.execute( | ||
""" | ||
UPDATE pr_zh.t_zh tzh | ||
SET main_id_rb = | ||
( | ||
SELECT id_rb | ||
FROM ( | ||
SELECT | ||
czr.id_rb AS id_rb, | ||
ST_Area(ST_Intersection( | ||
ST_GeomFromText(ST_AsText((SELECT geom FROM pr_zh.t_zh WHERE id_zh = tzh.id_zh ))), | ||
ST_GeomFromText(ST_AsText(trb.geom)) | ||
)) AS areas | ||
FROM pr_zh.cor_zh_rb czr | ||
LEFT JOIN pr_zh.t_river_basin trb ON trb.id_rb = czr.id_rb | ||
WHERE czr.id_zh = tzh.id_zh | ||
ORDER BY areas DESC | ||
LIMIT 1 | ||
) AS a | ||
) | ||
""" | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.execute( | ||
""" | ||
UPDATE pr_zh.t_zh tzh | ||
SET main_id_rb = null | ||
""" | ||
) |
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
Oops, something went wrong.