-
Notifications
You must be signed in to change notification settings - Fork 69
/
schema_v1.go
111 lines (96 loc) · 2.84 KB
/
schema_v1.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package db
type v1Schema struct{}
func (s v1Schema) Deploy(db *DB) error {
err := db.Exec(`CREATE TABLE schema_info (
version INTEGER
)`)
if err != nil {
return err
}
err = db.Exec(`INSERT INTO schema_info VALUES (1)`)
if err != nil {
return err
}
err = db.Exec(`CREATE TABLE targets (
uuid UUID PRIMARY KEY,
name TEXT,
summary TEXT,
plugin TEXT NOT NULL,
endpoint TEXT NOT NULL,
agent TEXT NOT NULL
)`)
if err != nil {
return err
}
err = db.Exec(`CREATE TABLE stores (
uuid UUID PRIMARY KEY,
name TEXT,
summary TEXT,
plugin TEXT NOT NULL,
endpoint TEXT NOT NULL
)`)
if err != nil {
return err
}
err = db.Exec(`CREATE TABLE schedules (
uuid UUID PRIMARY KEY,
name TEXT,
summary TEXT,
timespec TEXT NOT NULL
)`)
if err != nil {
return err
}
err = db.Exec(`CREATE TABLE retention (
uuid UUID PRIMARY KEY,
name TEXT,
summary TEXT,
expiry INTEGER NOT NULL
)`)
if err != nil {
return err
}
err = db.Exec(`CREATE TABLE jobs (
uuid UUID PRIMARY KEY,
target_uuid UUID NOT NULL,
store_uuid UUID NOT NULL,
schedule_uuid UUID NOT NULL,
retention_uuid UUID NOT NULL,
priority INTEGER DEFAULT 50,
paused BOOLEAN,
name TEXT,
summary TEXT
)`)
if err != nil {
return err
}
err = db.Exec(`CREATE TABLE archives (
uuid UUID PRIMARY KEY,
target_uuid UUID NOT NULL,
store_uuid UUID NOT NULL,
store_key TEXT NOT NULL,
taken_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
notes TEXT DEFAULT ''
)`)
if err != nil {
return err
}
err = db.Exec(`CREATE TABLE tasks (
uuid UUID PRIMARY KEY,
owner TEXT,
op TEXT NOT NULL,
job_uuid UUID,
archive_uuid UUID,
target_uuid UUID,
status TEXT NOT NULL,
requested_at INTEGER NOT NULL,
started_at INTEGER,
stopped_at INTEGER,
log TEXT
)`)
if err != nil {
return err
}
return nil
}