Open returns a migrate instance using embedded migrations, for use by the CLI (up/down/force/version). Caller must call m.Close() when done.
(databaseURL string)
| 63 | // Open returns a migrate instance using embedded migrations, for use by the CLI (up/down/force/version). |
| 64 | // Caller must call m.Close() when done. |
| 65 | func Open(databaseURL string) (*migrate.Migrate, error) { |
| 66 | if databaseURL == "" { |
| 67 | return nil, fmt.Errorf("DATABASE_URL is required for migrations") |
| 68 | } |
| 69 | |
| 70 | databaseURL = ensureSSLMode(databaseURL) |
| 71 | |
| 72 | source, err := iofs.New(migrationsFS, "migrations") |
| 73 | if err != nil { |
| 74 | return nil, fmt.Errorf("create embedded migrate source: %w", err) |
| 75 | } |
| 76 | |
| 77 | return migrate.NewWithSourceInstance("iofs", source, databaseURL) |
| 78 | } |
| 79 | |
| 80 | func ensureSSLMode(databaseURL string) string { |
| 81 | if !strings.Contains(databaseURL, "sslmode=") { |
nothing calls this directly
no test coverage detected