-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
49 lines (40 loc) · 1.25 KB
/
example_test.go
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
43
44
45
46
47
48
49
package rove_test
import (
"log"
"github.com/josephspurrier/rove"
"github.com/josephspurrier/rove/pkg/adapter/mysql"
)
func Example() {
var changesets = `
--changeset josephspurrier:1
CREATE TABLE user_status (
id TINYINT(1) UNSIGNED NOT NULL AUTO_INCREMENT,
status VARCHAR(25) NOT NULL,
created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id)
);
--rollback DROP TABLE user_status;
--changeset josephspurrier:2
INSERT INTO user_status (id, status, created_at, updated_at, deleted) VALUES
(1, 'active', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 0),
(2, 'inactive', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 0);
--rollback TRUNCATE TABLE user_status;`
// Create a new MySQL database object.
db, err := mysql.New(&mysql.Connection{
Hostname: "127.0.0.1",
Username: "root",
Password: "password",
Name: "main",
Port: 3306,
Parameter: "collation=utf8mb4_unicode_ci&parseTime=true&multiStatements=true",
})
if err != nil {
log.Fatalln(err)
}
// Perform all migrations against the database.
r := rove.NewChangesetMigration(db, changesets)
r.Verbose = true
r.Migrate(0)
}