-
Notifications
You must be signed in to change notification settings - Fork 28
/
table.go
74 lines (67 loc) · 1.65 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: Apache-2.0
package hook
import (
"context"
"github.com/go-vela/types/constants"
)
const (
// CreatePostgresTable represents a query to create the Postgres hooks table.
CreatePostgresTable = `
CREATE TABLE
IF NOT EXISTS
hooks (
id SERIAL PRIMARY KEY,
repo_id INTEGER,
build_id INTEGER,
number INTEGER,
source_id VARCHAR(250),
created INTEGER,
host VARCHAR(250),
event VARCHAR(250),
event_action VARCHAR(250),
branch VARCHAR(500),
error VARCHAR(500),
status VARCHAR(250),
link VARCHAR(1000),
webhook_id INTEGER,
UNIQUE(repo_id, number)
);
`
// CreateSqliteTable represents a query to create the Sqlite hooks table.
CreateSqliteTable = `
CREATE TABLE
IF NOT EXISTS
hooks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
repo_id INTEGER,
build_id INTEGER,
number INTEGER,
source_id TEXT,
created INTEGER,
host TEXT,
event TEXT,
event_action TEXT,
branch TEXT,
error TEXT,
status TEXT,
link TEXT,
webhook_id INTEGER,
UNIQUE(repo_id, number)
);
`
)
// CreateHookTable creates the hooks table in the database.
func (e *engine) CreateHookTable(ctx context.Context, driver string) error {
e.logger.Tracef("creating hooks table in the database")
// handle the driver provided to create the table
switch driver {
case constants.DriverPostgres:
// create the hooks table for Postgres
return e.client.Exec(CreatePostgresTable).Error
case constants.DriverSqlite:
fallthrough
default:
// create the hooks table for Sqlite
return e.client.Exec(CreateSqliteTable).Error
}
}