Generate SQL and notebooks
Generate a script from a version
A version’s script builds that version of the schema in a real database. It creates the database schemas, tables, keys, indexes, constraints, views, procedures, and functions in the right order. For Databricks and Fabric Lakehouse it is a PySpark notebook instead of a SQL file.
In the app: Data Model › Schemas › your schema › Versions › a version › Generate Script
Before you start¶
- Create a version that contains the changes you want to deploy. Scripts are generated from versions, not from the live schema. See How schema versioning works.
- Check the schema’s dialect. The script uses the dialect the schema had when the version was created.
- Generating is disabled while your organization is in read-only mode.
Steps¶
- Open the version.
- In the picker at the top right, choose a script type. See Script types below.
- Click
Generate Script. The dialog opens and showsValidating schema objects...while Kenseme checks the version against the dialect. - Read any errors (red) and warnings (yellow). Each names the object and the problem. Errors don’t block generation, but fix them in the schema and create a new version if you want a script that runs cleanly.
- If the dialog shows an
Environmentsection, pick the target environment for the schema and for any source schemas it reads from. See Environments below. - Set the options. All three are off by default:
Include Foreign Key Constraints. Not shown forLoad Script.Include DROP statements at top of script. The drops are commented out; you uncomment them yourself.Validate script with AI agent. Counts toward your AI usage.
- Click
Generate. The dialog showsGenerating script..., thenValidating with AI agent...if you asked for validation. - Review the result:
Lines,Size, and the AI validation findings. - Click
Downloadto save the file, orSave to Fabricfor a Fabric Lakehouse notebook.Closediscards the result.
To stop a long generation or validation, click Cancel, then Yes, Cancel. Continue resumes waiting.
Script types¶
| Type | Contains |
|---|---|
Full Script |
Every table, index, constraint, view, procedure, and function. |
Create Objects |
Tables, indexes, constraints, and the views, procedures, and functions you wrote. Leaves out Generated Objects. |
Load Script |
Only the Generated Objects: the load views, procedures, and scripts a Pipeline produced. Run it after Create Objects. |
Spark Schemas |
Databricks and Fabric Lakehouse only. A notebook with a PySpark StructType for every table and view. |
Spark Schemas has no options: it only emits StructType definitions, so foreign keys, drops, and AI validation don’t apply.
What the script contains¶
A SQL script runs in this order:
- A header comment with the schema, version, dialect, time, and your name.
- The commented-out
DROPblock, if you asked for one. - The
z_blaze_versiontracking table. CREATE SCHEMAfor every database schema the objects use (skipped if it already exists).- Native enum types, on dialects that support them.
- Tables. Tables with no columns are skipped.
- Primary keys, on dialects that need them added separately (Fabric Warehouse).
- Indexes.
- Check constraints for enum columns that use the
CHECKstrategy. - Foreign keys, if you included them.
- Views, then stored procedures, then functions. Within each group, an object comes after the objects it depends on.
- A row inserted into
z_blaze_versionrecording this deployment.
Only the view, procedure, and function scripts written in the version’s dialect are included. Objects without one are skipped, and the pre-check warns you about each.
For what a notebook contains, see PySpark notebooks.
Environments¶
If the schema has environments, or its Pipelines read from other schemas, the dialog shows an Environment section. Pick the environment you are deploying to for the destination schema and each source schema.
- Kenseme adds
CREATE SCHEMAstatements for the schema names those environments use. - It fills in environment-specific object names inside procedures Kenseme generated (for example, Pipeline load procedures).
- It does not rewrite schema names you typed into your own views, procedures, or functions. Those are emitted as written.
File names¶
Downloads are named <schema>_<version>_<dialect>_<type>, for example:
Sales_v1.2.0_SqlServer_Full.sqlSales_v1.2.0_Postgres_CreateObjects.sqlSales_v1.2.0_Databricks_Load.ipynbSales_v1.2.0_FabricLakehouse_SparkSchemas.ipynb
Save a notebook to Fabric¶
For Fabric Lakehouse schemas, the result has a Save to Fabric button in addition to Download. It writes the notebook straight into a Fabric workspace.
- Click
Save to Fabric. - In
Choose a Fabric folder, pick the Fabric credential, workspace, and folder, then clickChoose folder. - In
Save notebook to Fabric, confirm or change theNotebook name(up to 256 characters). - Click
Save to Fabric.
A toast confirms Notebook saved to Fabric at <workspace and folder>. The dialog stays open, so you can also download a copy. You choose the credential each time, so you can deploy the same version to dev, test, and production workspaces.
Note:
Save to Fabricneeds a Fabric credential set up for your organization. Ask an organization admin if the folder picker has nothing to choose from.