Skip to main content

MySQL Driver

The MySQL driver supports Queen's core migration flow, with MySQL-specific DDL caveats.

Packages

import (
"database/sql"

"github.com/yaop-labs/queen"
"github.com/yaop-labs/queen/drivers/mysql"
_ "github.com/go-sql-driver/mysql"
)

db, err := sql.Open("mysql", os.Getenv("DATABASE_URL"))
if err != nil {
return err
}

q := queen.New(mysql.New(db))

How it works

AreaImplementation
Migration tableInnoDB table with metadata columns.
Identifier quotingBackticks.
Placeholders?.
LockingMySQL GET_LOCK(lockName, timeoutSeconds) on a pinned *sql.Conn.
UnlockRELEASE_LOCK(lockName) on the same connection.
Lock namequeen_lock_ plus migration table name.
Executiondatabase/sql transaction through the shared base driver.
Atomic recordNo. Migration body commits before Record.

Guarantees

  • Locking uses a named MySQL lock and keeps the owning connection until unlock.
  • The migration table is created with ENGINE=InnoDB.
  • Existing metadata columns are checked through INFORMATION_SCHEMA.COLUMNS.

Limitations

  • MySQL DDL often causes implicit commits. A migration can contain statements that do not roll back the way PostgreSQL DDL does.
  • Migration metadata is not written in the same transaction as the migration body.
  • Lock timeout is passed to MySQL in whole seconds.
  • This path is supported but less heavily exercised than PostgreSQL.

DSN

Typical go-sql-driver/mysql DSN:

user:pass@tcp(localhost:3306)/myapp?parseTime=true