Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( SQLite = Dialect{ // contains filtered or unexported fields } Postgres = Dialect{ // contains filtered or unexported fields } MySQL = Dialect{ // contains filtered or unexported fields } )
Functions ¶
func Migrate ¶
Migrate runs database migrations in a safe and idempotent way.
It creates a schema_migrations table if it doesn't exist, then applies each migration exactly once by claiming it first. Migrations are grouped by module name and executed in order. Each migration runs in its own transaction - if it fails, the transaction is rolled back and an error is returned.
The function is safe for concurrent execution: only one instance will successfully claim and apply each migration. Already applied migrations are skipped automatically.
Parameters:
- ctx: context for cancellation and timeout control
- db: database connection to run migrations on
- dialect: database-specific SQL syntax (SQLite, Postgres, or MySQL)
- opts: optional configuration (migrations to run, logger for output)
Returns an error if table creation fails, transaction handling fails, or any migration SQL fails to execute.
Types ¶
type Migrations ¶
Click to show internal directories.
Click to hide internal directories.