Skip to content

Publish local runs to analytics_dev on the real database - #1

Open
lassebenni wants to merge 1 commit into
mainfrom
feat/analytics-dev-schema
Open

Publish local runs to analytics_dev on the real database#1
lassebenni wants to merge 1 commit into
mainfrom
feat/analytics-dev-schema

Conversation

@lassebenni

Copy link
Copy Markdown
Collaborator

TL;DR

Local pipeline runs publish to analytics_dev on the team's real Postgres instead of a Docker copy, so TLS, firewall and grants get tested before the scheduled run.

Situation

Trainees run ingest, dbt and publish on their laptops. The template still pointed publish at a local Postgres container.

Problem

A container hides the failures that show up on the first real scheduled run: TLS (sslmode=require), the Azure firewall, and whether the database role may write the target schema.

Solution

Port final-project-template#18: add analytics_dev + analytics_dev_user, point .env.example at the real host, stamp published tables with the source schema, and stop Astro from overriding the publish target back to Docker.

Example

A trainee sets BACKEND_PG_USER=analytics_dev_user and BACKEND_PG_PUBLISH_SCHEMA=analytics_dev, runs publish, and rows land in analytics_dev.fct_postings on the team VM — same table name production uses, different schema.

Test plan

  • python -m pytest data/tests/publishing/test_sync.py
  • astro dev start then airflow tasks test publish_to_backend writes to analytics_dev
  • Run scripts/db-setup.py on team Postgres if analytics_dev_user does not exist yet
  • Distribute analytics_dev_user password via Key Vault (fp-pg-analytics-dev-team-c)

Made with Cursor

Ports final-project-template#18: analytics_dev schema, dev publish role,
table stamp on publish, and Astro no longer overrides the DB target back to
Docker Postgres.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings August 13, 2026 12:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ports the “publish local runs to analytics_dev on the real database” workflow into this repo so trainees’ local pipeline runs exercise the same TLS/firewall/grant constraints as the scheduled run, without risking writes to production analytics.

Changes:

  • Extend scripts/db-setup.py to create an analytics_dev schema + analytics_dev_user role and grant read/write boundaries accordingly.
  • Stamp published backend tables with a COMMENT describing the warehouse source schema + timestamp, with tests for comment placement and optionality.
  • Update local Airflow + docs/env examples to stop forcing publish back to Docker Postgres and to default local publishes to analytics_dev.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
scripts/db-setup.py Adds analytics_dev schema/role and multi-schema read-only grants.
data/src/publishing/sync.py Adds optional source stamping via COMMENT ON TABLE.
data/tests/publishing/test_sync.py Tests the new stamping behavior and ordering.
data/airflow/dags/pipeline_dag.py Passes publish schema setting and source into publish().
data/airflow/docker-compose.override.yml Removes local-DB overrides so Astro uses the same backend DB settings as uv run.
data/.env.example Updates backend DB variables to target the real DB and analytics_dev_user.
data/README.md Documents new local publish target (analytics_dev) and the source-stamp behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread data/.env.example
Comment on lines +89 to +90
# looking at.
BACKEND_PG_HOST= # your teacher gives you this
Comment thread data/.env.example
Comment on lines +95 to +96
BACKEND_PG_USER=analytics_dev_user
BACKEND_PG_PASSWORD= # your teacher gives you this
Comment thread data/README.md
Comment on lines +319 to +320
| `BACKEND_PG_PUBLISH_SCHEMA` | `analytics_dev` | `analytics` |
| `BACKEND_PG_USER` | `analytics_dev_user` | `analytics_user` |
Comment thread data/README.md
Comment on lines 362 to +365
It reads `<catalog>.dev_yourname.fct_postings_enriched` and writes
`analytics.fct_postings` in your own Postgres, the one `scripts/db-setup.py`
created. `dbt_build` runs the same way. The `ingest` task does not: it starts a
`analytics_dev.fct_postings` in the real backend database. Same table name as
production, one schema across, so promoting it later changes nothing the
backend selects. `dbt_build` runs the same way.
"fct_postings",
columns,
rows,
source=f"{Warehouse.from_env().catalog}.{setting('DBT_SCHEMA')}",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants