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 schemaVersionsa versionGenerate Script

[screenshot]
The Generate Full Script dialog with the dialect badge, the Environment section, and the three option checkboxes.

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

  1. Open the version.
  2. In the picker at the top right, choose a script type. See Script types below.
  3. Click Generate Script. The dialog opens and shows Validating schema objects... while Kenseme checks the version against the dialect.
  4. 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.
  5. If the dialog shows an Environment section, pick the target environment for the schema and for any source schemas it reads from. See Environments below.
  6. Set the options. All three are off by default:
    • Include Foreign Key Constraints. Not shown for Load 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.
  7. Click Generate. The dialog shows Generating script..., then Validating with AI agent... if you asked for validation.
  8. Review the result: Lines, Size, and the AI validation findings.
  9. Click Download to save the file, or Save to Fabric for a Fabric Lakehouse notebook. Close discards 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:

  1. A header comment with the schema, version, dialect, time, and your name.
  2. The commented-out DROP block, if you asked for one.
  3. The z_blaze_version tracking table.
  4. CREATE SCHEMA for every database schema the objects use (skipped if it already exists).
  5. Native enum types, on dialects that support them.
  6. Tables. Tables with no columns are skipped.
  7. Primary keys, on dialects that need them added separately (Fabric Warehouse).
  8. Indexes.
  9. Check constraints for enum columns that use the CHECK strategy.
  10. Foreign keys, if you included them.
  11. Views, then stored procedures, then functions. Within each group, an object comes after the objects it depends on.
  12. A row inserted into z_blaze_version recording 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 SCHEMA statements 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.sql
  • Sales_v1.2.0_Postgres_CreateObjects.sql
  • Sales_v1.2.0_Databricks_Load.ipynb
  • Sales_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.

  1. Click Save to Fabric.
  2. In Choose a Fabric folder, pick the Fabric credential, workspace, and folder, then click Choose folder.
  3. In Save notebook to Fabric, confirm or change the Notebook name (up to 256 characters).
  4. 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 Fabric needs a Fabric credential set up for your organization. Ask an organization admin if the folder picker has nothing to choose from.