forked from vmware-archive/atc
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
164_add_worker_task_caches.go
61 lines (56 loc) · 1.35 KB
/
164_add_worker_task_caches.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
package migrations
import "github.com/concourse/atc/db/migration"
func AddWorkerTaskCaches(tx migration.LimitedTx) error {
_, err := tx.Exec(`
CREATE TABLE worker_task_caches (
id serial PRIMARY KEY,
worker_name text REFERENCES workers (name) ON DELETE CASCADE,
job_id int REFERENCES jobs (id) ON DELETE CASCADE,
step_name text NOT NULL,
path text NOT NULL
)
`)
if err != nil {
return err
}
_, err = tx.Exec(`
ALTER TABLE volumes
ADD COLUMN worker_task_cache_id int REFERENCES worker_task_caches (id) ON DELETE SET NULL,
DROP CONSTRAINT cannot_invalidate_during_initialization
`)
if err != nil {
return err
}
_, err = tx.Exec(`
ALTER TABLE volumes
ADD CONSTRAINT cannot_invalidate_during_initialization CHECK (
(
state IN ('created', 'destroying') AND (
(
worker_resource_cache_id IS NULL
) AND (
worker_base_resource_type_id IS NULL
) AND (
worker_task_cache_id IS NULL
) AND (
container_id IS NULL
)
)
) OR (
(
worker_resource_cache_id IS NOT NULL
) OR (
worker_base_resource_type_id IS NOT NULL
) OR (
worker_task_cache_id IS NOT NULL
) OR (
container_id IS NOT NULL
)
)
)
`)
if err != nil {
return err
}
return nil
}