databricks-schema 0.6.1__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/.gitignore +1 -1
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/CLAUDE.md +10 -3
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/PKG-INFO +167 -77
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/README.md +163 -76
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/databricks_schema/__init__.py +2 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/databricks_schema/cli.py +383 -81
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/databricks_schema/diff.py +53 -1
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/databricks_schema/extractor.py +13 -5
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/pyproject.toml +4 -1
- databricks_schema-0.8.0/skills/databricks-schema-cli/SKILL.md +200 -0
- databricks_schema-0.8.0/tests/test_cli.py +416 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/tests/test_diff.py +118 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/tests/test_extractor.py +28 -7
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/uv.lock +1 -1
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/.github/workflows/ci.yml +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/.github/workflows/release.yml +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/.python-version +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/LICENSE +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/databricks_schema/models.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/databricks_schema/sql_gen.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/databricks_schema/validate.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/databricks_schema/yaml_io.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/examples/01_extract_schema.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/examples/02_save_load_yaml.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/examples/03_diff_schemas.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/examples/04_generate_sql.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/tests/__init__.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/tests/test_models.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/tests/test_sql_gen.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/tests/test_validate.py +0 -0
- {databricks_schema-0.6.1 → databricks_schema-0.8.0}/tests/test_yaml_io.py +0 -0
|
@@ -21,9 +21,9 @@ databricks_schema/
|
|
|
21
21
|
models.py # Pydantic v2 models: Catalog, Schema, Table, Column, PrimaryKey, ForeignKey
|
|
22
22
|
extractor.py # CatalogExtractor — wraps databricks-sdk
|
|
23
23
|
yaml_io.py # schema/catalog to/from YAML and JSON; _strip_empty removes None + empty collections
|
|
24
|
-
diff.py # diff_schemas / diff_catalog_with_dir; FieldChange, ColumnDiff, TableDiff, SchemaDiff, CatalogDiff
|
|
24
|
+
diff.py # diff_schemas / diff_catalogs / diff_catalog_with_dir / diff_schema_dirs; FieldChange, ColumnDiff, TableDiff, SchemaDiff, CatalogDiff
|
|
25
25
|
sql_gen.py # schema_diff_to_sql — pure SQL generation from SchemaDiff; no SDK/IO
|
|
26
|
-
cli.py # argparse CLI: extract, diff, generate-sql, list-catalogs, list-schemas
|
|
26
|
+
cli.py # argparse CLI: extract, diff, generate-sql, validate, diff-files, list-catalogs, list-schemas
|
|
27
27
|
__init__.py # public re-exports
|
|
28
28
|
tests/
|
|
29
29
|
test_models.py
|
|
@@ -31,11 +31,14 @@ tests/
|
|
|
31
31
|
test_yaml_io.py
|
|
32
32
|
test_diff.py # pure model comparison, no SDK calls
|
|
33
33
|
test_sql_gen.py # pure SQL generation tests, no SDK calls
|
|
34
|
+
test_validate.py
|
|
35
|
+
skills/databricks-schema-cli/SKILL.md # Agent Skill: teaches an AI agent to drive the CLI
|
|
34
36
|
```
|
|
35
37
|
|
|
36
38
|
## Conventions
|
|
37
39
|
|
|
38
40
|
- Package manager: `uv`; do not use `pip` directly
|
|
41
|
+
- Version bumps: use `uv version --bump <major|minor|patch>` (updates `pyproject.toml` and `uv.lock` together) — do not hand-edit the version string
|
|
39
42
|
- Ruff: select E, W, F, I, UP; line-length 100; target py311
|
|
40
43
|
- Use `X | None` not `Optional[X]`; use `datetime.UTC` not `timezone.utc`
|
|
41
44
|
- `from __future__ import annotations` in every module
|
|
@@ -50,8 +53,11 @@ tests/
|
|
|
50
53
|
- CLI: catalog is a required positional argument (not a flag)
|
|
51
54
|
- `extract` `--format`/`-f` selects output format (`yaml` default, `json` opt-in); dest is `fmt`
|
|
52
55
|
- `diff` auto-detects format from files present in the directory; exits 2 on mixed YAML+JSON
|
|
56
|
+
- `diff`'s second positional arg is a directory if one exists at that path, else a second catalog name (`diff_catalogs`); first `catalog` arg is always the live side
|
|
53
57
|
- `TableType` is re-exported from `databricks.sdk.service.catalog` — do not redefine it
|
|
54
|
-
- `--include-metadata` flag (on `extract`, `diff`, `generate-sql`)
|
|
58
|
+
- `--include-metadata` flag (on `extract`, `diff`, `generate-sql`, `diff-files`) adds `owner` to output/comparison; `extract` additionally includes `storage_location` in its output (not compared by `diff`/`generate-sql`/`diff-files`); excluded by default
|
|
59
|
+
- `--include-tags` flag (on `extract`, `diff`, `generate-sql`) enables Unity Catalog tag lookups; excluded by default
|
|
60
|
+
- `--quiet`/`-q` flag (on `extract`, `diff`, `generate-sql`, `diff-files`) raises the log level to suppress progress messages; errors always print
|
|
55
61
|
- `diff` command exits 0 (no changes) or 1 (differences found) — useful in CI
|
|
56
62
|
- Diff result types are dataclasses (not Pydantic); comparison functions are pure (no SDK calls)
|
|
57
63
|
- `generate-sql` auto-detects format from files; exits 2 on mixed YAML+JSON or empty directory
|
|
@@ -59,3 +65,4 @@ tests/
|
|
|
59
65
|
- `sql_gen.py` is pure (no SDK, no I/O); diff direction: `FieldChange.old` = stored (target), `.new` = live
|
|
60
66
|
- FK refs in SQL use same catalog as the source table (`ref_schema` + `ref_table` from model)
|
|
61
67
|
- Unsupported field changes (`table_type`) emit `-- TODO: unsupported change: …` comments
|
|
68
|
+
- When CLI commands, flags, or output shape change, update `skills/databricks-schema-cli/SKILL.md` to match
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: databricks-schema
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Databricks Unity Catalog schema extractor
|
|
5
|
+
Project-URL: Homepage, https://github.com/frizzleqq/databricks-schema
|
|
5
6
|
Project-URL: Repository, https://github.com/frizzleqq/databricks-schema
|
|
6
7
|
Project-URL: Issues, https://github.com/frizzleqq/databricks-schema/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/frizzleqq/databricks-schema/releases
|
|
7
9
|
Author: frizzleqq
|
|
8
10
|
License-Expression: Apache-2.0
|
|
9
11
|
License-File: LICENSE
|
|
10
12
|
Keywords: databricks,schema,sql,unity-catalog
|
|
11
13
|
Classifier: Development Status :: 4 - Beta
|
|
12
14
|
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
16
|
Classifier: Programming Language :: Python :: 3
|
|
14
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -22,11 +25,19 @@ Description-Content-Type: text/markdown
|
|
|
22
25
|
|
|
23
26
|
# databricks-schema
|
|
24
27
|
|
|
25
|
-
A CLI tool and Python library that uses the Databricks SDK to extract and diff Unity Catalog schemas
|
|
28
|
+
A CLI tool and Python library that uses the Databricks SDK to extract and diff Unity Catalog schemas in YAML format. It can also generate Databricks Spark SQL to apply schema changes across catalogs.
|
|
26
29
|
|
|
27
|
-
##
|
|
30
|
+
## Getting Started
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
Install from PyPI (requires Python 3.11+):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install databricks-schema
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Configure your Databricks credentials (see [Authentication](#authentication) for all supported methods).
|
|
39
|
+
|
|
40
|
+
Then extract, diff, and generate SQL for your Unity Catalog schemas:
|
|
30
41
|
|
|
31
42
|
```bash
|
|
32
43
|
# 1. Find the catalog you want to snapshot
|
|
@@ -42,11 +53,76 @@ databricks-schema diff test_catalog ./schemas/
|
|
|
42
53
|
databricks-schema generate-sql test_catalog ./schemas/ --output-dir ./migrations/
|
|
43
54
|
```
|
|
44
55
|
|
|
45
|
-
|
|
56
|
+
## Databricks Authentication
|
|
57
|
+
|
|
58
|
+
The tool uses the [Databricks SDK](https://github.com/databricks/databricks-sdk-py) for auth. Configure it via environment variables:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
export DATABRICKS_HOST=https://<databricks-url>
|
|
62
|
+
export DATABRICKS_TOKEN=<your-personal-access-token>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Or use a [Databricks CLI profile](https://docs.databricks.com/dev-tools/cli/profiles.html) (`~/.databrickscfg`) — the SDK will pick it up automatically.
|
|
66
|
+
|
|
67
|
+
You can also pass credentials directly as flags using `--host` / `--token` below.
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
Requires Python 3.11+ and [uv](https://github.com/astral-sh/uv).
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
git clone https://github.com/frizzleqq/databricks-schema
|
|
75
|
+
cd databricks-schema
|
|
76
|
+
uv sync --all-groups # includes pytest and ruff
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Run tests
|
|
81
|
+
uv run pytest
|
|
82
|
+
|
|
83
|
+
# Lint
|
|
84
|
+
uv run ruff check databricks_schema/ tests/
|
|
85
|
+
|
|
86
|
+
# Format
|
|
87
|
+
uv run ruff format databricks_schema/ tests/
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Agent Skill
|
|
91
|
+
|
|
92
|
+
This repo ships an [Agent Skill](https://code.claude.com/docs/en/skills) at
|
|
93
|
+
[`skills/databricks-schema-cli/SKILL.md`](skills/databricks-schema-cli/SKILL.md)
|
|
94
|
+
that teaches an AI coding agent (e.g. Claude Code) how to use the `databricks-schema` CLI to
|
|
95
|
+
explore, snapshot, diff, and generate migration SQL for a live Unity Catalog. Copy the skill into
|
|
96
|
+
your own project and it can use the CLI directly instead of writing ad-hoc Databricks SDK calls
|
|
97
|
+
or queries.
|
|
98
|
+
|
|
99
|
+
The skill assumes the `databricks-schema` command is on `PATH`. Install it as a standalone tool
|
|
100
|
+
with [uv](https://github.com/astral-sh/uv):
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
uv tool install databricks-schema
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
To use the skill in your own project without cloning this repo, download it directly into your
|
|
107
|
+
project's `.claude/skills/`:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
mkdir -p .claude/skills/databricks-schema-cli
|
|
111
|
+
curl -o .claude/skills/databricks-schema-cli/SKILL.md \
|
|
112
|
+
https://raw.githubusercontent.com/frizzleqq/databricks-schema/main/skills/databricks-schema-cli/SKILL.md
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
For agentic harnesses other than Claude Code that look under `.agents/skills/` instead:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
mkdir -p .agents/skills/databricks-schema-cli
|
|
119
|
+
curl -o .agents/skills/databricks-schema-cli/SKILL.md \
|
|
120
|
+
https://raw.githubusercontent.com/frizzleqq/databricks-schema/main/skills/databricks-schema-cli/SKILL.md
|
|
121
|
+
```
|
|
46
122
|
|
|
47
123
|
## Output Format
|
|
48
124
|
|
|
49
|
-
Each schema is written to `{output-dir}/{schema-name}.yaml
|
|
125
|
+
Each schema is written to `{output-dir}/{schema-name}.yaml` if `--output-dir` is specified. Fields with no value (null comments, empty tag dicts, empty FK lists) are omitted. Use `--format json` to write `.json` files with the same structure.
|
|
50
126
|
|
|
51
127
|
```yaml
|
|
52
128
|
name: main
|
|
@@ -82,41 +158,46 @@ tables:
|
|
|
82
158
|
- id
|
|
83
159
|
```
|
|
84
160
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
Requires Python 3.11+ and [uv](https://github.com/astral-sh/uv).
|
|
161
|
+
Without `--output-dir`, `extract` prints a single `Catalog` document to stdout instead — the same schema shape nested under a `schemas` list, with the catalog name as a top-level field:
|
|
88
162
|
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
163
|
+
```yaml
|
|
164
|
+
name: prod_catalog
|
|
165
|
+
schemas:
|
|
166
|
+
- name: main
|
|
167
|
+
comment: Main production schema
|
|
168
|
+
tags:
|
|
169
|
+
env: prod
|
|
170
|
+
tables: [...]
|
|
93
171
|
```
|
|
94
172
|
|
|
95
|
-
|
|
173
|
+
## CLI Usage
|
|
96
174
|
|
|
97
|
-
```
|
|
98
|
-
|
|
175
|
+
```
|
|
176
|
+
databricks-schema [OPTIONS] COMMAND [ARGS]...
|
|
99
177
|
```
|
|
100
178
|
|
|
101
|
-
|
|
179
|
+
`extract`, `diff`, `generate-sql`, and `diff-files` print progress messages (e.g. `Extracting catalog 'X'...`) to stderr as they run. Pass `--quiet` / `-q` to suppress them;
|
|
180
|
+
results and errors are unaffected.
|
|
102
181
|
|
|
103
|
-
|
|
182
|
+
### `list-catalogs`
|
|
183
|
+
|
|
184
|
+
List all accessible catalogs:
|
|
104
185
|
|
|
105
186
|
```bash
|
|
106
|
-
|
|
107
|
-
export DATABRICKS_TOKEN=<your-personal-access-token>
|
|
187
|
+
databricks-schema list-catalogs
|
|
108
188
|
```
|
|
109
189
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
You can also pass credentials directly as flags (see `--host` / `--token` below).
|
|
190
|
+
### `list-schemas`
|
|
113
191
|
|
|
114
|
-
|
|
192
|
+
List schemas in a catalog:
|
|
115
193
|
|
|
116
|
-
```
|
|
117
|
-
databricks-schema
|
|
194
|
+
```bash
|
|
195
|
+
databricks-schema list-schemas <catalog>
|
|
118
196
|
```
|
|
119
197
|
|
|
198
|
+
Both print one name per line by default. Pass `--format json` / `-f json` (or `--format yaml`) to
|
|
199
|
+
get the names as a JSON array or YAML list instead.
|
|
200
|
+
|
|
120
201
|
### `extract`
|
|
121
202
|
|
|
122
203
|
Extract all schemas from a catalog to YAML files:
|
|
@@ -125,7 +206,11 @@ Extract all schemas from a catalog to YAML files:
|
|
|
125
206
|
databricks-schema extract <catalog> --output-dir ./schemas/
|
|
126
207
|
```
|
|
127
208
|
|
|
128
|
-
|
|
209
|
+
Print to stdout instead of writing files (no `--output-dir`) — the catalog and its schemas are printed as a single `Catalog` document (`name` + `schemas: [...]`):
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
databricks-schema extract <catalog>
|
|
213
|
+
```
|
|
129
214
|
|
|
130
215
|
Extract specific schemas only:
|
|
131
216
|
|
|
@@ -133,16 +218,17 @@ Extract specific schemas only:
|
|
|
133
218
|
databricks-schema extract <catalog> --schema main --schema raw --output-dir ./schemas/
|
|
134
219
|
```
|
|
135
220
|
|
|
136
|
-
|
|
221
|
+
Or extract a single schema or table by naming it directly, dotted onto the catalog (output keeps the same `Catalog`/`Schema` shape, just filtered down). This cannot be combined with `--schema`:
|
|
137
222
|
|
|
138
223
|
```bash
|
|
139
|
-
databricks-schema extract <catalog>
|
|
224
|
+
databricks-schema extract <catalog>.<schema>
|
|
225
|
+
databricks-schema extract <catalog>.<schema>.<table>
|
|
140
226
|
```
|
|
141
227
|
|
|
142
|
-
|
|
228
|
+
Include Unity Catalog tags in the output (extra API calls per entity; excluded by default):
|
|
143
229
|
|
|
144
230
|
```bash
|
|
145
|
-
databricks-schema extract <catalog> --output-dir ./schemas/ --
|
|
231
|
+
databricks-schema extract <catalog> --output-dir ./schemas/ --include-tags
|
|
146
232
|
```
|
|
147
233
|
|
|
148
234
|
Include additional metadata (`owner`, `storage_location`) in the output:
|
|
@@ -151,7 +237,7 @@ Include additional metadata (`owner`, `storage_location`) in the output:
|
|
|
151
237
|
databricks-schema extract <catalog> --output-dir ./schemas/ --include-metadata
|
|
152
238
|
```
|
|
153
239
|
|
|
154
|
-
Control the number of parallel workers (default: 4):
|
|
240
|
+
Control the number of parallel workers (default: 4), useful for large schemas with many tags:
|
|
155
241
|
|
|
156
242
|
```bash
|
|
157
243
|
databricks-schema extract <catalog> --output-dir ./schemas/ --workers 8
|
|
@@ -165,38 +251,51 @@ Compare the live catalog against previously extracted schema files (format auto-
|
|
|
165
251
|
databricks-schema diff <catalog> ./schemas/
|
|
166
252
|
```
|
|
167
253
|
|
|
254
|
+
Exits with code `0` if no differences are found, `1` if there are — making it suitable for CI pipelines. Output example:
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
~ Schema: main [MODIFIED]
|
|
258
|
+
~ Table: users [MODIFIED]
|
|
259
|
+
~ Column: score [MODIFIED]
|
|
260
|
+
data_type: 'int' -> 'double'
|
|
261
|
+
+ Column: phone [ADDED]
|
|
262
|
+
+ Table: events [ADDED]
|
|
263
|
+
- Schema: legacy [REMOVED]
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Markers: `+` added in catalog, `-` removed from catalog, `~` modified.
|
|
267
|
+
|
|
268
|
+
Or compare two live catalogs directly, e.g. dev against prod. The second argument is treated as a directory if one exists at that path, otherwise as a catalog name:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
databricks-schema diff dev_catalog prod_catalog
|
|
272
|
+
```
|
|
273
|
+
|
|
168
274
|
Compare specific schemas only:
|
|
169
275
|
|
|
170
276
|
```bash
|
|
171
277
|
databricks-schema diff <catalog> ./schemas/ --schema main --schema raw
|
|
172
278
|
```
|
|
173
279
|
|
|
174
|
-
|
|
280
|
+
Include Unity Catalog tags in the comparison (excluded by default):
|
|
175
281
|
|
|
176
282
|
```bash
|
|
177
|
-
databricks-schema diff <catalog> ./schemas/ --
|
|
283
|
+
databricks-schema diff <catalog> ./schemas/ --include-tags
|
|
178
284
|
```
|
|
179
285
|
|
|
180
|
-
Include
|
|
286
|
+
Include `owner` in the comparison (excluded by default):
|
|
181
287
|
|
|
182
288
|
```bash
|
|
183
289
|
databricks-schema diff <catalog> ./schemas/ --include-metadata
|
|
184
290
|
```
|
|
185
291
|
|
|
186
|
-
|
|
292
|
+
Get the same comparison as structured JSON or YAML instead of the `+`/`-`/`~` tree (exit codes unchanged) — useful for scripts or agents:
|
|
187
293
|
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
~ Column: score [MODIFIED]
|
|
192
|
-
data_type: 'int' -> 'double'
|
|
193
|
-
+ Column: phone [ADDED]
|
|
194
|
-
+ Table: events [ADDED]
|
|
195
|
-
- Schema: legacy [REMOVED]
|
|
294
|
+
```bash
|
|
295
|
+
databricks-schema diff <catalog> ./schemas/ --format json
|
|
296
|
+
databricks-schema diff <catalog> ./schemas/ --format yaml
|
|
196
297
|
```
|
|
197
298
|
|
|
198
|
-
Markers: `+` added in catalog, `-` removed from catalog, `~` modified.
|
|
199
|
-
|
|
200
299
|
### `generate-sql`
|
|
201
300
|
|
|
202
301
|
Generate Databricks Spark SQL statements to bring the live catalog in line with local schema files (format auto-detected, YAML or JSON, not mixed). Statements are printed to stdout by default:
|
|
@@ -223,13 +322,13 @@ Filter to specific schemas:
|
|
|
223
322
|
databricks-schema generate-sql <catalog> ./schemas/ --schema main --schema raw
|
|
224
323
|
```
|
|
225
324
|
|
|
226
|
-
|
|
325
|
+
Include Unity Catalog tags in the comparison (excluded by default):
|
|
227
326
|
|
|
228
327
|
```bash
|
|
229
|
-
databricks-schema generate-sql <catalog> ./schemas/ --
|
|
328
|
+
databricks-schema generate-sql <catalog> ./schemas/ --include-tags
|
|
230
329
|
```
|
|
231
330
|
|
|
232
|
-
Include
|
|
331
|
+
Include `owner` in the comparison (excluded by default):
|
|
233
332
|
|
|
234
333
|
```bash
|
|
235
334
|
databricks-schema generate-sql <catalog> ./schemas/ --include-metadata
|
|
@@ -243,28 +342,28 @@ Validate local schema files for structural integrity (no Databricks connection n
|
|
|
243
342
|
databricks-schema validate ./schemas/
|
|
244
343
|
```
|
|
245
344
|
|
|
345
|
+
Pass `--format json` or `--format yaml` for an `{"issues": [...]}` document instead of `OK`/`ERROR:` text.
|
|
346
|
+
|
|
246
347
|
### `diff-files`
|
|
247
348
|
|
|
248
|
-
Compare two local directories of schema files (no Databricks connection needed)
|
|
349
|
+
Compare two local directories of schema files (no Databricks connection needed). Same output,
|
|
350
|
+
exit codes, `--format json`/`yaml`, and `--schema` / `--include-metadata` flags as `diff`:
|
|
249
351
|
|
|
250
352
|
```bash
|
|
251
353
|
databricks-schema diff-files ./schemas-prod/ ./schemas-test/
|
|
252
354
|
```
|
|
253
355
|
|
|
254
|
-
### `
|
|
356
|
+
### `json-schema`
|
|
255
357
|
|
|
256
|
-
|
|
358
|
+
Print the JSON Schema for one of the CLI's structured output shapes — no Databricks connection
|
|
359
|
+
needed. Useful before parsing `--format json`/`yaml` output (or `extract`'s output)
|
|
360
|
+
programmatically. Add `--format yaml` to render the schema itself as YAML:
|
|
257
361
|
|
|
258
362
|
```bash
|
|
259
|
-
databricks-schema
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
List schemas in a catalog:
|
|
265
|
-
|
|
266
|
-
```bash
|
|
267
|
-
databricks-schema list-schemas <catalog>
|
|
363
|
+
databricks-schema json-schema catalog # extract's stdout Catalog document
|
|
364
|
+
databricks-schema json-schema schema # one per-schema extract file
|
|
365
|
+
databricks-schema json-schema diff # diff / diff-files --format json/yaml
|
|
366
|
+
databricks-schema json-schema validate # validate --format json/yaml
|
|
268
367
|
```
|
|
269
368
|
|
|
270
369
|
## Python Library Usage
|
|
@@ -274,14 +373,14 @@ See also the [`examples/`](examples/) directory for standalone scripts.
|
|
|
274
373
|
```python
|
|
275
374
|
from pathlib import Path
|
|
276
375
|
from databricks_schema import CatalogExtractor, catalog_to_yaml, schema_from_yaml
|
|
277
|
-
from databricks_schema import diff_catalog_with_dir, diff_schemas, schema_diff_to_sql
|
|
376
|
+
from databricks_schema import diff_catalog_with_dir, diff_catalogs, diff_schemas, schema_diff_to_sql
|
|
278
377
|
|
|
279
378
|
# Extract using configured auth (max_workers controls parallel table extraction)
|
|
280
379
|
extractor = CatalogExtractor(max_workers=4)
|
|
281
380
|
catalog = extractor.extract_catalog("my_catalog", schema_filter=["main", "raw"])
|
|
282
381
|
|
|
283
|
-
#
|
|
284
|
-
catalog = extractor.extract_catalog("my_catalog", include_tags=
|
|
382
|
+
# Include Unity Catalog tags (extra API calls per entity; excluded by default)
|
|
383
|
+
catalog = extractor.extract_catalog("my_catalog", include_tags=True)
|
|
285
384
|
|
|
286
385
|
# Include additional metadata (owner, storage_location)
|
|
287
386
|
catalog = extractor.extract_catalog("my_catalog", include_metadata=True)
|
|
@@ -299,6 +398,10 @@ if result.has_changes:
|
|
|
299
398
|
for schema_diff in result.schemas:
|
|
300
399
|
print(schema_diff.name, schema_diff.status)
|
|
301
400
|
|
|
401
|
+
# Compare two live catalogs directly
|
|
402
|
+
prod_catalog = extractor.extract_catalog("prod_catalog")
|
|
403
|
+
result = diff_catalogs(live=catalog, stored=prod_catalog)
|
|
404
|
+
|
|
302
405
|
# Compare two Schema objects directly
|
|
303
406
|
stored = schema_from_yaml(open("schemas/main.yaml").read())
|
|
304
407
|
diff = diff_schemas(live=catalog.schemas[0], stored=stored)
|
|
@@ -307,16 +410,3 @@ diff = diff_schemas(live=catalog.schemas[0], stored=stored)
|
|
|
307
410
|
sql = schema_diff_to_sql("my_catalog", diff, stored_schema=stored, allow_drop=False)
|
|
308
411
|
print(sql)
|
|
309
412
|
```
|
|
310
|
-
|
|
311
|
-
## Development
|
|
312
|
-
|
|
313
|
-
```bash
|
|
314
|
-
# Run tests
|
|
315
|
-
uv run pytest
|
|
316
|
-
|
|
317
|
-
# Lint
|
|
318
|
-
uv run ruff check databricks_schema/ tests/
|
|
319
|
-
|
|
320
|
-
# Format
|
|
321
|
-
uv run ruff format databricks_schema/ tests/
|
|
322
|
-
```
|