Skip to content

Commit e98039e

Browse files
committed
refactor(bootstrapper): remove VEDA logic (#29)
* remove injected VEDA funcs * flake8 BREAKING CHANGE: remove dashboard schema and functions from the database bootstrapper and remove automatic collection summary udpate from ingestor.
1 parent 4ef537c commit e98039e

File tree

3 files changed

+0
-111
lines changed

3 files changed

+0
-111
lines changed

lib/bootstrapper/runtime/handler.py

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -134,77 +134,6 @@ def register_extensions(cursor) -> None:
134134
cursor.execute(sql.SQL("CREATE EXTENSION IF NOT EXISTS postgis;"))
135135

136136

137-
def create_dashboard_schema(cursor, username: str) -> None:
138-
"""Create custom schema for dashboard-specific functions."""
139-
cursor.execute(
140-
sql.SQL(
141-
"CREATE SCHEMA IF NOT EXISTS dashboard;"
142-
"GRANT ALL ON SCHEMA dashboard TO {username};"
143-
"ALTER ROLE {username} SET SEARCH_PATH TO dashboard, pgstac, public;"
144-
).format(username=sql.Identifier(username))
145-
)
146-
147-
148-
def create_update_default_summaries_function(cursor) -> None:
149-
"""Create function to update collection summary metadata about default item assets."""
150-
151-
update_default_summary_sql = """
152-
CREATE OR REPLACE FUNCTION dashboard.update_default_summaries(_collection_id text) RETURNS VOID AS $$
153-
WITH coll_item_cte AS (
154-
SELECT jsonb_build_object(
155-
'summaries',
156-
jsonb_build_object(
157-
'datetime', (
158-
CASE
159-
WHEN (collections."content"->>'dashboard:is_periodic')::boolean
160-
THEN (to_jsonb(array[
161-
to_char(min(datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"'),
162-
to_char(max(datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')]))
163-
ELSE jsonb_agg(distinct to_char(datetime at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"'))
164-
END
165-
),
166-
'cog_default', (
167-
CASE
168-
WHEN collections."content"->'item_assets' ? 'cog_default'
169-
THEN jsonb_build_object(
170-
'min', min((items."content"->'assets'->'cog_default'->'raster:bands'-> 0 ->'statistics'->>'minimum')::float),
171-
'max', max((items."content"->'assets'->'cog_default'->'raster:bands'-> 0 ->'statistics'->>'maximum')::float)
172-
)
173-
ELSE NULL
174-
END
175-
)
176-
)
177-
) summaries,
178-
collections.id coll_id
179-
FROM items
180-
JOIN collections on items.collection = collections.id
181-
WHERE collections.id = _collection_id
182-
GROUP BY collections."content" , collections.id
183-
)
184-
UPDATE collections SET "content" = "content" || coll_item_cte.summaries
185-
FROM coll_item_cte
186-
WHERE collections.id = coll_item_cte.coll_id;
187-
$$ LANGUAGE SQL SET SEARCH_PATH TO dashboard, pgstac, public;
188-
"""
189-
190-
cursor.execute(sql.SQL(update_default_summary_sql))
191-
192-
193-
def create_update_all_default_summaries_function(cursor) -> None:
194-
"""Create function to update default summaries for all collections with required properties"""
195-
196-
update_all_default_summaries_sql = """
197-
CREATE OR REPLACE FUNCTION dashboard.update_all_default_summaries() RETURNS VOID AS $$
198-
SELECT
199-
update_default_summaries(id)
200-
FROM collections
201-
WHERE collections."content" ?| array['item_assets', 'dashboard:is_periodic'];
202-
$$ LANGUAGE SQL SET SEARCH_PATH TO dashboard, pgstac, public;
203-
"""
204-
205-
cursor.execute(sql.SQL(update_all_default_summaries_sql))
206-
207-
208137
def handler(event, context):
209138
"""Lambda Handler."""
210139
print(f"Handling {event}")
@@ -297,16 +226,6 @@ def handler(event, context):
297226
)
298227
)
299228

300-
# As admin, create custom dashboard schema and functions and grant privileges to bootstrapped user
301-
with psycopg.connect(stac_db_conninfo, autocommit=True) as conn:
302-
with conn.cursor() as cur:
303-
print("Creating dashboard schema...")
304-
create_dashboard_schema(cursor=cur, username=user_params["username"])
305-
306-
print("Creating update_default_summaries functions...")
307-
create_update_default_summaries_function(cursor=cur)
308-
create_update_all_default_summaries_function(cursor=cur)
309-
310229
except Exception as e:
311230
print(f"Unable to bootstrap database with exception={e}")
312231
send(event, context, "FAILED", {"message": str(e)})

lib/ingestor-api/runtime/src/loader.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,6 @@ def __init__(self, db) -> None:
1414
self.check_version()
1515
self.conn = self.db.connect()
1616

17-
def update_collection_summaries(self, collection_id: str) -> None:
18-
"""Update collection-level summaries for a single collection.
19-
This includes dashboard summaries (i.e. datetime and cog_default) as well as
20-
STAC-conformant bbox and temporal extent."""
21-
22-
with self.conn.cursor() as cur:
23-
with self.conn.transaction():
24-
logger.info(
25-
"Updating dashboard summaries for collection: {}.".format(
26-
collection_id
27-
)
28-
)
29-
cur.execute(
30-
"SELECT dashboard.update_default_summaries(%s)",
31-
[collection_id],
32-
)
33-
logger.info("Updating bbox for collection: {}.".format(collection_id))
34-
cur.execute("SELECT pgstac.collection_bbox(%s)", [collection_id])
35-
logger.info(
36-
"Updating temporal extent for collection: {}.".format(collection_id)
37-
)
38-
cur.execute(
39-
"SELECT pgstac.collection_temporal_extent(%s)", [collection_id]
40-
)
41-
4217
def delete_collection(self, collection_id: str) -> None:
4318
with self.conn.cursor() as cur:
4419
with self.conn.transaction():

lib/ingestor-api/runtime/src/utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,4 @@ def load_items(creds: DbCreds, ingestions: Sequence[Ingestion]):
4949
insert_mode=Methods.upsert,
5050
)
5151

52-
# Trigger update on summaries and extents
53-
collections = set([item["collection"] for item in items])
54-
for collection in collections:
55-
loader.update_collection_summaries(collection)
56-
5752
return loading_result

0 commit comments

Comments
 (0)