forked from schemalex/schemalex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
42 lines (36 loc) · 802 Bytes
/
example_test.go
File metadata and controls
42 lines (36 loc) · 802 Bytes
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
package schemalex_test
import (
"os"
"github.com/schemalex/schemalex/diff"
)
func Example() {
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;
}