-- {{product.name}}: analytical replication into DuckLake (runs on the lakehouse service).
--
-- pg_duckpipe follows the ODS write-ahead log and maintains a DuckLake copy of each table as
-- Parquet in the domain's `lake` bucket. The platform-level sync group `ods` already points
-- at the ODS (platform/compose.domain.yml); the product only registers its tables with it.
-- Trino reads the result as lake.{{product.schema}}.
.
CREATE SCHEMA IF NOT EXISTS {{product.schema}};
-- >>> repeat per entity table, parents before children
SELECT duckpipe.add_table(
'{{product.schema}}.{{table}}',
target_table => '{{product.schema}}.{{table}}',
sync_group => 'ods'
);
-- <<< end repeat
-- Readers (Trino) and writers (dbt, building experience products on top) need the tables.
-- pg_ducklake does not yet enforce SELECT on DuckLake tables, so these grants document intent
-- as much as they control it; see docs/security-architecture.md.
GRANT USAGE ON SCHEMA {{product.schema}} TO ducklake_reader, ducklake_writer;
GRANT SELECT ON ALL TABLES IN SCHEMA {{product.schema}} TO ducklake_reader, ducklake_writer;