Table of Contents

SQL Generation

The foundry sql command generates CREATE DDL scripts from Velocity schema or database definition files without executing them against a live database. The output is written to a file or printed to stdout, making it suitable for audit trails, release management, and deployment workflows where DDL must be reviewed before execution.

Note

foundry sql still requires a connection to determine the correct DDL syntax for the target database engine. The connection is not used to execute any statements — only to determine platform-specific SQL dialect.


foundry sql schema

Generates CREATE DDL for all objects in a schema definition file.

foundry sql schema [options]
Option Short Description
--datasource <FILE> -d Datasource JSON file
--conn <STRING> -c ADO.NET connection string
--db <TYPE> -b Database engine type
--file <FILE> -f Path to the schema definition file
--format <FORMAT> -F File format hint: Xml, Json, Yaml
--drop Prepend DROP statements before each CREATE
--out <FILE> -o Output file path (stdout if omitted)

Examples:

# Generate CREATE SQL to a file
foundry sql schema \
  --datasource connection.json \
  --file schemas/dbo.xml \
  --out scripts/dbo.sql

# Include DROP statements and write to file
foundry sql schema \
  --datasource SqlServer_16.0.json \
  --file schemas/dbo.xml \
  --drop --out scripts/dbo.sql

# Print to stdout for piping
foundry sql schema \
  --conn "Host=localhost;Database=mydb;Username=postgres;Password=pass" \
  --db PostgreSQL \
  --file schemas/public.json

foundry sql database

Generates CREATE DDL for all schemas in a database definition file.

foundry sql database [options]

Accepts the same options as foundry sql schema.

Examples:

# Generate DROP + CREATE for the whole database
foundry sql database \
  --datasource connection.json \
  --file mydb.xml \
  --drop --out scripts/mydb.sql

# Print to stdout
foundry sql database \
  --conn "Host=localhost;Database=mydb;Username=postgres;Password=pass" \
  --db PostgreSQL \
  --file mydb.yaml

Using SQL Output in Pipelines

Because foundry sql writes to stdout when --out is omitted, the output can be piped directly to a database client or captured to a variable:

# Pipe directly to psql
foundry sql schema \
  --conn "Host=localhost;Database=mydb;Username=postgres;Password=pass" \
  --db PostgreSQL \
  --file schemas/public.json | psql -U postgres mydb

# Capture to a variable in PowerShell
$ddl = foundry sql schema --datasource connection.json --file schemas/dbo.xml

Definition Files vs SQL Generation

foundry sql is complementary to foundry build:

Command Executes DDL? Suitable for
foundry build schema Yes Automated deployments where execution is acceptable
foundry sql schema No Pre-flight review, release artefacts, manual approval workflows

Both commands read the same definition file formats (XML, JSON, YAML).