Skip to content

Commit

Permalink
Merge branch 'feature-db-changes'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaraphael committed Nov 9, 2023
2 parents 789240b + 34028e0 commit 6e7abf4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
24 changes: 18 additions & 6 deletions alembic/versions/3736e85bc273_add_exposed_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def upgrade() -> None:
OUT cls_long_name text,
OUT aoi_type_1_ids bigint[],
OUT aoi_type_2_ids bigint[],
OUT aoi_type_3_ids bigint[]
OUT aoi_type_3_ids bigint[],
OUT source_type_1_ids bigint[],
OUT source_type_2_ids bigint[]
)
RETURNS SETOF record
LANGUAGE 'sql'
Expand Down Expand Up @@ -99,7 +101,9 @@ def upgrade() -> None:
sp.cls_long_name,
sp.aoi_type_1_ids,
sp.aoi_type_2_ids,
sp.aoi_type_3_ids
sp.aoi_type_3_ids,
sp.source_type_1_ids,
sp.source_type_2_ids
FROM public.slick_plus sp
LEFT JOIN slick_to_source sts ON sts.slick = sp.id AND source_id != 'NULL'
LEFT JOIN slick_to_aoi sta ON sta.slick = sp.id AND aoi_id != 'NULL'
Expand Down Expand Up @@ -137,7 +141,9 @@ def upgrade() -> None:
OUT cls_long_name text,
OUT aoi_type_1_ids bigint[],
OUT aoi_type_2_ids bigint[],
OUT aoi_type_3_ids bigint[]
OUT aoi_type_3_ids bigint[],
OUT source_type_1_ids bigint[],
OUT source_type_2_ids bigint[]
)
RETURNS SETOF record
LANGUAGE 'sql'
Expand Down Expand Up @@ -169,7 +175,9 @@ def upgrade() -> None:
sp.cls_long_name,
sp.aoi_type_1_ids,
sp.aoi_type_2_ids,
sp.aoi_type_3_ids
sp.aoi_type_3_ids,
sp.source_type_1_ids,
sp.source_type_2_ids
FROM public.slick_plus sp
JOIN slick_to_source sts ON sts.slick = sp.id
WHERE sts.source = ANY(string_to_array(source_id, ',')::int[])
Expand Down Expand Up @@ -205,7 +213,9 @@ def upgrade() -> None:
OUT cls_long_name text,
OUT aoi_type_1_ids bigint[],
OUT aoi_type_2_ids bigint[],
OUT aoi_type_3_ids bigint[]
OUT aoi_type_3_ids bigint[],
OUT source_type_1_ids bigint[],
OUT source_type_2_ids bigint[]
)
RETURNS SETOF record
LANGUAGE 'sql'
Expand Down Expand Up @@ -237,7 +247,9 @@ def upgrade() -> None:
sp.cls_long_name,
sp.aoi_type_1_ids,
sp.aoi_type_2_ids,
sp.aoi_type_3_ids
sp.aoi_type_3_ids,
sp.source_type_1_ids,
sp.source_type_2_ids
FROM public.slick_plus sp
JOIN slick_to_aoi sta ON sta.slick = sp.id
WHERE sta.aoi = ANY(string_to_array(aoi_id, ',')::int[]);
Expand Down
14 changes: 11 additions & 3 deletions alembic/versions/39277f6278f4_add_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,28 @@ def upgrade() -> None:
cls.long_name AS cls_long_name,
aoi_agg.aoi_type_1_ids,
aoi_agg.aoi_type_2_ids,
aoi_agg.aoi_type_3_ids
aoi_agg.aoi_type_3_ids,
source_agg.source_type_1_ids,
source_agg.source_type_2_ids
FROM slick
JOIN orchestrator_run ON orchestrator_run.id = slick.orchestrator_run
JOIN sentinel1_grd ON sentinel1_grd.id = orchestrator_run.sentinel1_grd
JOIN cls ON cls.id = slick.cls
JOIN (
LEFT JOIN (
SELECT slick_to_aoi.slick,
array_agg(aoi.id) FILTER (WHERE aoi.type = 1) AS aoi_type_1_ids,
array_agg(aoi.id) FILTER (WHERE aoi.type = 2) AS aoi_type_2_ids,
array_agg(aoi.id) FILTER (WHERE aoi.type = 3) AS aoi_type_3_ids
FROM slick_to_aoi
JOIN aoi ON slick_to_aoi.aoi = aoi.id
GROUP BY slick_to_aoi.slick
) aoi_agg ON aoi_agg.slick = slick.id;
) aoi_agg ON aoi_agg.slick = slick.id
LEFT JOIN ( SELECT slick_to_source.slick,
array_agg(source.id) FILTER (WHERE source.type = 1) AS source_type_1_ids,
array_agg(source.id) FILTER (WHERE source.type = 2) AS source_type_2_ids
FROM slick_to_source
JOIN source ON slick_to_source.source = source.id
GROUP BY slick_to_source.slick) source_agg ON source_agg.slick = slick.id;
""",
)
op.create_entity(slick_plus)
Expand Down
4 changes: 2 additions & 2 deletions alembic/versions/7cd715196b8d_add_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def downgrade() -> None:
op.drop_index("idx_orchestrator_run_git_hash", "orchestrator_run")
op.drop_index("idx_orchestrator_run_sentinel1_grd", "orchestrator_run")

op.drop_index("idx_slick_to_aoi_aoi", "source")
op.drop_index("idx_slick_to_aoi_slick", "source")
op.drop_index("idx_slick_to_aoi_aoi", "slick_to_aoi")
op.drop_index("idx_slick_to_aoi_slick", "slick_to_aoi")

op.drop_index("idx_source_name", "source")

Expand Down

0 comments on commit 6e7abf4

Please sign in to comment.