Table of Contents

Import & Export

Foundry provides commands for importing CSV data into database tables and exporting table data or schema definitions back to files.

Import

foundry import reads a CSV file and inserts its rows into a target table.

foundry import [options]

Required Options

Option Short Description
--datasource <FILE> -d Datasource JSON file
--conn <STRING> -c ADO.NET connection string
--db <TYPE> -b Database engine type
--schema <NAME> -s Target schema name
--table <NAME> -t Target table name
--file <FILE> -f Path to the CSV file to import

CSV Format Options

Option Short Default Description
--delimiter <CHAR> -D , Field delimiter character
--quote-char <CHAR> -q " Quote character for fields containing the delimiter
--escape-char <CHAR> -e \ Escape character within quoted fields
--line-terminator <STRING> system default Row terminator string
--no-headers -H CSV has no header row

Data Options

Option Short Description
--keep-identity -k Insert identity/auto-increment values from the file as-is
--no-full-text-update Skip full-text index update after import
--import-config <FILE> -i JSON file with detailed import settings (overrides CSV format flags)

Date & Time Format Options

Option Default Description
--date-format <FORMAT> yyyy-MM-dd Date format string
--time-format <FORMAT> HH:mm:ss Time format string
--interval-format <FORMAT> c Interval/TimeSpan format string
--datetime-format <FORMAT> yyyy-MM-dd HH:mm:ss DateTime format string
--timestamp-format <FORMAT> yyyy-MM-dd HH:mm:ss zzz DateTimeOffset format string

Examples

# Basic import
foundry import \
  --datasource connection.json \
  --schema dbo --table customers \
  --file data/customers.csv

# Semicolon-delimited file with European date format
foundry import \
  --datasource MySql_8.4.json \
  --schema sales --table orders \
  --file data/orders.csv \
  --delimiter ";" \
  --date-format "dd/MM/yyyy"

# Using an import configuration file
foundry import \
  --datasource PostgreSQL_17.6.json \
  --schema public --table events \
  --file data/events.csv \
  --import-config import-config.json

# Inline connection with identity preservation
foundry import \
  --conn "Server=localhost;Database=mydb;User Id=sa;Password=pass" \
  --db SQLServer \
  --schema dbo --table products \
  --file data/products.csv \
  --keep-identity
Note

When --import-config is specified, it takes full precedence over all CSV format flags (--delimiter, --quote-char, etc.).

Import Config File Reference

An import config file (validated against schemas/import-config.schema.json) covers everything the CSV format flags cover, plus two capabilities with no CLI flag equivalent: explicit column mappings and per-column blob handling.

Field Type Default Description
delimiter string (1 char) , Field delimiter
quoteChar string (1 char) " Quote character for fields containing the delimiter
escapeChar string (1 char) \ Escape character within quoted fields
lineTerminator string system newline Row terminator string
useColumnHeaders boolean true The first CSV row contains column header names
keepIdentity boolean false Insert identity/auto-increment values from the CSV as-is
updateFullTextIndex boolean true Rebuild full-text indexes on the target table after import
dateFormat string yyyy-MM-dd .NET format string for date-only columns
timeFormat string HH:mm:ss .NET format string for time-only columns
intervalFormat string c .NET format string for interval/TimeSpan columns
dateTimeFormat string yyyy-MM-dd HH:mm:ss .NET format string for DateTime columns
timestampFormat string yyyy-MM-dd HH:mm:ss zzz .NET format string for DateTimeOffset/timestamp columns
blobs array Per-column blob handling rules (see below)
mappings array auto-generated Explicit CSV-header-to-table-column mappings (see below)

Blob handling. Each entry in blobs needs a column and a handling of base64 (decode the CSV field from Base64) or file (treat the CSV field as a file path and read the blob from disk, using a pattern with {column_name} token substitution):

{
  "blobs": [
    { "column": "photo", "handling": "base64" },
    { "column": "document", "handling": "file", "pattern": "blobs/{document}" }
  ]
}

Column mappings. When mappings is omitted, Foundry auto-generates a mapping from the table definition, assuming the CSV header names match the column names exactly. Use mappings to map differently-named CSV headers to table columns; header defaults to column when omitted:

{
  "mappings": [
    { "header": "Customer Name", "column": "customer_name" },
    { "header": "Order Total", "column": "total" }
  ]
}

Full example:

{
  "$schema": "schemas/import-config.schema.json",
  "delimiter": ";",
  "dateFormat": "dd/MM/yyyy",
  "blobs": [
    { "column": "photo", "handling": "base64" }
  ],
  "mappings": [
    { "header": "Customer Name", "column": "customer_name" }
  ]
}

Export

Foundry provides three export commands: exporting raw table data to CSV, exporting a single schema definition to files, and exporting the full database definition to files.

foundry export data

Exports table data to a CSV file.

foundry export data [options]

Required Options

Option Short Description
--datasource <FILE> -d Datasource JSON file
--conn <STRING> -c ADO.NET connection string
--db <TYPE> -b Database engine type
--schema <NAME> -s Source schema name
--table <NAME> -t Source table name
--out <FILE> -o Output CSV file path

CSV Format Options

Option Short Default Description
--delimiter <CHAR> -D , Field delimiter character
--quote-char <CHAR> -q " Quote character
--escape-char <STRING> \\ Escape string within quoted fields
--line-terminator <STRING> system default Row terminator string
--force-qualifier Always quote all field values
--no-headers -H Omit column header row
--no-trim Preserve leading and trailing whitespace
--export-config <FILE> -e JSON file with export format settings

Date & Time Format Options

Option Default Description
--date-format <FORMAT> yyyy-MM-dd Date format string
--time-format <FORMAT> HH:mm:ss Time format string
--interval-format <FORMAT> c Interval/TimeSpan format string
--datetime-format <FORMAT> yyyy-MM-dd hh:mm:ss DateTime format string
--timestamp-format <FORMAT> yyyy-MM-dd hh:mm:ss zzz DateTimeOffset format string

Examples

# Export a table to CSV
foundry export data \
  --datasource connection.json \
  --schema public --table orders \
  --out exports/orders.csv

# Semicolon delimiter
foundry export data \
  --datasource MySql_8.4.json \
  --schema sales --table orders \
  --out exports/orders.csv \
  --delimiter ";"

# Inline connection string
foundry export data \
  --conn "Server=localhost;Database=mydb;User Id=sa;Password=pass" \
  --db SQLServer \
  --schema dbo --table customers \
  --out exports/customers.csv

Export Config File Reference

An export config file (validated against schemas/export-config.schema.json) covers everything the CSV format flags cover, plus per-column blob handling with no CLI flag equivalent.

Field Type Default Description
delimiter string (1 char) , Field delimiter
quoteChar string (1 char) " Quote character for fields containing the delimiter
escapeChar string \\ Escape string within quoted fields
lineTerminator string system newline Row terminator string
forceQualifier boolean false Always quote every field value, even when not strictly required
writeHeaders boolean true Write a column header row as the first output line
trimChars boolean true Trim leading and trailing whitespace from string values
dateFormat string yyyy-MM-dd .NET format string for date-only columns
timeFormat string HH:mm:ss .NET format string for time-only columns
intervalFormat string c .NET format string for interval/TimeSpan columns
dateTimeFormat string yyyy-MM-dd HH:mm:ss .NET format string for DateTime columns
timestampFormat string yyyy-MM-dd HH:mm:ss zzz .NET format string for DateTimeOffset/timestamp columns
blobs array Per-column blob handling rules (see below)

Blob handling. Each entry needs a column and a handling of base64 (encode the blob as Base64 inline in the CSV) or file (write the blob to an external file and emit the file path, using a pattern with {column_name} token substitution). Rules can be scoped globally, to a table, or to a schema + table, and are evaluated in that order — the first match wins:

{
  "blobs": [
    { "column": "thumbnail", "handling": "base64" },
    { "column": "document", "handling": "file", "pattern": "exports/blobs/{document}", "table": "contracts" },
    { "column": "scan", "handling": "file", "pattern": "exports/blobs/{scan}", "schema": "archive", "table": "records" }
  ]
}

Full example:

{
  "$schema": "schemas/export-config.schema.json",
  "delimiter": ";",
  "forceQualifier": true,
  "blobs": [
    { "column": "thumbnail", "handling": "base64" }
  ]
}

foundry export schema

Exports a schema definition from a connected database to one or more files.

foundry export schema [options]
Option Short Description
--datasource <FILE> -d Datasource JSON file
--conn <STRING> -c ADO.NET connection string
--db <TYPE> -b Database engine type
--target <SCHEMA> -t Name of the schema to export (required)
--out <PATH> -o Output directory path (required)
--format <FORMAT> -F Output format: Xml, Json, Yaml (default: Xml)
--data Include table data in the export
foundry export schema \
  --datasource connection.json \
  --target dbo --out exports/ --format Json

foundry export schema \
  --datasource PostgreSQL_17.6.json \
  --target public --out exports/ --data

foundry export database

Exports the full database definition from a connected database. Optionally scoped to specific schemas.

foundry export database [options]
Option Short Description
--datasource <FILE> -d Datasource JSON file
--conn <STRING> -c ADO.NET connection string
--db <TYPE> -b Database engine type
--target <SCHEMAS> -t Comma-separated schema names to include (all if omitted)
--out <PATH> -o Output directory path (required)
--format <FORMAT> -F Output format: Xml, Json, Yaml (default: Xml)
--data Include table data in the export
foundry export database \
  --datasource connection.json \
  --out exports/

# Export only specific schemas in YAML format
foundry export database \
  --datasource SqlServer_17.0.json \
  --target dbo,audit --out exports/ --format Yaml