package
3.3.0+incompatible
Repository: https://github.com/qdentity/migrate.git
Documentation: pkg.go.dev
# README
MySQL
mysql://user:password@tcp(host:port)/dbname?query
URL Query | WithInstance Config | Description |
---|---|---|
x-migrations-table | MigrationsTable | Name of the migrations table |
dbname | DatabaseName | The name of the database to connect to |
user | The user to sign in as | |
password | The user's password | |
host | The host to connect to. | |
port | The port to bind to. | |
x-tls-ca | The location of the root certificate file. | |
x-tls-cert | Cert file location. | |
x-tls-key | Key file location. | |
x-tls-insecure-skip-verify | Whether or not to use SSL (true|false) |
Use with existing client
If you use the MySQL driver with existing database client, you must create the client with parameter multiStatements=true
:
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"github.com/golang-migrate/migrate"
"github.com/golang-migrate/migrate/database/mysql"
_ "github.com/golang-migrate/migrate/source/file"
)
func main() {
db, _ := sql.Open("mysql", "user:password@tcp(host:port)/dbname?multiStatements=true")
driver, _ := mysql.WithInstance(db, &mysql.Config{})
m, _ := migrate.NewWithDatabaseInstance(
"file:///migrations",
"mysql",
driver,
)
m.Steps(2)
}
Upgrading from v1
- Write down the current migration version from schema_migrations
DROP TABLE schema_migrations
- Wrap your existing migrations in transactions (BEGIN/COMMIT) if you use multiple statements within one migration.
- Download and install the latest migrate version.
- Force the current migration version with
migrate force <current_version>
.
# Functions
instance must have `multiStatements` set to true.
# Variables
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author