Skip to content

Multi-Database Setup ​

dbsh supports eight databases. The only thing that changes is the connection string and the provider setting.

Supported providers ​

ProviderVersionConfig valueDriver
PostgreSQL12+postgresqlNpgsql 8
SQL Server2016+sqlserverMicrosoft.Data.SqlClient 5
MySQL / MariaDB8+ / 10.5+mysqlMySqlConnector 2
SQLite3sqliteMicrosoft.Data.Sqlite 8
Oracle19+oracleOracle.ManagedDataAccess.Core 23
CockroachDB22+cockroachdbNpgsql (wire-compatible)
YugabyteDB2.14+yugabyteNpgsql (wire-compatible)
Amazon Aurora—auroraNpgsql / MySqlConnector (wire-compatible)

Switch providers by changing the provider field in migration.json or using --provider on the CLI.

PostgreSQL ​

bash
dbsh migrate -c "Host=localhost;Port=5432;Database=myapp;Username=postgres;Password=secret"
json
{ "database": { "provider": "postgresql", "connectionString": "..." } }

PostgreSQL uses database schemas for module isolation: "module".table_name.

SQL Server ​

bash
dbsh migrate -c "Server=localhost;Database=myapp;User Id=sa;Password=secret;TrustServerCertificate=True"
json
{ "database": { "provider": "sqlserver", "connectionString": "..." } }

SQL Server uses database schemas for module isolation: [module].[table_name].

MySQL ​

bash
dbsh migrate -c "Server=localhost;Database=myapp;User=root;Password=secret"
json
{ "database": { "provider": "mysql", "connectionString": "..." } }

MySQL does not support schemas. Module isolation uses table-name prefixes: module__table_name.

SQLite ​

bash
dbsh migrate -c "Data Source=./myapp.db"
json
{ "database": { "provider": "sqlite", "connectionString": "..." } }

SQLite does not support schemas. Module isolation uses table-name prefixes: module__table_name.

Oracle ​

bash
dbsh migrate -c "Data Source=localhost:1521/ORCL;User Id=myuser;Password=secret"
json
{ "database": { "provider": "oracle", "connectionString": "..." } }

Oracle uses database schemas (user accounts) for module isolation: module.table_name.

CockroachDB ​

CockroachDB is wire-compatible with PostgreSQL. Use the cockroachdb or crdb provider alias.

bash
dbsh migrate -p cockroachdb -c "Host=localhost;Port=26257;Database=myapp;Username=root;Password=secret;SslMode=Require"
json
{ "database": { "provider": "cockroachdb", "connectionString": "..." } }

Uses the same SQL syntax and schema support as PostgreSQL.

YugabyteDB ​

YugabyteDB is wire-compatible with PostgreSQL. Use the yugabyte or yugabytedb provider alias.

bash
dbsh migrate -p yugabyte -c "Host=localhost;Port=5433;Database=myapp;Username=yugabyte;Password=secret"
json
{ "database": { "provider": "yugabyte", "connectionString": "..." } }

Uses the same SQL syntax and schema support as PostgreSQL.

Amazon Aurora ​

Amazon Aurora is wire-compatible with PostgreSQL and MySQL. Use the aurora provider alias, or aurora-postgresql / aurora-mysql to force a specific engine.

bash
# Aurora PostgreSQL
dbsh migrate -p aurora -c "Host=my-cluster.cluster-xxxx.us-east-1.rds.amazonaws.com;Port=5432;Database=myapp;Username=postgres;Password=secret"

# Aurora MySQL
dbsh migrate -p aurora-mysql -c "Host=my-cluster.cluster-xxxx.us-east-1.rds.amazonaws.com;Port=3306;Database=myapp;Username=admin;Password=secret"
json
{ "database": { "provider": "aurora", "connectionString": "..." } }

Uses the same SQL syntax and schema support as the underlying engine (PostgreSQL or MySQL).

Override provider from CLI ​

Override the provider at runtime without changing config:

bash
dbsh migrate -c "..." -p sqlserver

Provider-specific SQL notes ​

When writing migrations, keep these differences in mind:

ConcernPostgreSQLSQL ServerMySQLSQLiteOracle
Bool typeBOOLEANBITTINYINT(1)INTEGER (0/1)NUMBER(1) (0/1)
UUID typeUUIDUNIQUEIDENTIFIERCHAR(36)TEXTRAW(16) / SYS_GUID()
TimestampNOW()GETUTCDATE()UTC_TIMESTAMP()C# DateTime (ISO string)SYSTIMESTAMP
ID generationgen_random_uuid()NEWID()C# GuidC# GuidSYS_GUID()
JSON storageTEXTNVARCHAR(MAX)LONGTEXTTEXTCLOB
String concat|| or CONCAT()+CONCAT()|||| or CONCAT()
Limit/offsetLIMIT n OFFSET mOFFSET m ROWS FETCH NEXT n ROWS ONLYLIMIT n OFFSET mLIMIT n OFFSET mFETCH FIRST n ROWS ONLY
ILIKEILIKEuse LOWER()use LOWER()use LOWER()use LOWER()
IF NOT EXISTSCREATE TABLE IF NOT EXISTSIF NOT EXISTS (SELECT ...) CREATE TABLE ...CREATE TABLE IF NOT EXISTSCREATE TABLE IF NOT EXISTSPL/SQL DECLARE block

Released under the MIT License.