Skip to content

Tracking Tables

dbsh init creates three tables in your database. These track migration state, prevent concurrent deploys, and maintain an audit trail.

__migration_history

One row per applied migration per environment.

ColumnTypeDescription
idUUID/GUIDPrimary key
versionVARCHARMigration version (e.g., 001) or R for repeatables
nameVARCHARMigration name
script_nameVARCHARFilename (e.g., V001__CreateUsers.sql)
script_hashVARCHARSHA-256 checksum of the script content
migration_typeVARCHARSchema, Data, Patch, or Repeatable
categoryVARCHARCategory (e.g., Schema, Data, Patch)
executed_byVARCHARUser or identity that ran the migration
executed_at_utcTIMESTAMPWhen the migration was applied
execution_time_msBIGINTHow long the migration took
environmentVARCHARTarget environment name
statusVARCHARCompleted, Failed, InProgress, or RolledBack
rollback_availableBOOLEANWhether a U script exists for this version
rollback_script_nameVARCHARFilename of the rollback script
error_messageTEXTError details if the migration failed
batch_numberINTEGERBatch number for grouped executions

Unique constraints:

  • (script_name, environment) — each script applied once per environment
  • (version, environment) WHERE version <> 'R' — one versioned migration per version per environment

__migration_lock

Distributed lock preventing concurrent deploys.

ColumnTypeDescription
idUUID/GUIDPrimary key
lock_keyVARCHARLock identifier
locked_byVARCHAROwner identity
locked_at_utcTIMESTAMPWhen the lock was acquired
expires_at_utcTIMESTAMPWhen the lock expires (lease-based)
environmentVARCHARTarget environment
is_activeBOOLEANWhether the lock is currently held

The lock uses lease-based expiry with automatic renewal during batch execution. This means a crashed deployment won't block future runs indefinitely — the lock expires after lockTimeoutSeconds.

__migration_audit

Append-only audit trail of every action.

ColumnTypeDescription
idUUID/GUIDPrimary key
actionVARCHARValidate, DryRun, Deploy, Rollback, or Repair
performed_byVARCHARUser or identity
performed_at_utcTIMESTAMPWhen the action was performed
environmentVARCHARTarget environment
detailsTEXTJSON or text details about the action

Engine-specific DDL

The tracking table DDL differs between providers:

ConcernPostgreSQLSQL ServerMySQLSQLite
UUID columnUUIDUNIQUEIDENTIFIERCHAR(36)TEXT
Boolean columnBOOLEANBITTINYINT(1)INTEGER (0/1)
Timestamp columnTIMESTAMPTZDATETIME2DATETIMETEXT
ID defaultgen_random_uuid()NEWID()C# GuidC# Guid

Released under the MIT License.