Avoiding Schema Changes When Adding Analytics to Supabase

Keep analytics separate from production schema using a dedicated read layer.

· 10 min read
Cover illustration for “Avoiding Schema Changes When Adding Analytics to Supabase”
Supabase Analytics · October 10, 2026 · 10 min read · 2,267 words

Adding analytics to a Supabase project does not require touching the production schema. The production database stays exactly as it is; a separate read layer captures the data, JSONB and all, and a modeling layer above it defines what the metrics mean. That separation, not a new column or a bigger instance, is what lets a team run real analytics and hand it to an AI agent without risking the application that depends on the same database.

The Wrong Place for Analytics: The Production Schema

The easiest fix looks harmless at first: add an analytics column here, a materialized view there, maybe a service account with broad SELECT access so the BI tool can see what it needs. The trouble starts because application migrations and metric definitions now live in the same place and start fighting each other. A metric definition changes roughly as often as a product team runs a retro; an application schema changes when the product itself changes. Tie the two together and every schema migration risks breaking a metric, and every metric change starts requiring a migration.

Postgres is not the obstacle here. The production instance is tuned for transactional work: lots of small, fast reads and writes, row by row. A query that scans a million-row table to compute a monthly trend competes for the same CPU and memory that is supposed to be serving live traffic. Running that query at the wrong moment makes users feel it as latency.

JSONB columns make this worse in a specific way. So someone writes a SQL query to pull the field out. Within a few weeks, five people are running five slightly different extraction queries, and the business ends up with five slightly different answers to the same question.

The connection path compounds the problem. The alternative, a direct connection, holds a slot open against the same database serving the app for as long as the analytical query runs. Neither path was built for this job.

A row-level access control layer adds a final complication. Either choice muddies the one thing RLS is supposed to guarantee clearly. A team gets governed, AI-readable analytics by keeping all of this out of the production schema.

What pointing BI at a read replica costs

A read replica is the obvious next move, and it solves exactly one problem: it takes the load off the primary. Replica compute is billed at roughly the same size as the primary, plus the storage, so a team that adds a replica for analytics is roughly doubling its database spend to run the identical workload shape, just somewhere else.

Everything that made the production schema the wrong target is still a problem on the replica. And the governance questions that are about to be enforced at the API level (more on that shortly) don't go away just because the query runs on a second machine.

A separate analytical layer that reads Postgres as-is without schema changes

Diagram: Three-Layer Architecture: Production to AI Agent. Visualizes: Show a three-layer stack that separates the production Supabase database from AI agents and dashboards.

The architecture that resolves this keeps three things cleanly apart. The production schema stays untouched. A replication or read layer captures rows exactly as they exist, JSONB included, with no transformation. A modeling layer sits above that and defines what the numbers mean. Application migrations and metric definitions stop interfering with each other because they no longer live in the same place.

Supabase Pipelines, announced in December 2025 and updated to public alpha with BigQuery, ClickHouse, DuckLake, and Snowflake as destinations as of October 2, 2026, is one way to build the first half of that separation. It uses logical replication, the same mechanism Postgres has supported for years, to capture inserts, updates, deletes, and truncates as they happen. A publication on the production side defines which tables to replicate; the pipeline reads changes from that publication through a replication slot and writes them, in batches, to the destination. Setup needs no code changes on the application side, though turning Pipelines on does add an etl schema and a database event trigger to the source database.

What matters architecturally is that the data arrives as-is. JSONB travels intact rather than getting flattened or reshaped along the way (schema change support is currently in beta for the BigQuery destination). That also means Pipelines does one job and stops: it moves rows, it does not decide what "active user" or "MRR" means. That work still has to happen somewhere, and naming that gap honestly is what sets up the next section.

Two storage options matter once the data lands somewhere new. DuckLake, now at version 1.0 with 1.1 scheduled for October 2026 and available as a Pipelines destination, takes the same idea further: the analytical schema lives in a format completely decoupled from production Postgres, free to change shape without ever touching the database serving the app.

Metric definitions belong in the modeling layer, not the database

Once rows are sitting somewhere outside production, the temptation is to just query them directly and call the problem solved. That's where the real work actually starts. A metric encoded as a column or a view, wherever it lives, is still coupled to whatever schema it sits on top of. A schema change breaks the metric. When what the metric means changes, someone has to go edit the thing that computes it, wherever that happens to be.

The fix is building one foundation: one governed set of measures, filters, and dimensions that every metric gets derived from, so a dashboard and an AI agent pulling the same number always get the same answer, because they're drawing from the same calculation underneath.

Conflicting numbers, finance reporting one gross margin while marketing reports another, are almost never a math error. None of those count as a governed semantic layer, no matter how carefully each one was written.

A useful starting discipline for a founder without a dedicated data team: pick the handful of numbers the business actually runs on, maybe five, maybe seven, total revenue, blended CAC, LTV:CAC ratio, month-over-month growth, whatever the real list is for that business. None of this requires the production schema to change. The specific metrics matter less than the discipline of defining each one exactly once and routing every consumer through it.

The October 2026 Data API change

Supabase has made a change that turns this from a best practice into something closer to a requirement. Starting April 28, 2026, new projects could opt out of automatic Data API exposure for tables in the public schema. For projects that already existed, the change is enforced on October 30, 2026: new tables created after that date without explicit grants stop being reachable through PostgREST. Existing tables keep whatever grants they already had and stay reachable.

Any analytics tool or AI agent that was quietly relying on blanket PostgREST access to every table in a project now has to get explicit, per-table grants instead. Exposure used to happen by accident, as the default behavior nobody had to configure. Now it has to be a decision someone makes on purpose.

The move is not to grant broad access again just to restore the old convenience. Audit which tables the analytics layer touches, then build a role with read-only, explicitly scoped grants to exactly those tables and nothing else.

Why AI agents make the governed data layer non-negotiable

Everything that was a nuisance when a human ran a bad query becomes a different kind of risk once an AI agent is the one running it. Every naming inconsistency, every permission gap, every place where two metrics disagree turns into a failure mode the moment an agent can query the database directly, because the agent runs at machine speed and has no instinct that tells it something looks off.

There's a technical reason this matters more than it might initially seem. Foundation models can't reliably tell system instructions apart from ingested data when both arrive through the same context window. That means any untrusted text sitting in a production database, a user-submitted field, a support ticket, a free-text note, has to be treated as a possible attack vector. An AI agent built to answer analytical questions should never hold credentials that let it write to or alter the production schema.

A workable governance baseline for these agents has three parts: read-only access as the default, with write access requiring its own explicit justification; scope limited to a defined set of tables or schemas rather than the whole database; and time-bound credentials for any agent that only needs access temporarily. Applied concretely: an agent answering "what is MRR this month" needs SELECT on a pre-calculated metrics table. It does not need credentials to the orders, subscriptions, and events tables that metric was built from.

MCP: connecting a governed analytical layer to any AI agent

The Model Context Protocol, an open standard Anthropic introduced in November 2024, is what lets an AI agent query a data source and turn the result into something like a report. The donation runs through a newly formed body called the Agentic AI Foundation, and it moves MCP out from under any single company's control and places it under the same umbrella that hosts the CNCF, the body that governs Kubernetes and OpenTelemetry.

None of that governance history makes the underlying risk disappear. If anything, it raises the stakes, because an MCP server wired straight to a raw production database hands an agent the same dangerous reach as a direct database credential would. Build a read-only MCP server instead, one that exposes pre-modeled, pre-calculated datasets rather than raw tables, so an agent gets fast, accurate context without ever touching production directly.

Isolating credentials at the protocol layer itself, rather than relying on the application to police access after the fact, is what made it work.

Because of how the Linux Foundation now governs the standard, Claude and GPT support MCP natively, and Gemini's support is partial and still maturing. A Postgres MCP server exposing a governed, read-only analytics interface is infrastructure that the whole AI tooling ecosystem can already speak. The pattern this makes possible, metrics defined once and consumed by any agent or dashboard over MCP, sometimes called headless analytics, is running in production today.

What Dreambase does that the analytical layer alone cannot

Everything above describes an architecture: don't touch production, replicate rows as-is, define metrics once in a layer above the database, and expose that layer to agents through MCP. Building that architecture from scratch is real work, and most teams running a Supabase project don't have a data engineer on staff to do it.

Dreambase is built to sit at exactly that layer. It connects to a Supabase project, pre-calculates metrics into governed Parquet datasets that get queried through DuckDB, and exposes the result through a single MCP server, so agents never query production directly and the humans on a team stop seeing five versions of the same number. It adds full analytics capability on top of an existing Supabase project with no ETL pipeline to build, no schema changes, and no new infrastructure to run. The production schema is left exactly as it was before Dreambase ever connected.

Pipelines solves the replication half of the problem well, but what "MRR" actually means is left unanswered, by design, since that's not its job, and Dreambase is built to close that gap: it models data into datasets with one definition per metric, so a dashboard, an AI agent, and an investor update all pull from the same calculation.

For an AI agent specifically, this matters at the level of mechanics, not just governance. An agent querying modeled Parquet data through DuckDB is scanning something built to be scanned, faster and cheaper than a live query against production rows, and safe by construction because the agent was never given a path to production. That's the access pattern argued for across this piece, and it's what Dreambase runs in practice.

The same MCP server works across Claude, Claude Code, ChatGPT, Codex, Cursor, Gemini, Grok, and Slack, so a team can hand the same governed data layer to whichever AI tools it already uses, without setting up separate database credentials for each one.

Pricing starts at $29 a month on an annual plan, aimed at solo founders and small teams, with a 14-day free trial on every paid plan. For a team that has read this far and agrees with the architecture, Dreambase is one answer to the question of who actually builds it.

The objection worth taking seriously: is a semantic layer always necessary

Not everyone agrees a semantic layer is required.

Few Supabase projects meet all four conditions without the modeling layer this piece has been describing, because most schemas grew organically, under deadline pressure, by more than one person, over more than one year.

A pre-built MCP server for an individual tool doesn't fix the deeper problem either. If "active user" is computed one way in the events table, a different way in the subscriptions table, and a third way in a Stripe webhook payload, exposing all three to an agent raw gives it three conflicting answers. Unifying those three definitions into a single answer is the actual job a semantic layer does.

The disagreement over which specific tool to use is smaller than it looks. The discipline that decides this: never run analytics against production, keep every analytical access path read-only, and encode each metric definition exactly once, in a layer above the database, so every dashboard and every agent inherits the same answer. Whatever tooling a team picks to implement that discipline, the discipline itself is what decides whether the numbers can be trusted.

Sources

  1. Why Traditional Supabase Analytics Tools Fall Short
  2. Semantic Layer for Analytics: Fixing BI Metric Drift [2026]
  3. The 2026-07-28 MCP Specification Release Candidate

More in Supabase Analytics