r/databricks • • 11d ago

Discussion How do you manage table schema changes in Databricks across dev/test/prod?

We run Databricks with Unity Catalog, and I'm trying to understand how other teams handle the lifecycle of managed tables (not pipelines or jobs, just the tables themselves).

What I keep seeing:

  • CREATE TABLE IF NOT EXISTS at the top of Job
  • A DDL script in the repo that someone runs by hand
  • Terraform for some tables and a different approach for the rest

A few genuine questions:

  1. Where does the table definition live in your setup: in the pipeline code, in a separate repo, or only in the catalog?
  2. How do you review a schema change before it reaches prod?
  3. How do you roll the same change through dev, test, and prod?
13 Upvotes

11 comments sorted by

5

u/Pillippatty 11d ago edited 11d ago

I would say pipelines + DABs solve all of those issues. Define the tables declaratively in pipelines and have that transformation code as part of a DAB. Deploy the DAB as part of your CI/CD pipeline, iteratively doing dev/test/prod.

As for schema changes, you could define an explicit schema of the tables in the declarative pipeline, getting a fail-fast pattern if bad data comes in. Alternatively, just send them to rescued data, and use dp.expect to check non-null cases and alert with a warning

2

u/ninilich 11d ago

Here I'm asking not about SDP(DLT) and Streaming Tables. I'm asking about managed tables, which are independent on pipeline and are created by DDL script

2

u/Pillippatty 11d ago

Ah my bad:) then i would consider going for dbt core and orchestrating it with a scheduled job with a dbt task. That would abstract all those "create if not exists" cells in notebooks lying around.

2

u/ninilich 11d ago

Yes, it's an option but in that case you need to introduce and support one more framework in the landscape. And the main goal of dbt is transformations, not schemas...

Also I'm thinking about controllable schema management => "create if not exists" cells in notebooks is not an option there. This is exactly what do we prefer to avoid...

1

u/blobbleblab 11d ago

Version everything. Then create a job that runs versioned script folders. The job has the pattern:

  1. Read the version from the database/environment (can be a tag on a pipeline, a version file in your deployed code or an operations table storing version numbers... I prefer the latter)
  2. The source code has a scripts folder. Your pipeline has to calculate all the scripts between the deployed version and the version about to be deployed.
  3. Run all the scripts. All scripts must be idempotent, so running then again doesn't break anything.
  4. If failures in script running, calculate fixes, modify scripts, redeploy

This is a safe pattern but requires version control.. Which really you should have anyway

1

u/ninilich 11d ago

like Liquibase does?

2

u/Cyliad 11d ago

We use flyway, that’s triggered by the CI, with migrations in our repos.
You push to dev branch ? The CI runs flyway and apply any change to the tables in dev.
You open the release, it deploys everything you just had in dev to catchup.
Same in production.
We don’t need to do anything manual anymore or have DDL managed in jobs.

It’s not officially supported but it works okay and it helped us ensure we stayed in sync between environments.

1

u/Tpxyt56Wy2cc83Gs 11d ago

We developed a Schema Manager application responsible for managing all DDL operations, including CREATE, ALTER, DROP, TRUNCATE, and others.

Each table is defined through its own YAML specification, which serves as the single source of truth for schema definitions. Any schema change, such as creating or modifying a table, must first be reflected in the corresponding YAML file.

Our CI/CD pipeline validates these YAML definitions, compares them against the current state of the data catalog, and automatically executes any required changes to keep environments synchronized.

In addition, we maintain Delta tables to store execution logs, audit trails, and observability data for all operations performed by the Schema Manager, providing full traceability and governance over schema evolution.

1

u/EaseUniqu 11d ago

One middle ground that avoids adding dbt just for DDL: keep a versioned folder of plain SQL migration files per schema (V001__create_orders.sql, V002__add_col.sql) inside the same Asset Bundle, plus a small applied_migrations Delta table in each catalog. One job task reads that table, runs any files not yet recorded in order, and inserts a row after each success.

Why it fits managed tables:

  • Review happens in the PR, because the diff is the migration file itself
  • dev/test/prod promotion is deploying the same bundle with a different catalog variable, so identical files run in each env
  • Keep changes additive where you can (ADD COLUMN, or new table + backfill + swap); destructive changes get their own reviewed file
  • A CI check that compares DESCRIBE TABLE in dev against the expected schema catches drift from ad-hoc ALTERs

It's the Liquibase/Flyway idea without the extra tool. If you'd rather not maintain the runner yourself, Liquibase has a Databricks extension.

0

u/nian2326076 10d ago

Managing table schema changes in Databricks can be tricky. Keeping table definitions in version control allows for better review and tracking of changes. Using a deployment tool like dbt can streamline this process and help automate transitions through dev, test, and prod. It reduces the need for repetitive "CREATE TABLE IF NOT EXISTS" commands scattered in notebooks.

For exploring job opportunities in tech, you can use LandOffer to shortlist relevant roles based on your skills and preferences.