/
0029_add_webhook_spec_tables.go
47 lines (39 loc) · 1.41 KB
/
0029_add_webhook_spec_tables.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
package migrations
import (
"gorm.io/gorm"
)
const up29 = `
CREATE TABLE webhook_specs (
id SERIAL PRIMARY KEY,
on_chain_job_spec_id uuid NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
ALTER TABLE jobs ADD COLUMN webhook_spec_id INT REFERENCES webhook_specs(id),
DROP CONSTRAINT chk_only_one_spec,
ADD CONSTRAINT chk_only_one_spec CHECK (
num_nonnulls(offchainreporting_oracle_spec_id, direct_request_spec_id, flux_monitor_spec_id, keeper_spec_id, cron_spec_id, vrf_spec_id, webhook_spec_id) = 1
);
ALTER TABLE direct_request_specs DROP CONSTRAINT direct_request_specs_on_chain_job_spec_id_check;
ALTER TABLE direct_request_specs DROP COLUMN on_chain_job_spec_id;
ALTER TABLE direct_request_specs ADD COLUMN on_chain_job_spec_id uuid NOT NULL;
`
const down29 = `
ALTER TABLE jobs DROP CONSTRAINT chk_only_one_spec,
ADD CONSTRAINT chk_only_one_spec CHECK (
num_nonnulls(offchainreporting_oracle_spec_id, direct_request_spec_id, flux_monitor_spec_id, keeper_spec_id, cron_spec_id, vrf_spec_id) = 1
);
ALTER TABLE jobs DROP COLUMN webhook_spec_id;
DROP TABLE IF EXISTS webhook_specs;
`
func init() {
Migrations = append(Migrations, &Migration{
ID: "0029_add_webhook_spec_tables",
Migrate: func(db *gorm.DB) error {
return db.Exec(up29).Error
},
Rollback: func(db *gorm.DB) error {
return db.Exec(down29).Error
},
})
}