Modification Tools

The Tier 3 tools create and change the files in your schema package: tables, views, scripts, templates and settings. Each one checks what it is about to write before anything changes on disk.

By the SchemaSmith Team · Last reviewed

Ask Forge modification tools

Tools that create or change files in your schema package.

How Modify Tools Write

The Tier 3 tools change files on disk: table, view and object definitions, SQL scripts, Product.json and Template.json. None of them connects to a database. Every change to a package file follows the same rules:

  • Whole files or nothing. Each file is written to a temporary file beside the target and only then put in its place, so a write cut short by a full disk or a stopped process leaves the file as it was.
  • No backup copies. The tools keep no copy of the version they replace. Keep the package in source control: that is where an earlier version lives, and where you review each change before you commit it.
  • Nothing written over a change you have not seen. A tool reads its files, asks you to confirm, then writes. If a file changes while the question is open, because you saved it in SchemaHammer, switched branches, or another tool wrote it, the tool writes nothing, names the file, and asks you to run it again.
  • Refused before written. A value SchemaSmith's own rules refuse, such as a pattern, a length limit, a required value left blank, or a property of another platform, is refused before anything is written, and so is an error from SchemaQuench's own consistency checks. The message uses the words SchemaQuench --Validate would use. A warning from those checks is written, and the result says so. Only what the call introduces counts, so a file that already breaks a rule still takes an unrelated change, and the call that repairs it is never blocked.
  • Several files, all checked first. A tool that writes more than one file, such as a rename that updates every table whose foreign key names the renamed table, checks every file before it asks you. If something fails after the first write, the call returns an error that lists what was written and what was not.

Names that become files

A schema package is checked out on Windows, Linux and macOS, so a name a tool turns into a file or folder has to be valid on all three. On every operating system, these tools refuse a new name that:

  • contains any of < > : " / \ | ? * or a control character;
  • is a name Windows reserves for a device, such as CON, NUL, COM1 or LPT1, with or without an extension;
  • ends with a dot or a space.

The rule applies to schemasmith_create_product (when no path is given, so the name becomes the folder), schemasmith_create_template, schemasmith_add_folder, schemasmith_save_script and schemasmith_create_package. Nothing is written when a name is refused, and the message says which rule it breaks. It applies to new names only. Names inside the JSON, such as a table's Name, are not restricted, because tables, views and the other typed objects are stored under an encoded file name.

Confirmation

A Modify tool is confirmed before it writes, and how depends on where you call it:

  • The MCP server. The call's arguments must include confirm: true. Without it, nothing runs, and the reply says the call needs confirmation. For a tool reached through schemasmith_execute_tool, confirm: true goes beside tool_name, not inside the inner arguments. MCP Server Setup covers it in full.
  • The ask-forge CLI. The command shows what it is about to write and asks you to confirm. --yes, or -y, answers yes for that one command. With no terminal to answer the prompt, the command stops with an error and writes nothing, so a script passes --yes. The agent.confirmationLevel setting decides which commands ask for confirmation. With always, the default, it asks before Modify and External commands. With external, it asks before External commands only. With never, it does not ask. Configuration describes the setting.
  • The REPL. The conversational agent can run a Modify tool only at the operator trust level, and it asks you before each one while confirmTier3 is on, as it is by default. Trust Levels explains each level.

Tables and Columns

Create tables, change them, and rename them along with everything that names them. On the CLI, each tool is a kebab-case subcommand and each parameter a kebab-case option, and --help on any command lists every option.

schemasmith_apply_change

The general-purpose table editor. Each call makes one change to one table's JSON file. It can add, modify or remove a column, an index, a foreign key or a check constraint, and it can set the table's description or its Online Apply setting. On SQL Server and PostgreSQL it can also add, modify or remove a statistic. On SQL Server it can also set or remove a table's full-text index. A SQL Server table also takes spatial and JSON indexes, edge constraints, a ledger view and change data capture. Property names are the schema model's own, the same names your table files already use. Letter case and a few common synonyms, such as Type for DataType, are accepted and rewritten to the model's spelling, and any other unknown name is refused rather than written. A change that would leave an index or a foreign key naming a column that does not exist is refused, and nothing is written.

ParameterRequiredDescription
change_typeYesThe change, such as add_column, modify_index, remove_fk, set_fulltext or set_description. The command's help lists every change type
tableYesThe table to change
definitionYesThe change, as JSON, with the property names the table file uses, such as DataType and Nullable for a column
variantNoThe VariantName of one conditional variant, when more than one declaration shares a name. Without it, a name that matches more than one declaration is refused as ambiguous
ask-forge apply-change --change-type add_column --table Customers `
  --definition <json>
ask-forge apply-change --change-type add_column --table Customers \
  --definition <json>

schemasmith_create_table

Creates a new table file with the platform's identifier quoting, its default schema, and a primary key generated to match the conventions of the template's existing tables, unless you mark one of your own columns PrimaryKey. Columns use the same property names and the same leniency as schemasmith_apply_change, and any column property can be set inline. On MySQL and MariaDB a table has no schema, because the template's database identification script chooses the database, so the tool writes no Schema and refuses a schema you pass. Inside a schema template, the table is written without a schema, and the engine resolves it for each tenant. A table name longer than the platform allows is refused.

ParameterRequiredDescription
tableYesThe table's bare name
schemaNoSQL Server and PostgreSQL only. Defaults to dbo or public
columnsNoThe column definitions, as a JSON array
prevent_dropNoNever drop the table for being absent from the package
variant_nameNoMake the table a conditional variant with this name
should_apply_expressionNoThe SQL condition that decides whether the variant applies to a target
merge_typeNoStart the table with a data delivery using this merge type
match_columnsNoThe delivery's match columns. Defaults to the primary key
content_fileNoThe delivery's data file, relative to the Table Data folder
content_encodingNoJson, the default, or Xml
descriptionNoThe table's description
online_applyNoThe table's own Off, Prefer or Require, overriding the deployment's setting
enable_cdcNoSQL Server only. Turn change data capture on or off for the table
cdc_index_nameNoSQL Server only. The unique index change data capture identifies rows by
ask-forge create-table --table Orders --description "Customer orders"

schemasmith_apply_generated_schema

Writes the tables schemasmith_generate_schema produced into the template, one JSON file per table. Every table is checked before any is written, so one refused table means none are written. A result from an older version of schemasmith_generate_schema, which used property names SchemaSmith does not read, is refused with a request to generate it again. Schema Generation describes the step before this one.

ParameterRequiredDescription
schemaYesThe generated-schema JSON that schemasmith_generate_schema returned
product_pathNoThe product to write into. Defaults to the loaded product
templateNoThe template to write into. Defaults to the selected template
ask-forge apply-generated-schema --schema <json>

schemasmith_rename_table

Renames a table and the file that holds it, and sets OldName so SchemaQuench renames the table at deployment and keeps its data. Every foreign key that points at the table follows the rename, and so do the expressions that name the table, such as a merge filter's subquery. The confirmation and the result list each expression changed, before and after. Script files that mention the table are listed for you to update. The rename is refused before it asks you when a table of the new name already exists. A change of letter case alone counts as a rename, because PostgreSQL treats Customer and customer as two tables.

ParameterRequiredDescription
tableYesThe current name
new_nameYesThe new name
ask-forge rename-table --table Orders --new-name SalesOrders

schemasmith_rename_column

Renames a column and sets OldName, so SchemaQuench renames the column at deployment instead of dropping and recreating it. The rename follows the column through the table's indexes, foreign keys, statistics, full-text indexes, data delivery match columns and partition column, through every foreign key elsewhere in the package that references it, and through the table's own expressions, such as check constraints, computed columns and filters. A name is rewritten only where it stands whole, never inside a string or a comment, and the result lists each expression before and after. Script files that mention the column are listed for you to update.

ParameterRequiredDescription
tableYesThe table
columnYesThe current name
new_nameYesThe new name
ask-forge rename-column --table Customers --column Status --new-name State

Scripts and Migrations

Save SQL into the package's script folders, and turn a migration plan into files.

schemasmith_save_script

Writes a SQL script into one of the package's script folders, such as Before Scripts or Procedures, so that it deploys with the package. It replaces an existing script only when you ask it to, so a save cannot discard a script by accident. A new file name must pass the rule under Names that become files.

ParameterRequiredDescription
contentYesThe SQL
folderYesThe script folder, such as Procedures
filenameYesThe script's file name
overwriteNoReplace a script of the same name. Off by default
ask-forge save-script --folder Procedures --filename Orders.sql --content <sql>

schemasmith_save_migration

Writes a migration plan from schemasmith_plan_migration to disk: plan.md with the summary, migration.sql with the combined script, and a step-NN-<description>.sql file for each step. Without output_path, the files go in a new timestamped folder under Migrations/ in the product. It never writes over an earlier migration: if any of those files is already in the folder, it refuses before asking you. Each step file's name has every character Windows does not allow in a file name removed or replaced by -, on every operating system. schemasmith_plan_migration is one of the Read-Only Tools.

ParameterRequiredDescription
planYesThe migration plan JSON that schemasmith_plan_migration returned
output_pathNoThe folder to write to. Defaults to a new timestamped folder under Migrations/
ask-forge save-migration --plan <json>

Products and Templates

Start a package, add templates to it, and remove a template you no longer need.

schemasmith_create_product

Creates a new schema package: a folder holding Product.json, with the product's Name, its Platform and an optional MinimumVersion, and an empty Templates/ folder. The platform is required and cannot be changed later; a different platform means rebuilding the package. Without path, the package is created in a folder named after the product, inside the working directory. A folder that already holds a Product.json is refused rather than overwritten. The new product becomes the selected one, so schemasmith_create_template can follow straight away.

ParameterRequiredDescription
nameYesThe product's name
platformYesSqlServer, PostgreSQL, MySQL or MariaDb. Cannot be changed later
pathNoWhere to create the package. Defaults to a folder named after the product, in the working directory
minimum_versionNoThe oldest engine version the product supports. A target below it stops at pre-flight
ask-forge create-product --name Shop --platform PostgreSQL

schemasmith_create_template

Adds a template to the selected product: Templates/<name>/Template.json, holding only the template's Name, with the name added to the end of Product.json's TemplateOrder. TemplateOrder is deploy order, so pass first for a template the others depend on. The name is also the folder's name, so it must pass the rule under Names that become files. Until schemasmith_configure_template gives it an identification script, a new template targets nothing.

ParameterRequiredDescription
nameYesThe template's name, which is also its folder's name
firstNoPut the template first in TemplateOrder instead of last
ask-forge create-template --name Shared --first

schemasmith_delete_template

Deletes a whole template from the selected product: its folder, with every table and script in it, and every TemplateOrder entry that names it. The confirmation says how many tables go with it. The delete is refused, with nothing deleted, when removing the template would leave a foreign key naming a column that no longer exists, or when a file it would delete or change is read-only. A delete never falls back to the selected template; you always name the one to delete.

ParameterRequiredDescription
templateYesThe template's folder name, in any letter case
ask-forge delete-template --template Archive

Packages, Folders and Tokens

Package a product for deployment, register script folders, and manage script tokens.

schemasmith_create_package

Zips the whole product for deployment or hand-off: Product.json, every template or just the one you name, and, by default, the script folders. It packages a product that already exists, where schemasmith_create_product starts one. For a patch that holds only the objects that changed, use schemasmith_run_schema_shears, one of the External Tools.

ParameterRequiredDescription
nameYesThe ZIP's name, without .zip
output_pathNoThe folder to write to. Defaults to the product folder
include_scriptsNoInclude the script folders. On by default; turn it off for a tables-only package
templateNoPackage this template only
ask-forge create-package --name shop-1.4.0

schemasmith_add_folder

Creates a script folder and registers it in Product.json or Template.json with a deployment slot. Leave the slot out and the tool infers it from the folder name. A template that declares no folders deploys the engine's default folder set, so registering the first folder there writes those defaults first, so nothing that deployed before stops deploying. A folder that is already registered is refused, compared without letter case. With parent, the folder is created as a subfolder on disk, without a registration of its own, and deploys with its parent.

ParameterRequiredDescription
folderYesThe folder to create
parentNoCreate the folder inside this existing folder, unregistered
quench_slotNoA template folder takes Setup, Before, Objects, BetweenTablesAndKeys, AfterTablesScripts, AfterTablesObjects, TableData or After; a product folder takes Before or After. Inferred from the folder name when left out
levelNoproduct or template. Defaults to the current context
object_typeNoThe type of object the folder's scripts create, such as Views or Procedures
server_to_quenchNoSQL Server product folders only. Primary, Secondary or Both
should_apply_expressionNoA SQL condition that decides at deployment whether the folder deploys
ask-forge add-folder --folder Reports --quench-slot After

schemasmith_manage_tokens

Manages the {{TokenName}} placeholders SchemaQuench replaces at deployment. list shows the tokens in Product.json and the selected template's Template.json. add, update and remove change one token. scan finds where a token is used, or, in orphans mode, references to tokens that are not defined. suggest looks through scripts for hard-coded values, such as database or server names, that could become tokens. A value can be one of the special token types, named by a prefix such as <*Query*> or <*File*>. The value of a token whose name looks secret is shown as ***. A change that would stop the package loading is refused, and nothing is written.

ParameterRequiredDescription
actionYeslist, add, update, remove, scan or suggest
levelNoproduct or template. Required for add, update and remove
token_nameNoThe token's name, without the braces. Required for add, update and remove, and for scan in token mode
token_valueNoThe token's value. Required for add and update
scan_modeNotoken, the default, or orphans
ask-forge manage-tokens --action scan --scan-mode orphans

Product and Template Settings

Set what a product and its templates deploy, and which drops and rebuilds a deployment may make. Each of these tools changes only the properties you supply, and clear: true removes the properties you name instead, so they go back to being inherited or unset.

schemasmith_configure_product

Sets product-level properties in Product.json: the validation, baseline-validation and version-stamp scripts, the branch-name settings behind the {{BranchName}} token, the template order, the minimum version, whether indexes the package does not declare are dropped, and how SchemaTongs routes check constraints. A template order that names a template the product does not have is refused, and nothing is written.

ParameterRequiredDescription
template_orderNoThe template names in deploy order, comma-separated. Only the listed templates deploy
minimum_versionNoThe oldest engine version the product supports
validation_scriptNoSQL run once per server, before any database work, to check a precondition
baseline_validation_scriptNoSQL run once, after the validation script and before any template, to check a precondition
version_stamp_scriptNoSQL run after a successful deployment to record the version on the target
branch_name_fileNoA file whose contents give the branch name behind {{BranchName}}
before_branch_name_maskNoText trimmed from the front of that file's contents
after_branch_name_maskNoText trimmed from the end of that file's contents
drop_unknown_indexesNoDrop indexes on the target that the package does not declare
check_constraint_styleNoColumnLevel or TableLevel, how SchemaTongs routes check constraints. SQL Server and PostgreSQL only
clearNoRemove the properties you name instead of setting them
ask-forge configure-product --template-order Shared,Main

schemasmith_configure_template

Sets template-level properties in the selected template's Template.json: how it finds its target databases, whether it deploys once per schema, how it handles failures and parallel targets, its validation and version-stamp scripts, index handling, and, on SQL Server, which replica it deploys to. schema_identification_script, on SQL Server and PostgreSQL, turns the template into a schema template: the whole template deploys once for each schema the script returns, with that schema available as {{SchemaName}}. The tool refuses that change while an object in the template names a schema of its own, and lists each one.

ParameterRequiredDescription
database_identification_scriptNoSQL returning the databases the template deploys to
identification_databaseNoThe database that script runs against, when it is not the platform's own
schema_identification_scriptNoSQL Server and PostgreSQL only. SQL returning one schema per row, which makes the template a schema template
create_schema_if_missingNoSchema templates only. Create a schema the script returns that does not exist yet
require_at_least_one_targetNoFail the run when the identification script returns no databases. On by default
allow_parallelNoSchema templates only. Deploy the template's schemas in parallel. On by default; off runs them one at a time
continue_on_database_failureNoCarry on with the remaining databases when one fails
continue_on_schema_failureNoSchema templates only. Carry on with the remaining schemas when one fails
skip_if_read_onlyNoSkip a read-only target, such as a replica, rather than fail against it
baseline_validation_scriptNoSQL checking a precondition before the template runs
version_stamp_scriptNoSQL run after the template deploys, to record the version on the target
index_only_table_quenchesNoApply only index changes to the template's tables
update_fill_factorNoSQL Server and PostgreSQL only. Apply fill-factor changes to existing indexes. On by default; such a change rebuilds the index
drop_unknown_indexesNoDrop indexes on the target that the package does not declare
server_to_quenchNoSQL Server only. Primary, Secondary or Both
cdc_filegroupNoSQL Server only. The default filegroup for the template's change data capture tables
cdc_supports_net_changesNoSQL Server only. Whether change data capture supports net changes, by default
clearNoRemove the properties you name instead of setting them
ask-forge configure-template --database-identification-script "SELECT 'Shop'"

schemasmith_configure_drop_policy

Sets the drop-on-removal flags, Drop*RemovedFromProduct, at the product, template or table tier. They decide whether an object removed from the package is dropped from the target at the next deployment. The flags cascade from product to template to table, and an explicit false at any tier suppresses drops below it. prevent_drop, at the table tier only, protects one table from being dropped by absence.

ParameterRequiredDescription
tierYesproduct, template or table
templateNoThe template, for the template and table tiers
tableNoThe table, for the table tier
drop_tablesNoDrop tables removed from the package. Product and template tiers only
drop_columnsNoDrop columns removed from the package
drop_foreign_keysNoDrop foreign keys removed from the package
drop_check_constraintsNoDrop check constraints removed from the package
drop_indexesNoDrop indexes removed from the package
drop_statisticsNoSQL Server and PostgreSQL only. Drop statistics removed from the package
drop_exclude_constraintsNoPostgreSQL only. Drop exclude constraints removed from the package
drop_schema_bound_dependentsNoSQL Server only. Drop the schema-bound dependents of a changed or removed object. Product and template tiers only
drop_periodsNoMariaDB only, table tier only. Drop application-time periods removed from the package
prevent_dropNoTable tier only. Never drop the table for being absent from the package
clearNoRemove the flags you name, so the tier inherits from the one above
ask-forge configure-drop-policy --tier product --drop-columns

schemasmith_configure_rebuild_policy

Sets the rebuild-trigger policy at the product, template or table tier: NEVER, ALWAYS, or THRESHOLD with a drift threshold, plus an optional trigger when column order no longer matches the definition. Unlike the drop flags, the policy does not cascade field by field. The winning tier's policy applies whole, so a table's policy inherits nothing from the template or product above it.

ParameterRequiredDescription
tierYesproduct, template or table
templateNoThe template, for the template and table tiers
tableNoThe table, for the table tier
modeNoNEVER, ALWAYS or THRESHOLD
thresholdNoThe drift that triggers a rebuild under THRESHOLD
on_order_mismatchNoRebuild when column order no longer matches the definition
clearNoRemove the tier's policy, so it inherits from the tier above
ask-forge configure-rebuild-policy --tier product --mode ALWAYS

Table Settings

Configure a table's data delivery, and the settings that particular engines add to a table, without rewriting the table.

schemasmith_configure_data_delivery

Sets up data delivery on a table: how SchemaQuench merges the table's reference data at deployment. It writes the merge type, match columns, merge filter, trigger handling and content file under the table's DataDelivery key. For Insert/Update and Insert/Update/Delete, match columns you leave out are filled from the primary key. A merge that needs a key is refused when the table declares none: every merge type on SQL Server and PostgreSQL, and Insert/Update/Delete on MySQL and MariaDB. merge_type: None removes the delivery, or, with variant, removes only that variant.

ParameterRequiredDescription
tableYesThe table
merge_typeYesNone, Insert, Insert/Update or Insert/Update/Delete
match_columnsNoThe columns rows are matched on, comma-separated
merge_filterNoA SQL WHERE clause limiting which rows are merged
disable_triggersNoDisable triggers during the merge
content_fileNoThe data file, relative to the Table Data folder
content_encodingNoJson, the default, or Xml
variant_nameNoThe name of a conditional variant of the delivery
should_apply_expressionNoThe SQL condition for that variant. Required on every variant once there are two
variantNoAn existing variant to replace, or with None to remove
merge_disable_rulesNoPostgreSQL only. Disable rules during the merge
merge_update_descendentsNoPostgreSQL only. Carry the merge to descendant tables
time_zoneNoMySQL and MariaDB only. The time zone the content file's TIMESTAMP values were extracted in, as an offset such as +00:00
ask-forge configure-data-delivery --table Countries --merge-type Insert/Update

schemasmith_configure_partitioning MySQL and MariaDB

Sets or removes an existing table's partitioning in one call. The call declares the whole partitioning and replaces what the table had, so a partition you leave out is removed. To add one, pass the existing partitions as well as the new one. On a database where the table already exists, SchemaQuench applies one kind of change: RANGE or LIST partitions appended after the last one, when the last is not MAXVALUE. It refuses a changed method, expression, subpartitioning or HASH/KEY count, and a removed, moved or reordered partition, before touching the table, because repartitioning rewrites every row. A changed partition comment is reported and not applied, and removing the partitioning leaves a deployed table's partitions in place. The SYSTEM_TIME method and its options are MariaDB only and need a system-versioned table.

ParameterRequiredDescription
tableYesThe table
methodNoRANGE, LIST, HASH, KEY, their LINEAR and COLUMNS forms, or on MariaDB SYSTEM_TIME. Required unless you remove the partitioning
expressionNoThe partitioning expression, or the column list for KEY and the COLUMNS methods. Required for every method but SYSTEM_TIME
partition_countNoHow many partitions, for the hash and key methods and SYSTEM_TIME
partitionsNoThe partitions in order, as a JSON array, each with a name, values and comment
key_algorithmNoKEY and LINEAR KEY only. 1 or 2, the default
subpartition_methodNoRANGE and LIST only. Split each partition again by a hash or key method
subpartition_expressionNoThe subpartitioning expression or column list
subpartition_countNoSubpartitions in each partition
intervalNoMariaDB SYSTEM_TIME only. A new history partition per interval, such as 1 MONTH
starts_atNoMariaDB SYSTEM_TIME only, with interval. When the first interval starts
limitNoMariaDB SYSTEM_TIME only. A new history partition after this many history rows
autoNoMariaDB SYSTEM_TIME only, MariaDB 10.9.1 and later. MariaDB adds history partitions as they fill
removeNoRemove the table's partitioning
ask-forge configure-partitioning --table orders --method HASH `
  --expression id --partition-count 4
ask-forge configure-partitioning --table orders --method HASH \
  --expression id --partition-count 4

schemasmith_configure_periods MariaDB

Adds, updates or removes an application-time period (PERIOD FOR) on an existing table: a validity window between a start column and an end column, separate from system versioning. MariaDB allows one application-time period per table, so adding a second is refused. Whether a removed period is dropped at deployment is the drop_periods flag of schemasmith_configure_drop_policy, under Product and Template Settings.

ParameterRequiredDescription
tableYesThe table
periodYesThe period's name
start_columnNoThe column holding the start of the window. Needed to add a period
end_columnNoThe column holding the end of the window. Needed to add a period
removeNoRemove the named period
ask-forge configure-periods --table bookings --period valid_period `
  --start-column valid_from --end-column valid_to
ask-forge configure-periods --table bookings --period valid_period \
  --start-column valid_from --end-column valid_to

schemasmith_configure_policies PostgreSQL

Adds, updates or removes one row-level-security policy on an existing table, and turns the table's row-level security on or off. A policy is enforced only while row-level security is on, and row-level security with no policy that grants access hides every row from every role that does not bypass it: superusers, BYPASSRLS roles, and the owner unless the table forces row-level security. A call that leaves policies with row-level security off, or row-level security on with no policies, is written with a warning. A policy is identified by its name and its variant name together.

ParameterRequiredDescription
tableYesThe table
policyNoThe policy's name. Required for any policy change
variant_nameNoThe policy's variant name, which with its name identifies it
commandNoALL, SELECT, INSERT, UPDATE or DELETE
permissiveNoPERMISSIVE or RESTRICTIVE
rolesNoThe roles the policy applies to, comma-separated
using_expressionNoThe USING expression: which existing rows are visible
with_check_expressionNoThe WITH CHECK expression: which new rows are allowed
should_apply_expressionNoThe SQL condition for this variant. Required on every variant once there are two
row_level_securityNoTurn the table's row-level security on or off
removeNoRemove the identified policy
ask-forge configure-policies --table orders --row-level-security

Views

Create the view types that have a definition file of their own.

schemasmith_create_indexed_view SQL Server

Creates an indexed view definition file. The definition is the view's SELECT statement; SchemaQuench creates the view WITH SCHEMABINDING, so name each table by its two-part name. The view's stored Name and Schema are written in square brackets, the form SQL Server's own extraction writes, and the file is named with the plain values.

ParameterRequiredDescription
nameYesThe view's bare name
definitionYesThe view's SELECT statement. SchemaQuench adds WITH SCHEMABINDING
schemaNoDefaults to dbo
descriptionNoThe view's description
ask-forge create-indexed-view --name vw_Sales --definition <sql>

schemasmith_create_materialized_view PostgreSQL

Creates a materialized view definition file with its defining query and storage settings. with_data populates the view when it is created. Turn it off to create the view unpopulated and refresh it later, when the defining query is expensive.

ParameterRequiredDescription
nameYesThe view's bare name
definitionYesThe defining query
schemaNoDefaults to public
with_dataNoPopulate the view when it is created. On by default
tablespaceNoThe view's tablespace
access_methodNoThe table access method behind the view, such as heap
descriptionNoThe view's description
ask-forge create-materialized-view --name sales_summary --definition <sql>

Modeled Folder Objects

These tools write a typed JSON definition into a script folder: Enum Types/, Sequences/, Domain Types/ or Events/. Those folders also hold ordinary .sql scripts, and a new definition lands beside them without touching anything already there.

  • One object per file. Two conditional variants of one object are two files that share a Name, each with its own should_apply_expression. The variant_name becomes part of the file name, so you write a second variant by calling the tool again with another variant_name.
  • Gated by engine. Each tool runs only on the engines that read its folder, and refuses elsewhere rather than write a file nothing would read.
  • One object, one form. An object declared both as a typed definition and as a .sql script of the same name in the folder is refused before anything is written.

Each of the create tools also takes should_apply_expression, variant_name and description.

schemasmith_create_enum_type PostgreSQL

Creates an enum type (CREATE TYPE ... AS ENUM) in Enum Types/. The order of the labels is the declared order, and it matters, because PostgreSQL sorts an enum by declared position. A label the target does not have yet is added in its declared position at deployment. Removing or reordering a label the target already has is reported rather than applied, because it needs the type dropped and recreated.

ParameterRequiredDescription
nameYesThe type's bare name
valuesYesThe labels in order, as a JSON array or a comma-separated list
schemaNoDefaults to public
descriptionNoThe type's description
should_apply_expressionNoThe SQL condition for a conditional variant
variant_nameNoThe variant's name, which becomes part of the file name
ask-forge create-enum-type --name order_status --values draft,active,archived

schemasmith_create_sequence PostgreSQL and MariaDB

Creates a sequence (CREATE SEQUENCE) in Sequences/. SchemaQuench creates it, or alters an existing one in place, and never resets its current value. Only the values you supply are written, and the rest keep the engine's defaults. A MariaDB sequence name is not schema-qualified, so schema, persistence_type and description are refused on MariaDB.

ParameterRequiredDescription
nameYesThe sequence's bare name
data_typeNoThe storage type. Defaults to bigint
startNoThe value it starts with
incrementNoThe step between values
min_valueNoThe lowest value
max_valueNoThe highest value
cacheNoHow many values are cached
cycleNoWrap around on reaching a bound
schemaNoPostgreSQL only. Defaults to public
persistence_typeNoPostgreSQL only. Logged or Unlogged
descriptionNoPostgreSQL only. The sequence's description
should_apply_expressionNoThe SQL condition for a conditional variant
variant_nameNoThe variant's name, which becomes part of the file name
ask-forge create-sequence --name order_no --start 1000

schemasmith_create_domain_type PostgreSQL

Creates a domain type (CREATE DOMAIN) in Domain Types/, with its NOT NULL, DEFAULT and CHECK constraints. The data type and the collation are set when the domain is created. PostgreSQL cannot alter either, so a later change to either on a domain the target already has is refused, and the deployment fails until the definition matches or a migration script recreates the domain. The default can be changed in place.

ParameterRequiredDescription
nameYesThe type's bare name
data_typeYesThe underlying type, such as varchar(2)
not_nullNoReject NULL
defaultNoThe default expression
collationNoThe collation, when it differs from the base type's
check_constraintsNoThe check constraints, as a JSON array, each with a name and an expression
schemaNoDefaults to public
descriptionNoThe type's description
should_apply_expressionNoThe SQL condition for a conditional variant
variant_nameNoThe variant's name, which becomes part of the file name
ask-forge create-domain-type --name us_state --data-type "varchar(2)"

schemasmith_create_event MySQL and MariaDB

Creates a scheduled event (CREATE EVENT) in Events/. An event has no schema, so its name is its whole identity. A recurring event, EVERY, the default, takes an interval and optional start and end bounds; a one-shot event, AT, takes a run time. A field that belongs to the other kind is refused rather than dropped.

ParameterRequiredDescription
nameYesThe event's name
definitionYesThe SQL the scheduler runs
schedule_typeNoEVERY, the default, or AT
intervalNoHow often an EVERY event runs, such as 1 DAY. Required for EVERY
execute_atNoWhen an AT event runs. Required for AT
startsNoWhen an EVERY event starts
endsNoWhen an EVERY event ends
statusNoENABLE, DISABLE or DISABLE ON SLAVE
preserveNoKeep the event after its last run
time_zoneNoThe time zone the schedule's times are read in
sql_modeNoThe sql_mode the event body runs under
descriptionNoThe event's description
should_apply_expressionNoThe SQL condition for a conditional variant
variant_nameNoThe variant's name, which becomes part of the file name
ask-forge create-event --name purge_logs --definition <sql> --interval "1 DAY"

schemasmith_rename_modeled_object PostgreSQL, MySQL and MariaDB

Renames one of these objects: a PostgreSQL enum type or domain type, a PostgreSQL or MariaDB sequence, or a MySQL or MariaDB event. It writes the new Name into the definition and moves the file to match, for every conditional variant of the object unless variant narrows it to one. Calling a create tool again with the new name would leave two objects instead of one. These objects carry no OldName, so a deployment after the rename creates the new object and leaves the old one in place. For an event, SchemaQuench's DropEventsRemovedFromProduct setting, off by default (drop_removed_events in schemasmith_run_schema_quench's options), can remove it; otherwise drop the old object with a migration script.

ParameterRequiredDescription
object_typeYesenum_type, sequence, domain_type or event
nameYesThe current name, without a schema
new_nameYesThe new name, without a schema
schemaNoThe current schema, for the PostgreSQL objects. Defaults to public
variantNoRename only the variant with this VariantName
ask-forge rename-modeled-object --object-type enum_type `
  --name order_status --new-name order_state
ask-forge rename-modeled-object --object-type enum_type \
  --name order_status --new-name order_state

Shape. Strengthen. Succeed.

Free schema-as-code for SQL Server, PostgreSQL, MySQL, and MariaDB.

The source is on GitHub for anyone to read.

Get Started on GitHub