-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmigrate_test.go
More file actions
53 lines (50 loc) · 1.71 KB
/
migrate_test.go
File metadata and controls
53 lines (50 loc) · 1.71 KB
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
50
51
52
53
package sq_test
import (
"context"
sq "github.com/goclub/sql"
)
type Migrate struct {
db *sq.Database
}
func (dep Migrate) Migrate20201004160444CreateUserTable() (err error) {
ctx := context.Background()
if _, err = dep.db.Exec(ctx, `
CREATE TABLE user (
id char(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
name varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
age int(11) NOT NULL DEFAULT '0',
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at timestamp NULL DEFAULT NULL,
PRIMARY KEY (id),
KEY name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
`, nil); err != nil {
return
}
if _, err = dep.db.Exec(ctx, `
CREATE TABLE user_address (
user_id char(36) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
address varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at timestamp NULL DEFAULT NULL,
PRIMARY KEY (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
`, nil); err != nil {
return
}
if _, err = dep.db.Exec(ctx, `
CREATE TABLE `+"`insert`"+` (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
age int(11) DEFAULT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
deleted_at timestamp NULL DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
`, nil); err != nil {
return
}
return
}