-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathoptions.go
More file actions
65 lines (52 loc) · 1.67 KB
/
Copy pathoptions.go
File metadata and controls
65 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package mysql
import (
"database/sql"
"github.com/cschleiden/go-workflows/backend"
)
type options struct {
*backend.Options
MySQLOptions func(db *sql.DB)
// ApplyMigrations automatically applies database migrations on startup.
ApplyMigrations bool
// MigrationDSN is an optional DSN to use for running migrations. This is useful when
// using NewMysqlBackendWithDB where no DSN is available. The DSN must support
// multi-statement queries (e.g., include &multiStatements=true).
MigrationDSN string
// MigrationsTable is the table used to track applied migrations. If empty,
// golang-migrate uses its default table.
MigrationsTable string
}
type option func(*options)
// WithApplyMigrations automatically applies database migrations on startup.
func WithApplyMigrations(applyMigrations bool) option {
return func(o *options) {
o.ApplyMigrations = applyMigrations
}
}
func WithMySQLOptions(f func(db *sql.DB)) option {
return func(o *options) {
o.MySQLOptions = f
}
}
// 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 WithMigrationDSN(dsn string) option {
return func(o *options) {
o.MigrationDSN = dsn
}
}
// WithMigrationsTable sets the table used to track applied migrations.
func WithMigrationsTable(migrationsTable string) option {
return func(o *options) {
o.MigrationsTable = migrationsTable
}
}
// WithBackendOptions allows to pass generic backend options.
func WithBackendOptions(opts ...backend.BackendOption) option {
return func(o *options) {
for _, opt := range opts {
opt(o.Options)
}
}
}