-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmigration_0002_create_notes_table.go
48 lines (41 loc) · 1.24 KB
/
migration_0002_create_notes_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
/*
Copyright © 2025 Acronis International GmbH.
Released under MIT license.
*/
package main
import (
"github.com/acronis/go-dbkit"
"github.com/acronis/go-dbkit/migrate"
)
const migration0002CreateNotesTableUpMySQL = `
CREATE TABLE notes (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
content TEXT,
user_id BIGINT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
`
const migration0002CreateNotesTableUpPostgres = `
CREATE TABLE notes (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
content TEXT,
user_id BIGINT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
`
const migration0002CreateNotesTableDown = `
DROP TABLE notes;
`
func NewMigration0002CreateNotesTable(dialect dbkit.Dialect) *migrate.CustomMigration {
var upSQL []string
var downSQL []string
switch dialect {
case dbkit.DialectMySQL:
upSQL = []string{migration0002CreateNotesTableUpMySQL}
downSQL = []string{migration0002CreateNotesTableDown}
case dbkit.DialectPgx, dbkit.DialectPostgres:
upSQL = []string{migration0002CreateNotesTableUpPostgres}
downSQL = []string{migration0002CreateNotesTableDown}
}
return migrate.NewCustomMigration("0002_create_notes_table", upSQL, downSQL, nil, nil)
}