Skip to content
VibORM
Esc
↑↓navigate↵open⌘Jpreview
On this page

Migration Drivers

Database-specific DDL generation, schema introspection, and type mapping

What Migration Drivers Do

  • Schema introspection - Read current database state
  • DDL generation - Generate database-specific SQL
  • Type mapping - Convert VibORM types to database types
  • Capability detection - Handle database-specific limitations

Available Drivers

Driver Database Native Enums Native Arrays Index Types Effectful V1 commands
PostgreSQL PostgreSQL Yes Yes btree, hash, gin, gist Providers with a proven pinned session
MySQL MySQL Yes (inline ENUM) No (JSON) btree, fulltext, spatial MySQL2 with namespace attestation; stepwise DDL
SQLite SQLite3, Bun SQLite No (CHECK) No (JSON) btree Yes
SQLite Durable Objects No (CHECK) No (JSON) btree Yes
SQLite LibSQL / Turso No (CHECK) No (JSON) btree Refused until constraint alteration and reconstruction are proven
SurrealDB SurrealDB 4 No (string) Yes plain and unique; others through .rawIndex() Yes

Driver Capabilities

Each driver declares what its database can do: whether enums and arrays are native, which index types exist, and whether enum values can be added inside a transaction. PostgreSQL has native enum types and arrays. On PostgreSQL 12+, adding a value is a transactional, catalog-only ALTER TYPE ... ADD VALUE, but using that value before commit is forbidden; removals and reorders use one transactional type replacement. MySQL defines enums inline on the column (changing one is a MODIFY COLUMN, which implicitly commits) and stores arrays as JSON. SQLite emulates enums with CHECK constraints and stores arrays as JSON.

Supported Operations

Migration drivers generate DDL for these operations:

Operation PostgreSQL MySQL SQLite
createTable Direct Direct Direct
dropTable Direct Direct Direct
renameTable Direct Direct Direct
addColumn Direct Direct Direct
dropColumn Direct Direct Direct (3.35.0+)
renameColumn Direct Direct Direct (3.25.0+)
alterColumn Direct MODIFY COLUMN Table recreation
createIndex Direct Direct Direct
dropIndex Direct Direct Direct
addForeignKey Direct Direct Table recreation
dropForeignKey Direct Direct Table recreation
addPrimaryKey Direct Direct Table recreation
dropPrimaryKey Direct Direct Table recreation
createEnum CREATE TYPE No-op (inline in column) No-op (TEXT)
dropEnum DROP TYPE No-op No-op
alterEnum ADD VALUE [BEFORE] for additions; type replacement for removals, reorders and additions the same migration may use (see PostgreSQL) MODIFY COLUMN per column Table recreation

Automatic Driver Selection

VibORM automatically selects the migration driver based on your database driver:

import { createClient } from "viborm/postgres";
import { createMigrationClient } from "viborm/migrations";

const client = createClient({
  databaseUrl: "...",
  schema: { User },
});

// PostgreSQL migration driver is automatically used
await createMigrationClient(client).push();

Type Mapping

Each driver maps VibORM scalar types to database-specific types:

Common Mappings

VibORM Scalar PostgreSQL MySQL SQLite
string() text TEXT TEXT
int() integer INT INTEGER
bigint() bigint BIGINT INTEGER
number() double precision DOUBLE REAL
decimal({ precision, scale }) NUMERIC(p,s) DECIMAL(p,s) checked scaled INTEGER
boolean() boolean TINYINT(1) INTEGER
s.dateTime() timestamptz(3) DATETIME(3) Canonical UTC TEXT
json() jsonb JSON TEXT
blob() bytea BLOB BLOB

Fixed-decimal lists use NUMERIC(p,s)[] on PostgreSQL and coefficient-string containers on MySQL and SQLite. SQLite declares that container as TEXT, not the generic array JSON type. See the Decimal guide for provider limits, descriptor migrations, and raw-SQL representation.

See individual driver pages for complete type mappings.

Next Steps

Was this page helpful?