-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmigration_0001_create_users_table.go
60 lines (49 loc) · 1.37 KB
/
migration_0001_create_users_table.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
50
51
52
53
54
55
56
57
58
59
60
/*
Copyright © 2025 Acronis International GmbH.
Released under MIT license.
*/
package main
import (
"github.com/acronis/go-dbkit"
"github.com/acronis/go-dbkit/migrate"
)
const migration0001CreateUsersTableUpMySQL = `
CREATE TABLE users (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL
);
`
const migration0001CreateUsersTableUpPostgres = `
CREATE TABLE users (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name VARCHAR(255) NOT NULL
);
`
const migration0001CreateUsersTableDown = `
DROP TABLE users;
`
type Migration0001CreateUsersTable struct {
*migrate.NullMigration
}
func NewMigration0001CreateUsersTable(dialect dbkit.Dialect) *Migration0001CreateUsersTable {
return &Migration0001CreateUsersTable{&migrate.NullMigration{Dialect: dialect}}
}
func (m *Migration0001CreateUsersTable) ID() string {
return "0001_create_users_table"
}
func (m *Migration0001CreateUsersTable) UpSQL() []string {
switch m.Dialect {
case dbkit.DialectMySQL:
return []string{migration0001CreateUsersTableUpMySQL}
case dbkit.DialectPgx, dbkit.DialectPostgres:
return []string{migration0001CreateUsersTableUpPostgres}
}
return nil
}
func (m *Migration0001CreateUsersTable) DownSQL() []string {
switch m.Dialect {
case dbkit.DialectMySQL, dbkit.DialectPgx, dbkit.DialectPostgres:
return []string{migration0001CreateUsersTableDown}
}
return nil
}