forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
01_initial_schema.go
112 lines (102 loc) · 2.24 KB
/
01_initial_schema.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
112
package migrations
import "github.com/concourse/atc/db/migration"
func InitialSchema(tx migration.LimitedTx) error {
_, err := tx.Exec(`
CREATE TYPE build_status AS ENUM (
'pending',
'started',
'aborted',
'succeeded',
'failed',
'errored'
)
`)
if err != nil {
return err
}
// only for reference; configuration is not duped into db
_, err = tx.Exec(`
CREATE TABLE jobs (
name text PRIMARY KEY,
build_number_seq integer NOT NULL DEFAULT 0
)
`)
if err != nil {
return err
}
// only for reference; configuration is denormalized in resource instances
_, err = tx.Exec(`
CREATE TABLE resources (
name text PRIMARY KEY
)
`)
if err != nil {
return err
}
// all builds
_, err = tx.Exec(`
CREATE TABLE builds (
id serial PRIMARY KEY,
job_name text REFERENCES jobs (name),
name text NOT NULL,
status build_status NOT NULL,
scheduled boolean NOT NULL DEFAULT false,
abort_url varchar(255),
log text NOT NULL DEFAULT '',
UNIQUE (job_name, name)
)
`)
if err != nil {
return err
}
// denormalized resource information
_, err = tx.Exec(`
CREATE TABLE versioned_resources (
id serial PRIMARY KEY,
resource_name text REFERENCES resources (name),
version text NOT NULL,
UNIQUE (resource_name, version)
)
`)
if err != nil {
return err
}
// input references for a build
_, err = tx.Exec(`
CREATE TABLE build_inputs (
build_id integer REFERENCES builds (id),
versioned_resource_id integer REFERENCES versioned_resources (id),
source text NOT NULL,
metadata text NOT NULL
)
`)
if err != nil {
return err
}
// versions generated by a build's output
_, err = tx.Exec(`
CREATE TABLE build_outputs (
build_id integer REFERENCES builds (id),
versioned_resource_id integer REFERENCES versioned_resources (id),
source text NOT NULL,
metadata text NOT NULL
)
`)
if err != nil {
return err
}
// current version for a build's input
// to be replaced with entries in versioned_resources
_, err = tx.Exec(`
CREATE TABLE transitional_current_versions (
id serial PRIMARY KEY,
job_name text REFERENCES jobs (name),
resource_name text REFERENCES resources (name),
version text NOT NULL
)
`)
if err != nil {
return err
}
return nil
}