forked from amakelov/parlamentaren-kontrol
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_db.sh
128 lines (108 loc) · 4.11 KB
/
create_db.sh
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
dropdb parlamentarenkontrol -U parlamentarenkontrol
createdb -E UTF8 parlamentarenkontrol -U parlamentarenkontrol
psql parlamentarenkontrol -U parlamentarenkontrol <<SQL
CREATE TABLE stenograms (
stenogram_date date PRIMARY KEY,
text text[],
vote_line_nb integer[],
problem bool,
original_url text UNIQUE NOT NULL
);
CREATE TABLE vote_sessions (
stenogram_date date REFERENCES stenograms (stenogram_date),
session_number integer,
description text,
time time,
PRIMARY KEY (stenogram_date, session_number)
);
CREATE TABLE parties (
party_name text PRIMARY KEY
);
CREATE TABLE mps (
mp_name text PRIMARY KEY,
email text[]
);
CREATE TABLE parliaments (
parliament integer PRIMARY KEY
);
CREATE TABLE elections (
mp_name text REFERENCES mps (mp_name),
orig_party_name text REFERENCES parties (party_name),
parliament integer REFERENCES parliaments (parliament),
original_url text UNIQUE NOT NULL,
PRIMARY KEY (mp_name, orig_party_name, parliament)
);
CREATE TYPE mp_vote_enum AS ENUM ('yes', 'no', 'abstain', 'absent');
CREATE TABLE mp_votes (
mp_name text REFERENCES mps (mp_name),
with_party text REFERENCES parties (party_name),
stenogram_date date,
session_number integer,
vote mp_vote_enum,
PRIMARY KEY (mp_name, stenogram_date, session_number),
FOREIGN KEY (stenogram_date, session_number) REFERENCES vote_sessions (stenogram_date, session_number)
);
CREATE TYPE mp_reg_enum AS ENUM ('present', 'absent', 'manually_registered');
CREATE TABLE mp_reg (
mp_name text REFERENCES mps (mp_name),
with_party text REFERENCES parties (party_name),
stenogram_date date REFERENCES stenograms (stenogram_date),
reg mp_reg_enum,
PRIMARY KEY (mp_name, stenogram_date)
);
CREATE TABLE party_votes (
party_name text REFERENCES parties (party_name),
stenogram_date date,
session_number integer,
yes integer,
no integer,
abstain integer,
total integer,
PRIMARY KEY (party_name, stenogram_date, session_number),
FOREIGN KEY (stenogram_date, session_number) REFERENCES vote_sessions (stenogram_date, session_number)
);
CREATE TABLE party_reg (
party_name text REFERENCES parties (party_name),
stenogram_date date REFERENCES stenograms (stenogram_date),
present integer,
expected integer,
PRIMARY KEY (party_name, stenogram_date)
);
CREATE TABLE bills (
bill_name text,
bill_signature text PRIMARY KEY,
bill_date date,
original_url text UNIQUE NOT NULL
);
CREATE TABLE bill_authors (
bill_signature text REFERENCES bills (bill_signature),
bill_author text REFERENCES mps (mp_name),
PRIMARY KEY (bill_signature, bill_author)
);
CREATE TABLE bills_by_government (
bill_signature text PRIMARY KEY REFERENCES bills (bill_signature)
);
CREATE TYPE bill_event AS ENUM ('proposed_1st', 'proposed_2nd',
'accepted_1st', 'accepted_2nd',
'rejected_1st', 'rejected_2nd',
'retracted',
'vetoed',
'proposed_after_veto',
'accepted_after_veto',
'challenged_after_veto'
);
CREATE TABLE bill_history (
bill_signature text REFERENCES bills (bill_signature),
event_date date,
event bill_event,
PRIMARY KEY (bill_signature, event_date, event)
);
CREATE TABLE laws (
bill_signature text PRIMARY KEY REFERENCES bills (bill_signature),
sg_issue int,
sg_year date,
text text
);
CREATE INDEX mp_votes_BY_stenogram_date_session_number ON mp_votes (stenogram_date, session_number);
CREATE EXTENSION first_last_agg;
SQL