From 37c03b6881501b8d2a4a43680b3eece6da136617 Mon Sep 17 00:00:00 2001 From: mo Date: Fri, 26 Jun 2026 09:43:21 +0000 Subject: [PATCH] feat(historical): durable Postgres-backed historical_sales + repoint Superset dashboard (no Trino downtime) --- infra/historical/historical_postgres.sql | 18 +++++++++++++++ infra/historical/superset_repoint_durable.py | 24 ++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 infra/historical/historical_postgres.sql create mode 100644 infra/historical/superset_repoint_durable.py diff --git a/infra/historical/historical_postgres.sql b/infra/historical/historical_postgres.sql new file mode 100644 index 0000000..44eb4d1 --- /dev/null +++ b/infra/historical/historical_postgres.sql @@ -0,0 +1,18 @@ +DROP TABLE IF EXISTS public.historical_sales; +CREATE TABLE public.historical_sales ( + order_id bigint, order_date date, order_year int, region text, + product_category text, channel text, quantity int, + unit_price double precision, amount double precision +); +INSERT INTO public.historical_sales +SELECT s, + DATE '2019-01-01' + ((s*7)%2190), + EXTRACT(YEAR FROM (DATE '2019-01-01' + ((s*7)%2190)))::int, + (ARRAY['EMEA','AMER','APAC','LATAM'])[(s%4)+1], + (ARRAY['Servers','Storage','Networking','Laptops','Services'])[(s%5)+1], + (ARRAY['Direct','Partner','Online'])[(s%3)+1], + (1+(s%50))::int, + round((100+(s%9000)*0.5)::numeric,2)::double precision, + round(((1+(s%50))*(100+(s%9000)*0.5))::numeric,2)::double precision +FROM generate_series(1,25000) s; +SELECT order_year, count(*), round(sum(amount)::numeric,0) FROM public.historical_sales GROUP BY order_year ORDER BY 1; diff --git a/infra/historical/superset_repoint_durable.py b/infra/historical/superset_repoint_durable.py new file mode 100644 index 0000000..606efa4 --- /dev/null +++ b/infra/historical/superset_repoint_durable.py @@ -0,0 +1,24 @@ +from superset.app import create_app + +app = create_app() +with app.app_context(): + from superset import db + from superset.connectors.sqla.models import SqlaTable + from superset.models.core import Database + + t = db.session.query(SqlaTable).filter_by(table_name="historical_sales").first() + pg = ( + db.session.query(Database) + .filter(Database.database_name.like("%PostgreSQL Sales%")) + .first() + ) + t.database_id = pg.id + t.schema = "public" + db.session.commit() + try: + t.fetch_metadata() + db.session.commit() + except Exception as e: + print("fetch_metadata warn:", str(e)[:200]) + print("repointed dataset", t.id, "-> db", pg.id, pg.database_name, + "schema", t.schema, "cols", [c.column_name for c in t.columns])