VibORM
Drivers

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

DriverDatabaseNative EnumsNative ArraysIndex Types
PostgreSQLPostgreSQLYesYesbtree, hash, gin, gist
SQLiteSQLite, LibSQLNo (CHECK)No (JSON)btree

Driver Capabilities

Each driver declares its capabilities:

interface MigrationCapabilities {
  supportsNativeEnums: boolean;
  supportsAddEnumValueInTransaction: boolean;
  supportsIndexTypes: string[];
  supportsNativeArrays: boolean;
}

PostgreSQL

{
  supportsNativeEnums: true,
  supportsAddEnumValueInTransaction: false,
  supportsIndexTypes: ["btree", "hash", "gin", "gist"],
  supportsNativeArrays: true
}

SQLite

{
  supportsNativeEnums: false,
  supportsAddEnumValueInTransaction: true,
  supportsIndexTypes: ["btree"],
  supportsNativeArrays: false
}

Supported Operations

Migration drivers generate DDL for these operations:

OperationPostgreSQLSQLite
createTableDirectDirect
dropTableDirectDirect
renameTableDirectDirect
addColumnDirectDirect
dropColumnDirectDirect (3.35.0+)
renameColumnDirectDirect (3.25.0+)
alterColumnDirectTable recreation
createIndexDirectDirect
dropIndexDirectDirect
addForeignKeyDirectTable recreation
dropForeignKeyDirectTable recreation
addPrimaryKeyDirectTable recreation
dropPrimaryKeyDirectTable recreation
createEnumCREATE TYPENo-op (TEXT)
dropEnumDROP TYPENo-op
alterEnumALTER TYPENo-op

Automatic Driver Selection

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

import { createClient } from "viborm";
import { PostgresDriver } from "viborm/drivers/postgres";

const client = createClient({
  driver: new PostgresDriver({ connectionString: "..." }),
  schema: { User },
});

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

Type Mapping

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

Common Mappings

VibORM TypePostgreSQLSQLite
string()textTEXT
int()integerINTEGER
bigint()bigintINTEGER
float()double precisionREAL
boolean()booleanINTEGER
datetime()timestampTEXT
json()jsonbTEXT
blob()byteaBLOB

See individual driver pages for complete type mappings.

Next Steps

On this page