r/databricks • u/[deleted] • 18d 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 EXISTSat the top of JobA 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:
Where does the table definition live in your setup: in the pipeline code, in a separate repo, or only in the catalog?
How do you review a schema change before it reaches prod?
How do you roll the same change through dev, test, and prod?
1
u/blobbleblab 18d ago
Version everything. Then create a job that runs versioned script folders. The job has the pattern:
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)
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.
Run all the scripts. All scripts must be idempotent, so running then again doesn't break anything.
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
2
u/Cyliad 17d 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 17d 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 17d 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 17d 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.
0
u/mack_attaque 4h ago
wouldn't it be great if someone could build a database platform that can manage schemas across sql and databricks? https://www.schema-ops.com/
5
u/Pillippatty 18d ago edited 18d 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