Skip to main content

Auto-migration

When Config.Adapter implements Migrator, goauth.New runs Migrate(ctx) before serving traffic.

type Migrator interface {
Migrate(ctx context.Context) error
}

Implemented by: postgres, mysql (and mariadb).

Behavior

  • Idempotent CREATE TABLE IF NOT EXISTS DDL
  • Runs once at process startup
  • Failure prevents New from returning a handler

Disable auto-migration

Use an adapter wrapper that does not expose Migrator, or run DDL yourself:

_, _ = db.Exec(postgres.Schema(postgres.DefaultPrefix))
adapter := postgres.New(db)

Production recommendation

For large deployments, prefer explicit migrations (Flyway, golang-migrate) using postgres.Schema() as reference SQL rather than implicit migrate on every pod start.