Schema Migration
Examples of using Sling to migrate database schema attributes along with data
Schema migration (v1.5.7) is a powerful feature that allows Sling to replicate not just data, but also important schema attributes like primary keys, foreign keys, indexes, default values, nullable constraints, auto-increment columns, and column/table descriptions from source to target databases.
Overview
When migrating databases, preserving schema attributes is often critical for maintaining data integrity and application compatibility. Sling's schema migration feature extracts extended metadata from source tables and applies the corresponding constraints and properties to target tables.
Supported Attributes
primary_key
Primary key constraints
id INT PRIMARY KEY
foreign_key
Foreign key relationships
REFERENCES customers(id)
indexes
Non-primary key indexes
CREATE INDEX idx_name ON table(col)
auto_increment
Identity/auto-increment columns
IDENTITY(1,1) or SERIAL
nullable
NOT NULL constraints
email VARCHAR(255) NOT NULL
default_value
Column default values
DEFAULT CURRENT_TIMESTAMP
description
Column and table comments
COMMENT ON COLUMN...
Supported Databases
Schema migration works between any combination of these databases. The level of support varies by database—see the compatibility matrix below for details.
Full Support
PostgreSQL
MySQL / MariaDB
SQL Server / Azure SQL
Oracle
Redshift
Databricks
Partial Support
Snowflake (no indexes)
BigQuery (no auto-increment, no default values, no indexes)
SQLite (no descriptions)
DuckDB (no auto-increment, no default values)
ClickHouse (primary key, nullable, description only)
StarRocks (v1.6.4, single-column indexes only, limited default values)
Database Compatibility Matrix
The following matrix shows which schema attributes are supported for each database:
PostgreSQL
✓
✓
✓
✓
✓
✓
✓
MySQL / MariaDB
✓
✓
✓¹
✓
✓
✓
✓
SQL Server / Azure SQL
✓
✓
✓
✓
✓
✓
✓
Oracle
✓
✓
✓²
✓
✓
✓
✓
Redshift
✓
✓³
✓³
✓
✓
—⁴
✓
Databricks
✓⁵
✓⁶
✓⁶
✓
✓
—⁷
✓
Snowflake
✓
✓⁸
✓⁸
✓
✓
—
✓
BigQuery
—
✓⁹
✓⁹
—
✓
—
✓
SQLite
✓¹⁰
✓
✓¹¹
✓
✓
✓
—
DuckDB
—
✓
✓
—
✓
✓
✓
ClickHouse
—
✓¹²
—
✓
✓
—
✓
StarRocks
✓¹³
✓¹⁴
✓¹⁵
✓¹⁶
✓
✓¹⁷
✓
Legend: ✓ = Supported | — = Not supported
Notes:
MySQL/MariaDB: Foreign keys require InnoDB engine; MyISAM ignores FK constraints
Oracle: Supports
ON DELETEactions but notON UPDATEactions for foreign keysRedshift: Primary keys and foreign keys are informational only (not enforced)
Redshift: Does not support traditional indexes; use SORTKEY/DISTKEY instead
Databricks: Auto-increment only supports
BIGINTcolumn typeDatabricks: Primary keys and foreign keys are informational only (not enforced); only NOT NULL is enforced
Databricks: Does not support traditional indexes; use Z-ordering instead
Snowflake: Primary keys and foreign keys are not enforced in standard tables (metadata only); only NOT NULL is enforced
BigQuery: Primary keys and foreign keys use
NOT ENFORCEDsyntax (metadata only for query optimization)SQLite: Auto-increment only works with
INTEGER PRIMARY KEYcolumnsSQLite: Foreign keys require
PRAGMA foreign_keys = ONper connection (disabled by default)ClickHouse: Primary key defines sort order and sparse index; does not enforce uniqueness
StarRocks: Auto-increment only supports
BIGINTcolumns. Seed and increment values are not keptStarRocks: The source primary key becomes the key of a Primary Key table and the hash distribution key
StarRocks: Foreign keys are informational only (stored in the
foreign_key_constraintstable property)StarRocks: Only literal values,
CURRENT_TIMESTAMP(datetime columns) anduuid()are supported. Sling drops aCURRENT_DATEdefaultStarRocks: Bitmap indexes on one column only. Sling skips multi-column indexes and indexes on primary key columns
Constraint Enforcement Matrix
PostgreSQL
✓ Yes
✓ Yes
✓ Yes
✓ Yes
MySQL / MariaDB
✓ Yes
✓ Yes (InnoDB)
✓ Yes
✓ Yes
SQL Server
✓ Yes
✓ Yes
✓ Yes
✓ Yes
Oracle
✓ Yes
✓ Yes
✓ Yes
✓ Yes
Redshift
✗ No
✗ No
✓ Yes
✓ Yes
Databricks
✗ No
✗ No
✓ Yes
✓ Yes
Snowflake
✗ No
✗ No
✓ Yes
✓ Yes
BigQuery
✗ No
✗ No
✓ Yes
Partial
SQLite
✓ Yes
✓ Yes*
✓ Yes
✓ Yes
DuckDB
✓ Yes
✓ Yes
✓ Yes
✓ Yes
ClickHouse
✗ No
N/A
✗ No
✓ Yes
StarRocks
Upsert*
✗ No
✓ Yes
✓ Yes
Legend: ✓ Yes = Enforced at runtime | ✗ No = Metadata only (not enforced) | * = Requires configuration (SQLite), or see note (StarRocks)
What You Can Use for Each Database
All features supported and enforced. PostgreSQL is fully compatible with schema migration.
Primary Key
✓
✓ Yes
Foreign Key
✓
✓ Yes
Auto-increment
✓
✓ Yes
Default Value
✓
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
✓
Functional
Description
✓
Metadata
Auto-increment uses
GENERATED BY DEFAULT AS IDENTITYFull foreign key support with
ON DELETEandON UPDATEactionsColumn/table comments via
COMMENT ONsyntax
All features supported and enforced (with InnoDB engine).
Primary Key
✓
✓ Yes
Foreign Key
✓
✓ Yes (InnoDB only)
Auto-increment
✓
✓ Yes
Default Value
✓
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
✓
Functional
Description
✓
Metadata
Auto-increment uses
AUTO_INCREMENTkeywordForeign keys require InnoDB engine (MyISAM ignores FK constraints)
Comments via
COMMENTclause
All features supported and enforced. SQL Server and Azure SQL are fully compatible.
Primary Key
✓
✓ Yes
Foreign Key
✓
✓ Yes
Auto-increment
✓
✓ Yes
Default Value
✓
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
✓
Functional
Description
✓
Metadata
Auto-increment uses
IDENTITY(seed, increment)syntaxForeign keys can be disabled with
NOCHECKif neededDescriptions via Extended Properties (
MS_Description)
All features supported and enforced with one limitation.
Primary Key
✓
✓ Yes
Foreign Key
✓
✓ Yes (ON DELETE only)
Auto-increment
✓
✓ Yes
Default Value
✓
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
✓
Functional
Description
✓
Metadata
Auto-increment uses
GENERATED BY DEFAULT AS IDENTITYForeign keys support
ON DELETEactions but notON UPDATE(Oracle limitation)Comments via
COMMENT ON COLUMN/COMMENT ON TABLE
DDL supported but constraints not enforced. Snowflake is an analytical database.
Primary Key
✓
✗ No (metadata only)
Foreign Key
✓
✗ No (metadata only)
Auto-increment
✓
✓ Yes
Default Value
✓
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
—
N/A
Description
✓
Metadata
Auto-increment uses
AUTOINCREMENT START ... INCREMENT ...Primary keys and foreign keys are not enforced — they exist for documentation and query optimization only
Only
NOT NULLconstraints are enforced in standard tablesIndexes are not applicable (Snowflake uses clustering keys instead)
Limited support. BigQuery constraints are metadata only.
Primary Key
✓
✗ No (NOT ENFORCED)
Foreign Key
✓
✗ No (NOT ENFORCED)
Auto-increment
—
N/A
Default Value
—
N/A
NOT NULL
✓
✓ Yes
Indexes
—
N/A
Description
✓
Metadata
Primary keys and foreign keys use
NOT ENFORCEDsyntax (query optimization hints only)Column descriptions via
ALTER TABLE ... SET OPTIONSNo identity columns—use application-generated IDs or
GENERATE_UUID()
DDL supported but PK/FK not enforced. Redshift is an analytical data warehouse.
Primary Key
✓
✗ No (informational)
Foreign Key
✓
✗ No (informational)
Auto-increment
✓
✓ Yes
Default Value
✓
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
—
N/A
Description
✓
Metadata
Auto-increment uses
IDENTITY(seed, increment)Primary keys and foreign keys are informational only — used as query optimizer hints, not enforced
Does not support traditional indexes; use
SORTKEYandDISTKEYfor performanceComments via
COMMENT ONsyntax
Most features supported. Foreign keys require explicit enabling.
Primary Key
✓
✓ Yes
Foreign Key
✓
✓ Yes (when enabled)
Auto-increment
✓
✓ Yes
Default Value
✓
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
✓
Functional
Description
—
N/A
Auto-increment only works with
INTEGER PRIMARY KEYcolumnsForeign keys require
PRAGMA foreign_keys = ONper connection (disabled by default)No native column/table comment support
Partial support but constraints are enforced. DuckDB enforces integrity unlike most analytical DBs.
Primary Key
✓
✓ Yes
Foreign Key
✓
✓ Yes
Auto-increment
—
N/A
Default Value
—
N/A
NOT NULL
✓
✓ Yes
Indexes
✓
Functional
Description
✓
Metadata
No native identity columns—use sequences with
DEFAULT nextval('seq')Foreign keys are enforced (unlike Snowflake, BigQuery, Redshift)
Indexes are fully supported via
duckdb_indexes()metadataColumn descriptions via
COMMENT ONsyntax
DDL supported but PK/FK not enforced. Databricks uses Delta Lake.
Primary Key
✓
✗ No (informational)
Foreign Key
✓
✗ No (informational)
Auto-increment
✓
✓ Yes
Default Value
✓
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
—
N/A
Description
✓
Metadata
Auto-increment uses
GENERATED BY DEFAULT AS IDENTITY(BIGINT only)Note: When Databricks is used as a source, identity column detection is limited (Databricks doesn't expose identity metadata via
information_schema)Primary keys and foreign keys are informational only — used for query optimization
Only
NOT NULLandCHECKconstraints are enforcedDoes not support traditional indexes; use Z-ordering for performance
Limited support. ClickHouse is optimized for OLAP, not constraint enforcement.
Primary Key
✓
✗ No (sort order only)
Foreign Key
—
N/A
Auto-increment
—
N/A
Default Value
✓
✓ Yes
NOT NULL
✓
✗ No
Indexes
—
N/A
Description
✓
Metadata
Primary key defines sort order and sparse index — does not enforce uniqueness
No foreign key support
No auto-increment columns (use
generateSerialID()in v25.1+)NOT NULL is not enforced; use
Nullable(T)wrapper to allow NULLsUses data-skipping indexes (MinMax, Bloom) instead of traditional indexes
Supported from v1.6.4. StarRocks is an analytical database. Some attributes have limits.
Primary Key
✓
Upsert (no duplicate rows)
Foreign Key
✓
✗ No (informational)
Auto-increment
✓ (BIGINT only)
✓ Yes
Default Value
✓ (limited)
✓ Yes
NOT NULL
✓
✓ Yes
Indexes
✓ (single column)
Functional
Description
✓
Metadata
Sling creates a Primary Key table from the source primary key:
primary key(id) distributed by hash(id). Without a primary key, Sling uses a_sling_row_idcolumn as the hash keyAuto-increment uses
AUTO_INCREMENTonBIGINTcolumns only. StarRocks does not keep the seed and increment valuesDefault values: StarRocks accepts literal values,
CURRENT_TIMESTAMPon datetime columns, and(uuid()). Sling drops defaults that StarRocks does not support (for exampleCURRENT_DATE)Foreign keys go into the
foreign_key_constraintstable property. The optimizer uses them. StarRocks does not enforce themIndexes are bitmap indexes on one column. Sling skips multi-column indexes and indexes on primary key columns. StarRocks builds each index in an async job, and Sling waits for the job to finish
Column comments go in the
CREATE TABLEstatement. Table comments useALTER TABLE ... COMMENT = '...'StarRocks has no
UNIQUEconstraint
Enabling Schema Migration
Set the SLING_SCHEMA_MIGRATION environment variable to enable specific attributes:
Available Options
all
Enable all schema migration attributes
primary_key
Migrate primary key constraints
foreign_key
Migrate foreign key relationships
indexes
Migrate indexes (non-PK)
auto_increment
Migrate identity/auto-increment columns
nullable
Migrate NOT NULL constraints
default_value
Migrate column default values
description
Migrate column and table comments
Basic Example
Migrate all schema attributes from SQL Server to PostgreSQL:
Foreign Key Migration
When migrating foreign keys, Sling automatically handles table ordering to ensure parent tables are created before child tables that reference them.
Automatic Table Ordering
Sling performs topological sorting based on foreign key dependencies. Even if you list tables in the wrong order, they will be processed correctly:
Sling will automatically reorder streams to: customers → orders → order_items
Handling Circular Dependencies
If circular foreign key dependencies are detected, Sling will report an error. Options to resolve:
Remove one table from the replication
Disable foreign key migration
Handle FK creation manually via hooks
Auto-Increment / Identity Columns
Sling migrates auto-increment columns with their seed and increment values:
Database-Specific Behavior
SQL Server IDENTITY(1,1)
PostgreSQL
GENERATED BY DEFAULT AS IDENTITY
PostgreSQL SERIAL
MySQL
AUTO_INCREMENT
Oracle GENERATED AS IDENTITY
SQL Server
IDENTITY(seed, incr)
Default Values
Sling translates default value expressions between databases:
Default Value Translation
Current timestamp
GETDATE()
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP
SYSDATE
UTC timestamp
GETUTCDATE()
CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
UTC_TIMESTAMP()
SYS_EXTRACT_UTC(SYSTIMESTAMP)
UUID
NEWID()
gen_random_uuid()
UUID()
SYS_GUID()
Boolean true
1
true
1
1
Boolean false
0
false
0
0
Column & Table Descriptions
Migrate comments and descriptions to preserve documentation:
This will migrate:
Column comments (e.g.,
COMMENT ON COLUMN products.price IS 'Product retail price')Table comments (e.g.,
COMMENT ON TABLE products IS 'Product catalog')
Indexes
Migrate non-primary key indexes to preserve query performance:
This migrates regular indexes, unique indexes, and composite indexes.
Complete E-Commerce Migration Example
A comprehensive example migrating an e-commerce schema with all relationships:
Selective Attribute Migration
Enable only specific attributes based on your needs:
Data Integrity Focus
Performance Focus
Documentation Preservation
Using with Pipelines
Schema migration can also be used within pipelines:
Incremental Mode Considerations
Schema migration attributes are applied during table creation. When using incremental mode:
First run: Table is created with all schema attributes
Subsequent runs: Only data is upserted; schema is not modified
Troubleshooting
Missing Foreign Key Dependencies
Error: missing foreign key dependencies: 'orders' depends on 'customers' (not in stream list)
Solution: Add the missing referenced table to your streams:
Circular Dependency Detected
Error: circular foreign key dependency detected involving: table_a, table_b
Solution: Either disable FK migration or handle FKs manually with hooks:
Unsupported Default Expression
If a default expression cannot be translated, Sling will pass it through as-is with a debug warning. You may need to manually adjust the default in the target database.
Identity Column Conflicts
When using auto_increment migration, Sling uses GENERATED BY DEFAULT AS IDENTITY (PostgreSQL/Oracle) to allow explicit value inserts during data migration while still supporting auto-generation for new inserts.
Best Practices
Test First: Run schema migration on a test environment before production
Start Selective: Begin with
primary_keyonly, then add more attributesInclude All Dependencies: Ensure all FK-referenced tables are in the replication
Use Full-Refresh: Schema attributes are best applied with
full-refreshmode initiallyReview Generated Schema: After migration, review the target schema for any needed adjustments
Consider Indexes Separately: Large tables may benefit from creating indexes after data load via hooks
See Also
Last updated
Was this helpful?