Skip to content

Multi-Database Setup

dbsh supports four 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

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.

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 ServerMySQLSQLite
Bool typeBOOLEANBITTINYINT(1)INTEGER (0/1)
UUID typeUUIDUNIQUEIDENTIFIERCHAR(36)TEXT
TimestampNOW()GETUTCDATE()UTC_TIMESTAMP()C# DateTime (ISO string)
ID generationgen_random_uuid()NEWID()C# GuidC# Guid
JSON storageTEXTNVARCHAR(MAX)LONGTEXTTEXT
String concat|| or CONCAT()+CONCAT()||
Limit/offsetLIMIT n OFFSET mOFFSET m ROWS FETCH NEXT n ROWS ONLYLIMIT n OFFSET mLIMIT n OFFSET m
ILIKEILIKEuse 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 EXISTS

Released under the MIT License.