-
Notifications
You must be signed in to change notification settings - Fork 28
/
table.go
80 lines (73 loc) · 2.02 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
75
76
77
78
79
80
// SPDX-License-Identifier: Apache-2.0
package secret
import (
"context"
"github.com/go-vela/types/constants"
)
const (
// CreatePostgresTable represents a query to create the Postgres secrets table.
CreatePostgresTable = `
CREATE TABLE
IF NOT EXISTS
secrets (
id SERIAL PRIMARY KEY,
type VARCHAR(100),
org VARCHAR(250),
repo VARCHAR(250),
team VARCHAR(250),
name VARCHAR(250),
value BYTEA,
images VARCHAR(1000),
events VARCHAR(1000),
allow_events INTEGER,
allow_command BOOLEAN,
allow_substitution BOOLEAN,
created_at INTEGER,
created_by VARCHAR(250),
updated_at INTEGER,
updated_by VARCHAR(250),
UNIQUE(type, org, repo, name),
UNIQUE(type, org, team, name)
);
`
// CreateSqliteTable represents a query to create the Sqlite secrets table.
CreateSqliteTable = `
CREATE TABLE
IF NOT EXISTS
secrets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT,
org TEXT,
repo TEXT,
team TEXT,
name TEXT,
value TEXT,
images TEXT,
events TEXT,
allow_events INTEGER,
allow_command BOOLEAN,
allow_substitution BOOLEAN,
created_at INTEGER,
created_by TEXT,
updated_at INTEGER,
updated_by TEXT,
UNIQUE(type, org, repo, name),
UNIQUE(type, org, team, name)
);
`
)
// CreateSecretTable creates the secrets table in the database.
func (e *engine) CreateSecretTable(ctx context.Context, driver string) error {
e.logger.Tracef("creating secrets table in the database")
// handle the driver provided to create the table
switch driver {
case constants.DriverPostgres:
// create the secrets table for Postgres
return e.client.Exec(CreatePostgresTable).Error
case constants.DriverSqlite:
fallthrough
default:
// create the secrets table for Sqlite
return e.client.Exec(CreateSqliteTable).Error
}
}