Skip to content

feat!: keep SQLBuild's own tables out of a schema named preserve - #1741

Open
kvlonge wants to merge 2 commits into
mainfrom
fix/preserve-schema-own-tables
Open

kvlonge wants to merge 2 commits into
mainfrom
fix/preserve-schema-own-tables

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Why

On a schema = "preserve" target, SQLBuild used preserve literally as the schema for its own tables. Every Snowflake build ran CREATE SCHEMA IF NOT EXISTS <db>.preserve for _sqlbuild_resource_costs. Query-mode sqb diff put its scratch tables there, or failed when the schema was missing. Review markers and the janitor looked there too.

Changes

  • New TargetSettingsValues::own_table_locations, one resolver for SQLBuild's own tables. With preserve it uses loader_schema, then the adapter's default schema, else stops with S105 before running anything. It never resolves to preserve.
  • Used by cost publication, query-diff scratch tables, review markers, and the janitor's artifact and review-schema lookups.
  • Docs: where these tables go; the Snowflake cost, diff, review and janitor pages.
  • DuckShop: no case. This is a target setting, not a model, macro or test shape.

Verification

  • DuckDB e2e with a cost-reporting adapter: loader_schema, the adapter default, and S105 for build and diff. A build with nothing to run passes. No preserve schema is left.
  • Snowflake: the real adapter's query diff stops with S105 before connecting; a unit test checks the exact message.
  • Postgres e2e: the cost table and diff scratch tables go to loader_schema and public.
  • The new cases fail on main. The janitor, diff, cost, node-result and review suites pass; clippy is clean.

BREAKING CHANGE: Snowflake targets with schema = "preserve" now need loader_schema. Snowflake has no default schema, so without it any build with work to run, a query diff or a review stops with S105 before running anything; add loader_schema = "..." to the target. On every preserve target, _sqlbuild_resource_costs, query-diff scratch tables and review markers move to loader_schema, or else to the adapter's default schema. Cost rows recorded earlier stay in the old preserve schema.

A target with schema = "preserve" keeps each model's own schema, but
SQLBuild used "preserve" literally for the tables it writes for itself:
every Snowflake build created a PRESERVE schema for
_sqlbuild_resource_costs, and query-mode sqb diff, review markers and the
janitor used it too.

TargetSettingsValues::own_table_locations now resolves one location for
these tables: the target's loader_schema, else the adapter's default
schema, else S105 before running anything. Cost publication, query-diff
scratch tables, review ownership markers and the janitor's artifact and
review-schema lookups use it.

BREAKING CHANGE: on a preserve target, _sqlbuild_resource_costs,
query-diff scratch tables and review markers move to loader_schema, or
the adapter's default schema. Adapters without one (Snowflake, BigQuery,
Databricks) need targets.<name>.loader_schema for a query diff or review,
and on Snowflake for every build; otherwise they fail with S105. Cost
rows recorded earlier stay in the old preserve schema.
…ng to run pass

S105 for SQLBuild's own tables now names the target, says its adapter has
no default schema, and gives the fix: add loader_schema = "..." to that
target. A build with no executable work records no costs, so it no longer
needs a schema for them. Covered by a unit test of the Snowflake message,
a query diff with the real Snowflake adapter that stops before connecting,
and a no-work build on a preserve target.

This branch has not been deployed

No deployments
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.

1 participant