| author | Tomas Zeman <tzeman@volny.cz> |
| Tue, 05 Jun 2012 15:40:45 +0200 | |
| changeset 104 | ef29ecada49d |
| parent 101 | b6a00fd29998 |
| permissions | -rw-r--r-- |
|
98
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
1 |
-- DATABASE SCHEMA CHANGES BETWEEN 0.2 -> 0.3 VERSION |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
2 |
|
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
3 |
-- project_location |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
4 |
create table "project_location" ( |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
5 |
"location" bigint not null, |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
6 |
"project" bigint not null |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
7 |
); |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
8 |
alter table "project_location" add foreign key ("project") references "project"("id") on delete cascade;
|
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
9 |
alter table "project_location" add foreign key ("location") references "location"("id") on delete cascade;
|
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
diff
changeset
|
10 |
alter table "project_location" add unique("project","location");
|
| 99 | 11 |
|
12 |
-- service |
|
13 |
create table "service" ( |
|
14 |
"name" varchar(100) not null, |
|
15 |
"updated_at" timestamp not null, |
|
16 |
"id" bigint primary key not null, |
|
17 |
"to" timestamp, |
|
18 |
"state" bigint not null, |
|
19 |
"company" bigint not null, |
|
20 |
"note" varchar(10240), |
|
21 |
"from" timestamp not null, |
|
22 |
"created_at" timestamp not null, |
|
23 |
"created_by" bigint, |
|
24 |
"updated_by" bigint |
|
25 |
); |
|
26 |
create sequence "service_id_seq"; |
|
27 |
alter table "service" add foreign key ("company") references "company"("id");
|
|
28 |
alter table "service" add foreign key ("state") references "code_list_item"("id");
|
|
29 |
||
30 |
-- service payment |
|
31 |
create table "service_payment" ( |
|
32 |
"id" bigint primary key not null, |
|
33 |
"service" bigint not null, |
|
34 |
"direction" integer not null, |
|
35 |
"period" bigint not null, |
|
36 |
"amount" numeric(16,2) not null, |
|
37 |
"currency" bigint not null |
|
38 |
); |
|
39 |
create sequence "service_payment_id_seq"; |
|
40 |
alter table "service_payment" add foreign key ("service") references "service"("id") on delete cascade;
|
|
41 |
alter table "service_payment" add foreign key ("period") references "code_list_item"("id");
|
|
42 |
alter table "service_payment" add foreign key ("currency") references "code_list_item"("id");
|
|
43 |
||
| 100 | 44 |
-- attachments |
45 |
create table "attachment" ( |
|
46 |
"name" varchar(100) not null, |
|
47 |
"updated_at" timestamp not null, |
|
48 |
"id" bigint primary key not null, |
|
49 |
"mime_type" varchar(80) not null, |
|
50 |
"note" varchar(10240), |
|
51 |
"content_id" varchar(20) not null, |
|
52 |
"size" bigint not null, |
|
53 |
"created_at" timestamp not null, |
|
54 |
"created_by" bigint, |
|
55 |
"updated_by" bigint |
|
56 |
); |
|
57 |
create sequence "attachment_id_seq"; |
|
58 |
create table "project_attachment" ( |
|
59 |
"project" bigint not null, |
|
60 |
"attachment" bigint not null |
|
61 |
); |
|
62 |
create table "task_attachment" ( |
|
63 |
"task" bigint not null, |
|
64 |
"attachment" bigint not null |
|
65 |
); |
|
66 |
alter table "project_attachment" add foreign key ("project") references "project"("id") on delete cascade;
|
|
67 |
alter table "project_attachment" add foreign key ("attachment") references "attachment"("id") on delete cascade;
|
|
68 |
alter table "task_attachment" add foreign key ("task") references "task"("id") on delete cascade;
|
|
69 |
alter table "task_attachment" add foreign key ("attachment") references "attachment"("id") on delete cascade;
|
|
70 |
alter table "project_attachment" add unique("project","attachment");
|
|
71 |
alter table "task_attachment" add unique("task","attachment");
|
|
| 101 | 72 |
|
73 |
-- task number |
|
74 |
create sequence task_2012; |
|
75 |
create sequence task_2013; |
|
76 |
create sequence task_2014; |
|
77 |
create sequence task_2015; |
|
78 |
create sequence task_2016; |
|
79 |
create sequence task_2017; |
|
80 |
create sequence task_2018; |
|
81 |
create sequence task_2019; |
|
82 |
create sequence task_2020; |
|
83 |
ALTER TABLE task ADD num integer; |
|
84 |
CREATE VIEW vtask AS SELECT * FROM task ORDER BY id; |
|
85 |
CREATE RULE rtask AS ON UPDATE TO vtask DO INSTEAD UPDATE task SET num = NEW.num WHERE id = NEW.id; |
|
86 |
UPDATE vtask SET num = nextval('task_2012');
|
|
87 |
DROP RULE rtask ON vtask; |
|
88 |
DROP VIEW vtask; |
|
89 |
ALTER TABLE task ALTER COLUMN num SET NOT NULL; |
|
|
104
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
90 |
|
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
91 |
-- project extensions |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
92 |
UPDATE code_list_item SET s1 = 'closed', i1 = 0 WHERE code_list = 'project_state' AND i1 = 1; |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
93 |
UPDATE code_list_item SET s1 = 'assigned' WHERE code_list = 'project_state' AND name LIKE '%assigned'; |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
94 |
ALTER TABLE project ADD COLUMN phase bigint; |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
95 |
alter table "project" add foreign key ("phase") references "code_list_item"("id");
|
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
96 |
UPDATE project SET phase = (select id from code_list_item where name = 'project.phase.offer'); |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
97 |
ALTER TABLE project ALTER COLUMN phase SET NOT NULL; |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
98 |
ALTER TABLE project ADD COLUMN "location_a" varchar(1024); |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
99 |
ALTER TABLE project ADD COLUMN "location_b" varchar(1024); |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
100 |
UPDATE project SET location_a = '', location_b = ''; |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
101 |
ALTER TABLE project ALTER COLUMN "location_a" SET NOT NULL ; |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
102 |
ALTER TABLE project ALTER COLUMN "location_b" SET NOT NULL ; |
|
ef29ecada49d
d6925c97404faf15 Project extensions
Tomas Zeman <tzeman@volny.cz>
parents:
101
diff
changeset
|
103 |