-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsql.upgrade
87 lines (64 loc) · 3.34 KB
/
psql.upgrade
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
ALTER TABLE "Slices" ADD COLUMN IF NOT EXISTS project_id VARCHAR;
ALTER TABLE "Slices" ADD COLUMN IF NOT EXISTS slc_state INTEGER;
ALTER TABLE "Reservations" ADD COLUMN IF NOT EXISTS project_id VARCHAR;
ALTER TABLE "Reservations" ADD COLUMN IF NOT EXISTS site VARCHAR;
ALTER TABLE "Reservations" ADD COLUMN IF NOT EXISTS rsv_type VARCHAR;
ALTER TABLE "Delegations" ADD COLUMN IF NOT EXISTS site VARCHAR;
UPDATE "Slices" set slc_state=2 where slc_name='broker';
CREATE SEQUENCE IF NOT EXISTS site_id start 1 increment 1;
CREATE TABLE IF NOT EXISTS "Sites" (
site_id INTEGER NOT NULL DEFAULT nextval('site_id') PRIMARY KEY,
name VARCHAR NOT NULL,
state INTEGER NOT NULL,
properties BYTEA
);
CREATE TABLE IF NOT EXISTS "Components" (
reservation_id INTEGER,
component VARCHAR,
PRIMARY KEY (reservation_id, component),
FOREIGN KEY (reservation_id) REFERENCES "Reservations"(rsv_id)
);
ALTER TABLE "Reservations" ADD COLUMN IF NOT EXISTS components VARCHAR;
-- Add new columns with the TIMESTAMP WITH TIME ZONE data type
ALTER TABLE "Reservations" ADD COLUMN lease_start_with_tz TIMESTAMPTZ;
ALTER TABLE "Reservations" ADD COLUMN lease_end_with_tz TIMESTAMPTZ;
-- Update the new columns with data from the existing columns
UPDATE "Reservations" SET lease_start_with_tz = lease_start::TIMESTAMPTZ;
UPDATE "Reservations" SET lease_end_with_tz = lease_end::TIMESTAMPTZ;
-- Drop the existing columns
ALTER TABLE "Reservations" DROP COLUMN lease_start;
ALTER TABLE "Reservations" DROP COLUMN lease_end;
-- Rename the new columns to the original column names
ALTER TABLE "Reservations" RENAME COLUMN lease_start_with_tz TO lease_start;
ALTER TABLE "Reservations" RENAME COLUMN lease_end_with_tz TO lease_end;
ALTER TABLE "Slices" ADD COLUMN IF NOT EXISTS components VARCHAR;
-- Add new columns with the TIMESTAMP WITH TIME ZONE data type
ALTER TABLE "Slices" ADD COLUMN lease_start_with_tz TIMESTAMPTZ;
ALTER TABLE "Slices" ADD COLUMN lease_end_with_tz TIMESTAMPTZ;
-- Update the new columns with data from the existing columns
UPDATE "Slices" SET lease_start_with_tz = lease_start::TIMESTAMPTZ;
UPDATE "Slices" SET lease_end_with_tz = lease_end::TIMESTAMPTZ;
-- Drop the existing columns
ALTER TABLE "Slices" DROP COLUMN lease_start;
ALTER TABLE "Slices" DROP COLUMN lease_end;
-- Rename the new columns to the original column names
ALTER TABLE "Slices" RENAME COLUMN lease_start_with_tz TO lease_start;
ALTER TABLE "Slices" RENAME COLUMN lease_end_with_tz TO lease_end;
-- Add new columns with the TIMESTAMP WITH TIME ZONE data type
ALTER TABLE "Poas" ADD COLUMN last_update_time_with_tz TIMESTAMPTZ;
-- Update the new columns with data from the existing columns
UPDATE "Poas" SET last_update_time_with_tz = last_update_time::TIMESTAMPTZ;
-- Drop the existing columns
ALTER TABLE "Poas" DROP COLUMN last_update_time;
-- Rename the new columns to the original column names
ALTER TABLE "Poas" RENAME COLUMN last_update_time_with_tz TO last_update_time;
CREATE TABLE IF NOT EXISTS "Metrics" (
m_id INTEGER NOT NULL DEFAULT nextval('m_id') PRIMARY KEY,
user_id VARCHAR NOT NULL,
project_id VARCHAR NOT NULL,
slice_count INTEGER NOT NULL,
);
ALTER TABLE "Reservations" ADD COLUMN host VARCHAR(255) NULL;
ALTER TABLE "Reservations" ADD COLUMN ip_subnet VARCHAR(255) NULL;
CREATE INDEX idx_host ON "Reservations"(host);
CREATE INDEX idx_ip_subnet ON "Reservations"(ip_subnet);