mysql

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 26 Imported by: 0

README

MySQL backend

MySQL stores workflow histories, pending events, timers and activities for workers sharing one database. See backend operations for durability, retention and deployment boundaries.

Connections and migrations

NewMysqlBackend opens and owns its SQL connection and applies embedded migrations by default. Its Close closes that connection. WithMySQLOptions configures the pool before migration.

NewMysqlBackendWithDB uses a caller-owned *sql.DB. It does not close the connection and disables migrations by default. To apply migrations through that constructor, set WithApplyMigrations(true) and provide WithMigrationDSN with multi-statement support. Keep connection credentials in application configuration, not source.

Constructors can panic when initialization or automatic migration fails. Apply migrations during controlled startup, before accepting work, and back up the database before schema upgrades.

Maintaining the backend

Embedded migrations live in db/migrations, with paired .up.sql and .down.sql files. Follow the existing sequence, preserve published migrations and test schema changes against real MySQL. The constructor and Migrate method use this embedded source.

Run make test-mysql from the repository root. It creates its own isolated MySQL service and runs the backend contracts with -race; it does not use a production database. See testing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMysqlBackend

func NewMysqlBackend(host string, port int, user, password, database string, opts ...option) *mysqlBackend

func NewMysqlBackendWithDB

func NewMysqlBackendWithDB(db *sql.DB, opts ...option) *mysqlBackend

NewMysqlBackendWithDB creates a new MySQL backend using an existing database connection. When using this constructor, the backend will not close the database connection when Close() is called. Migrations are disabled by default; to enable them, use WithApplyMigrations(true) along with WithMigrationDSN to provide a DSN that supports multi-statement queries.

func WithApplyMigrations

func WithApplyMigrations(applyMigrations bool) option

WithApplyMigrations automatically applies database migrations on startup.

func WithBackendOptions

func WithBackendOptions(opts ...backend.BackendOption) option

WithBackendOptions allows to pass generic backend options.

func WithMigrationDSN

func WithMigrationDSN(dsn string) option

WithMigrationDSN sets the DSN to use for running migrations. This is required when using NewMysqlBackendWithDB with ApplyMigrations enabled. The DSN should support multi-statement queries.

func WithMySQLOptions

func WithMySQLOptions(f func(db *sql.DB)) option

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL