Documentation
¶
Overview ¶
Package diff contains functions to generate SQL statements to migrate an old schema to the new schema
Example ¶
package main
import (
"os"
"github.com/shogo82148/schemalex-deploy/diff"
)
func main() {
const sql1 = `CREATE TABLE hoge (
id INTEGER NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
);`
const sql2 = `CREATE TABLE hoge (
id INTEGER NOT NULL AUTO_INCREMENT,
c VARCHAR (20) NOT NULL DEFAULT "hoge",
PRIMARY KEY (id)
);
CREATE TABLE fuga (
id INTEGER NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
);`
diff.Strings(os.Stdout, sql1, sql2, diff.WithTransaction(true))
}
Output: BEGIN; SET FOREIGN_KEY_CHECKS = 0; CREATE TABLE `fuga` ( `id` INT (11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ); ALTER TABLE `hoge` ADD COLUMN `c` VARCHAR (20) NOT NULL DEFAULT 'hoge' AFTER `id`; SET FOREIGN_KEY_CHECKS = 1; COMMIT;
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Statements ¶
Statements compares two model.Stmts and generates a series of statements to migrate from the old one to the new one, writing the result to `dst`
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithCurrentSchema ¶ added in v0.0.8
WithCurrentSchema specifies the current schema deployed in MySQL.
func WithIndent ¶ added in v0.0.8
WithIndent specifies the indent string to use, and the length. For example, if you specify WithIndent(" " /* single space */, 2), the indent will be 2 spaces per level.
Please note that no check on the string will be performed, so anything you specify will be used as-is.
func WithParser ¶
WithParser specifies the parser instance to use when parsing the statements given to the diffing functions. If unspecified, a default parser will be used
func WithTransaction ¶
WithTransaction specifies if statements to control transactions should be included in the diff.