From 64e0ce27ba89391cc64a7f3f9d10bd2efdcb936b Mon Sep 17 00:00:00 2001 From: Semprini Date: Thu, 17 Sep 2026 23:22:37 +1200 Subject: [PATCH] Scaffold domain digital-core --- .env.example | 26 +++++++++++++++++++++ .gitignore | 6 +++++ .gitmodules | 3 +++ README.md | 48 +++++++++++++++++++++++++++++++++++++ compose.yml | 14 +++++++++++ dbt/dbt_project.yml | 26 +++++++++++++++++++++ dbt/macros/ducklake.sql | 52 +++++++++++++++++++++++++++++++++++++++++ dbt/models/.gitkeep | 0 dbt/profiles.yml | 16 +++++++++++++ dbt/schedules.yml | 9 +++++++ platform | 1 + products/.gitkeep | 0 pyproject.toml | 11 +++++++++ 13 files changed, 212 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 README.md create mode 100644 compose.yml create mode 100644 dbt/dbt_project.yml create mode 100644 dbt/macros/ducklake.sql create mode 100644 dbt/models/.gitkeep create mode 100644 dbt/profiles.yml create mode 100644 dbt/schedules.yml create mode 160000 platform create mode 100644 products/.gitkeep create mode 100644 pyproject.toml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d567aba --- /dev/null +++ b/.env.example @@ -0,0 +1,26 @@ +# digital-core — secrets and ports for this domain's stack. Never commit .env. +# platform/setup-domain.sh creates .env from this file and generates every CHANGE_ME. +# Keep values shell-safe (letters, digits, - _): scripts source .env. + +DOMAIN=digital-core + +# Host ports, all bound to 127.0.0.1 (port base 20000; give each domain its own base) +GRAPHQL_PORT=20000 +KAFKA_PORT=20001 +FLINK_PORT=20002 +TRINO_PORT=20003 +MINIO_CONSOLE_PORT=20004 + +KAFKA_CLUSTER_ID=CHANGE_ME +ODS_PASSWORD=CHANGE_ME +AUTHENTICATOR_PASSWORD=CHANGE_ME +LAKEHOUSE_PASSWORD=CHANGE_ME +MINIO_ROOT_USER=lake-admin +MINIO_ROOT_PASSWORD=CHANGE_ME +DBT_PASSWORD=CHANGE_ME +TRINO_LAKE_PASSWORD=CHANGE_ME + +# Written by platform/domain-integration.sh register|unregister mgmt. +# COMPOSE_PROFILES=scheduled starts the dbt-worker once Airflow can accept it. +AIRFLOW_JWT_SECRET= +COMPOSE_PROFILES= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..71052da --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.env +.venv/ +__pycache__/ +dbt/target/ +dbt/logs/ +dbt/dbt_packages/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..32c3bdd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "platform"] + path = platform + url = https://git.semprini.me/paul/semprini-data-domain.git diff --git a/README.md b/README.md new file mode 100644 index 0000000..7800fe1 --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +# Data domain: digital-core + +The running instance of the digital-core data domain: its stack, its generated data products and +its dbt project. Owned and operated by the domain's data product engineering team. + +It brings together work from three teams, each in its own repository: + +| Input | Owner | Repository | Used as | +|---|---|---|---| +| Domain platform | Data platform team | [semprini-data-domain](https://git.semprini.me/paul/semprini-data-domain) | the `platform/` submodule | +| Domain data model | Modelling team | the domain's `semprini-domain-*-datamodel` repository | product declarations and entities to generate from | +| Data product templates | Engineering teams | [semprini-data-product-templates](https://git.semprini.me/paul/semprini-data-product-templates) | what a product directory looks like, and the agent that generates it | + +| Path | What | +|---|---| +| `compose.yml` | The domain stack: includes `platform/compose.domain.yml` | +| `.env` | Domain name, ports and secrets (generated, never committed) | +| `products//` | Data products generated from a template for one model declaration | +| `dbt/` | dbt project for experience data products, built into the lakehouse | +| `dbt/schedules.yml` | When the management zone's Airflow runs them | + +Record which model and template versions a product was generated from in its commit +message, e.g. `Generate canonical-party from digital-datamodel v1.0.0, templates v0.1.0`. + +## Run + +The data management zone must be up first (semprini-data: `./stack-data.sh up mgmt`). + +```bash +git submodule update --init # after cloning +platform/setup-domain.sh # .env with generated secrets (idempotent) +docker compose up -d --build # the domain stack +uv run data-domain deploy /canonical_data_product/example # platform smoke test +uv run data-domain test /canonical_data_product/example +``` + +Run `data-domain` from this directory; it acts on the domain repository it is run in. + +Register with Keycloak (classification groups), OpenMetadata and Airflow, then start the +dbt-worker that the registration enables: + +```bash +platform/domain-integration.sh register all +docker compose up -d +``` + +Ports (127.0.0.1): GraphQL 20000, Kafka 20001, Flink 20002, Trino 20003, +MinIO console 20004. See `platform/README.md` for the platform. diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..ba89df5 --- /dev/null +++ b/compose.yml @@ -0,0 +1,14 @@ +# compose.yml — data domain digital-core +# +# The platform (ODS, GraphQL, Kafka, Flink, lakehouse, Trino, dbt-worker) is defined in +# platform/compose.domain.yml, from the semprini-data-domain submodule. Add services +# that belong only to this domain below the include. +# +# Requires the data management zone: cd ../semprini-data && ./stack-data.sh up mgmt + +name: digital-core + +include: + - path: platform/compose.domain.yml + project_directory: . + env_file: .env diff --git a/dbt/dbt_project.yml b/dbt/dbt_project.yml new file mode 100644 index 0000000..213808d --- /dev/null +++ b/dbt/dbt_project.yml @@ -0,0 +1,26 @@ +# dbt project for the digital-core domain's experience data products. +# +# Runs against the lakehouse as role `dbt`, whose default table access method is +# ducklake, so every model table is DuckLake (Parquet in MinIO), readable through +# Trino as lake... Give each experience product its own schema: +# models//*.sql with +schema: +# +# By hand: uv run data-domain dbt build +# Scheduled: schedules.yml, registered with platform/domain-integration.sh register mgmt + +name: digital_core +version: "1.0.0" +profile: domain + +model-paths: ["models"] +macro-paths: ["macros"] + +models: + digital_core: + +materialized: table + # Trino reads the lake as `trino`, a member of ducklake_reader. + +grants: + select: ["ducklake_reader"] + +on-run-end: + - "{% for schema in schemas %}grant usage on schema {{ schema }} to ducklake_reader;{% endfor %}" diff --git a/dbt/macros/ducklake.sql b/dbt/macros/ducklake.sql new file mode 100644 index 0000000..6ef03d5 --- /dev/null +++ b/dbt/macros/ducklake.sql @@ -0,0 +1,52 @@ +{#- + Macros that make dbt-postgres work against pg_ducklake. Verified 2026-09-17 with + dbt-core 1.12.5 / dbt-postgres 1.11.0 for table, view and incremental models. +-#} + +{#- + dbt-postgres stages incremental rows in `create temporary table ... as`. The dbt role + runs with default_table_access_method = ducklake, and DuckLake tables cannot be + temporary ("temporary tables are not supported with ducklake access method"), so + temporary tables are pinned to heap. Everything else is dbt-postgres's macro verbatim. +-#} +{% macro postgres__create_table_as(temporary, relation, sql) -%} + {%- set unlogged = config.get('unlogged', default=false) -%} + {%- set sql_header = config.get('sql_header', none) -%} + + {{ sql_header if sql_header is not none }} + + create {% if temporary -%} + temporary + {%- elif unlogged -%} + unlogged + {%- endif %} table {{ relation }} + {% if temporary -%} using heap {%- endif %} + {% set contract_config = config.get('contract') %} + {% if contract_config.enforced %} + {{ get_assert_columns_equivalent(sql) }} + {% endif -%} + {% if contract_config.enforced and (not temporary) -%} + {{ get_table_columns_and_constraints() }} ; + insert into {{ relation }} ( + {{ adapter.dispatch('get_column_names', 'dbt')() }} + ) + {%- set sql = get_select_subquery(sql) %} + {% else %} + as + {% endif %} + ( + {{ sql }} + ); +{%- endmacro %} + +{#- + A model's +schema is its experience product's schema, used as given rather than + prefixed with the target schema, so the product reads as lake..
. +-#} +{% macro generate_schema_name(custom_schema_name, node) -%} + {%- if custom_schema_name is none -%} + {{ target.schema }} + {%- else -%} + {{ custom_schema_name | trim }} + {%- endif -%} +{%- endmacro %} diff --git a/dbt/models/.gitkeep b/dbt/models/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/dbt/profiles.yml b/dbt/profiles.yml new file mode 100644 index 0000000..014b066 --- /dev/null +++ b/dbt/profiles.yml @@ -0,0 +1,16 @@ +# dbt connection profile, read inside the dbt-worker container. +# DBT_PASSWORD comes from the domain's .env; nothing else leaves the domain. +domain: + target: lakehouse + outputs: + lakehouse: + type: postgres + host: lakehouse + port: 5432 + user: dbt + password: "{{ env_var('DBT_PASSWORD') }}" + dbname: lake + schema: experience + # DuckLake does not retry conflicting transactions. On a first run dbt creates + # schemas from several threads at once, and two creating the same schema abort. + threads: 1 diff --git a/dbt/schedules.yml b/dbt/schedules.yml new file mode 100644 index 0000000..786e92b --- /dev/null +++ b/dbt/schedules.yml @@ -0,0 +1,9 @@ +# dbt schedules for domain digital-core: one Airflow DAG per entry, run by this domain's +# dbt-worker (platform/airflow/dbt_dags.py). The management zone's Airflow reads a copy, +# so re-run `platform/domain-integration.sh register mgmt` after editing this file. +domain: digital-core +schedules: [] +# - name: experience-hourly # DAG id: dbt_digital_core_experience_hourly +# select: tag:hourly # dbt node selection +# schedule: "@hourly" # cron or preset; null for manual runs only +# description: Rebuild the experience products tagged hourly diff --git a/platform b/platform new file mode 160000 index 0000000..fbbbef3 --- /dev/null +++ b/platform @@ -0,0 +1 @@ +Subproject commit fbbbef3a1df459f2677deceb9a29a254af8960e1 diff --git a/products/.gitkeep b/products/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..83b523c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[project] +name = "semprini-domain-digital-core" +version = "0.1.0" +description = "Data domain digital-core" +requires-python = ">=3.12" +dependencies = [ + "semprini-data-domain", +] + +[tool.uv.sources] +semprini-data-domain = { path = "platform", editable = true }