Skip to content
VibORM
Esc
navigateopen⌘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
PostgreSQL PostgreSQL Yes Yes btree, hash, gin, gist
MySQL MySQL Yes (inline ENUM) No (JSON) btree, fulltext, spatial
SQLite SQLite, LibSQL No (CHECK) No (JSON) btree

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 but can’t run ALTER TYPE ... ADD VALUE inside a transaction. 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 ALTER TYPE MODIFY COLUMN per column No-op

Automatic Driver Selection

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

import { createClient } from "viborm/postgres";

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

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

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
float() double precision DOUBLE REAL
boolean() boolean TINYINT(1) INTEGER
datetime() timestamp DATETIME(3) TEXT
json() jsonb JSON TEXT
blob() bytea BLOB BLOB

See individual driver pages for complete type mappings.

Next Steps

Was this page helpful?