| 1 |
package schema |
| 2 |
|
| 3 |
import "database/sql" |
| 4 |
|
| 5 |
// Dialect selects the SQL flavor Migrate speaks to the version table. |
| 6 |
type Dialect int |
| 7 |
|
| 8 |
// Supported dialects; SQLite is the zero value |
| 9 |
const ( |
| 10 |
SQLite Dialect = iota |
| 11 |
Postgres |
| 12 |
) |
| 13 |
|
| 14 |
// MigrateFunc applies one schema change inside the setup transaction: the initial creation of |
| 15 |
// a store's tables, or one step upgrading a store from version N to N+1. Migrations needing |
| 16 |
// config capture it via closure, e.g. func migrations(cacheDuration time.Duration) map[int]MigrateFunc. |
| 17 |
type MigrateFunc func(tx *sql.Tx) error |
| 18 |
|
| 19 |
// AsMigrateFunc converts a simple query to a migration function |
| 20 |
func AsMigrateFunc(query string) MigrateFunc { |
| 21 |
return func(tx *sql.Tx) error { |
| 22 |
_, err := tx.Exec(query) |
| 23 |
return err |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
// NopMigrateFunc is a migration step that does nothing, for versions where a dialect has no |
| 28 |
// work to do (e.g. when only the other dialect's schema changed). |
| 29 |
func NopMigrateFunc(_ *sql.Tx) error { |
| 30 |
return nil |
| 31 |
} |