mysql

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 10 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.

db/models mirrors those tables; db/repositories contains GORM Gen output. The common-go MySQL wrapper opens owned connections and supplies a separate multi-statement migration pool. Runtime claims use read-committed transactions and skip locked rows. MySQL reports changed rows by default, so heartbeat updates verify ownership separately when a second-precision timestamp has not changed. See generation.

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(pool *sql.DB, opts ...option) *mysqlBackend

NewMysqlBackendWithDB leaves connection configuration and ownership with the caller. Automatic migrations require WithMigrationDSN and are disabled by default.

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.

Directories

Path Synopsis
db
Package db owns mysql connection setup and the backend's immutable migration history.
Package db owns mysql connection setup and the backend's immutable migration history.

Jump to

Keyboard shortcuts

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