forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
117_add_next_build_inputs.go
76 lines (70 loc) · 1.85 KB
/
117_add_next_build_inputs.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
package migrations
import "github.com/concourse/atc/db/migration"
func AddNextBuildInputs(tx migration.LimitedTx) error {
_, err := tx.Exec(`
CREATE TABLE independent_build_inputs (
id serial PRIMARY KEY,
job_id integer NOT NULL,
CONSTRAINT independent_build_inputs_job_id_fkey
FOREIGN KEY (job_id)
REFERENCES jobs (id)
ON DELETE CASCADE,
input_name text NOT NULL,
CONSTRAINT independent_build_inputs_unique_job_id_input_name
UNIQUE (job_id, input_name),
version_id integer NOT NULL,
CONSTRAINT independent_build_inputs_version_id_fkey
FOREIGN KEY (version_id)
REFERENCES versioned_resources (id)
ON DELETE CASCADE,
first_occurrence bool NOT NULL
)
`)
if err != nil {
return err
}
_, err = tx.Exec(`
CREATE TABLE next_build_inputs (
id serial PRIMARY KEY,
job_id integer NOT NULL,
CONSTRAINT next_build_inputs_job_id_fkey
FOREIGN KEY (job_id)
REFERENCES jobs (id)
ON DELETE CASCADE,
input_name text NOT NULL,
CONSTRAINT next_build_inputs_unique_job_id_input_name
UNIQUE (job_id, input_name),
version_id integer NOT NULL,
CONSTRAINT next_build_inputs_version_id_fkey
FOREIGN KEY (version_id)
REFERENCES versioned_resources (id)
ON DELETE CASCADE,
first_occurrence bool NOT NULL
)
`)
if err != nil {
return err
}
_, err = tx.Exec(`
ALTER TABLE jobs
ADD COLUMN resource_check_finished_at timestamp NOT NULL DEFAULT 'epoch',
ADD COLUMN resource_check_waiver_end integer NOT NULL DEFAULT 0,
ADD COLUMN inputs_determined bool NOT NULL DEFAULT false,
ADD COLUMN max_in_flight_reached bool NOT NULL DEFAULT false
`)
if err != nil {
return err
}
_, err = tx.Exec(`
ALTER TABLE builds
DROP COLUMN inputs_determined,
DROP COLUMN last_scheduled
`)
if err != nil {
return err
}
_, err = tx.Exec(`
DROP TABLE build_preparation
`)
return err
}