Documentation
¶
Overview ¶
Package mymigrate implements sqlmigrate.Migrator for MySQL and MariaDB using database/sql with github.com/go-sql-driver/mysql.
The *sql.Conn must originate from a *sql.DB opened with multiStatements=true in the DSN; without it, multi-statement migration files will silently execute only the first statement. The multiStatements requirement is validated lazily on the first ExecUp or ExecDown call:
db, err := sql.Open("mysql", "user:pass@tcp(host:3306)/dbname?multiStatements=true")
conn, err := db.Conn(ctx)
MySQL and MariaDB do not support transactional DDL. Statements like CREATE TABLE and ALTER TABLE cause an implicit commit, so if a migration fails partway through, earlier DDL statements in that migration will already be committed. DML-only migrations are fully transactional.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Migrator ¶
Migrator implements sqlmigrate.Migrator using a *sql.Conn with MySQL/MariaDB.
func New ¶
New creates a Migrator from the given connection. Use db.Conn(ctx) to obtain a *sql.Conn from a *sql.DB. The multiStatements=true DSN requirement is validated lazily on the first ExecUp or ExecDown call.
func (*Migrator) Applied ¶
Applied returns all applied migrations from the _migrations table. Returns an empty slice if the table does not exist (MySQL error 1146).
The table-missing check is applied at both Query and rows.Err — some drivers may surface the error lazily after iteration begins.