composite_primary_keys 7.0.16 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +600 -623
- data/lib/composite_primary_keys.rb +113 -115
- data/lib/composite_primary_keys/associations/association.rb +23 -23
- data/lib/composite_primary_keys/associations/association_scope.rb +73 -77
- data/lib/composite_primary_keys/associations/collection_association.rb +15 -0
- data/lib/composite_primary_keys/associations/has_many_association.rb +69 -56
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +30 -28
- data/lib/composite_primary_keys/associations/join_dependency.rb +87 -89
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
- data/lib/composite_primary_keys/associations/preloader/association.rb +90 -78
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
- data/lib/composite_primary_keys/associations/singular_association.rb +15 -0
- data/lib/composite_primary_keys/attribute_methods.rb +9 -0
- data/lib/composite_primary_keys/attribute_methods/dirty.rb +29 -26
- data/lib/composite_primary_keys/attribute_methods/read.rb +19 -34
- data/lib/composite_primary_keys/attribute_methods/write.rb +30 -36
- data/lib/composite_primary_keys/attribute_set/builder.rb +20 -0
- data/lib/composite_primary_keys/base.rb +135 -129
- data/lib/composite_primary_keys/composite_arrays.rb +30 -30
- data/lib/composite_primary_keys/composite_predicates.rb +50 -50
- data/lib/composite_primary_keys/composite_relation.rb +48 -48
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -4
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +46 -60
- data/lib/composite_primary_keys/core.rb +69 -47
- data/lib/composite_primary_keys/fixtures.rb +22 -22
- data/lib/composite_primary_keys/persistence.rb +56 -60
- data/lib/composite_primary_keys/relation.rb +68 -56
- data/lib/composite_primary_keys/relation/calculations.rb +79 -75
- data/lib/composite_primary_keys/relation/finder_methods.rb +175 -196
- data/lib/composite_primary_keys/relation/query_methods.rb +40 -40
- data/lib/composite_primary_keys/sanitization.rb +52 -52
- data/lib/composite_primary_keys/validations/uniqueness.rb +36 -37
- data/lib/composite_primary_keys/version.rb +8 -8
- data/tasks/databases/oracle.rake +25 -25
- data/tasks/databases/sqlserver.rake +27 -40
- data/test/abstract_unit.rb +113 -113
- data/test/connections/databases.ci.yml +15 -15
- data/test/connections/databases.example.yml +18 -18
- data/test/connections/native_oracle/connection.rb +11 -11
- data/test/connections/native_oracle_enhanced/connection.rb +16 -16
- data/test/connections/native_sqlserver/connection.rb +11 -14
- data/test/fixtures/comment.rb +7 -7
- data/test/fixtures/db_definitions/db2-create-tables.sql +125 -126
- data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
- data/test/fixtures/db_definitions/mysql.sql +207 -208
- data/test/fixtures/db_definitions/oracle.drop.sql +45 -45
- data/test/fixtures/db_definitions/oracle.sql +222 -223
- data/test/fixtures/db_definitions/postgresql.sql +209 -210
- data/test/fixtures/db_definitions/sqlite.sql +196 -197
- data/test/fixtures/db_definitions/sqlserver.drop.sql +91 -94
- data/test/fixtures/db_definitions/sqlserver.sql +225 -232
- data/test/fixtures/dorm.rb +2 -2
- data/test/fixtures/employee.rb +5 -5
- data/test/fixtures/membership.rb +6 -6
- data/test/fixtures/membership_statuses.yml +16 -16
- data/test/fixtures/memberships.yml +10 -10
- data/test/fixtures/product_tariffs.yml +14 -14
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/restaurants_suburb.rb +2 -2
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/topic.rb +5 -5
- data/test/fixtures/topic_source.rb +6 -6
- data/test/fixtures/topic_sources.yml +3 -3
- data/test/fixtures/topics.yml +8 -8
- data/test/fixtures/users.yml +10 -10
- data/test/test_associations.rb +295 -275
- data/test/test_attribute_methods.rb +63 -63
- data/test/test_attributes.rb +60 -60
- data/test/test_calculations.rb +37 -42
- data/test/test_callbacks.rb +99 -99
- data/test/test_create.rb +112 -112
- data/test/test_delete.rb +148 -152
- data/test/test_delete_all.rb +28 -26
- data/test/test_dumpable.rb +15 -15
- data/test/test_enum.rb +21 -20
- data/test/test_equal.rb +26 -26
- data/test/test_find.rb +118 -118
- data/test/test_habtm.rb +113 -113
- data/test/test_nested_attributes.rb +124 -124
- data/test/test_polymorphic.rb +26 -26
- data/test/test_predicates.rb +40 -40
- data/test/test_santiago.rb +23 -23
- data/test/test_suite.rb +33 -34
- data/test/test_touch.rb +23 -23
- data/test/test_tutorial_example.rb +21 -21
- data/test/test_update.rb +71 -71
- metadata +9 -13
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -20
- data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +0 -59
- data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +0 -39
- data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +0 -46
- data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +0 -17
- data/lib/composite_primary_keys/locking/optimistic.rb +0 -55
- data/test/test_optimistic.rb +0 -18
@@ -1,223 +1,222 @@
|
|
1
|
-
create sequence topics_seq start with 1000;
|
2
|
-
|
3
|
-
create table topics (
|
4
|
-
id number(11) primary key,
|
5
|
-
name varchar(50) default null,
|
6
|
-
feed_size number(11) default null,
|
7
|
-
);
|
8
|
-
|
9
|
-
create table topic_sources (
|
10
|
-
topic_id number(11),
|
11
|
-
platform varchar(50),
|
12
|
-
keywords varchar(50) default null,
|
13
|
-
);
|
14
|
-
|
15
|
-
create sequence reference_types_seq start with 1000;
|
16
|
-
|
17
|
-
create table reference_types (
|
18
|
-
reference_type_id number(11) primary key,
|
19
|
-
type_label varchar2(50) default null,
|
20
|
-
abbreviation varchar2(50) default null,
|
21
|
-
description varchar2(50) default null
|
22
|
-
);
|
23
|
-
|
24
|
-
create table reference_codes (
|
25
|
-
reference_type_id number(11),
|
26
|
-
reference_code number(11),
|
27
|
-
code_label varchar2(50) default null,
|
28
|
-
abbreviation varchar2(50) default null,
|
29
|
-
description varchar2(50) default null
|
30
|
-
);
|
31
|
-
|
32
|
-
create sequence products_seq start with 1000;
|
33
|
-
|
34
|
-
create table products (
|
35
|
-
id number(11) primary key,
|
36
|
-
name varchar2(50) default null
|
37
|
-
);
|
38
|
-
|
39
|
-
create table tariffs (
|
40
|
-
tariff_id number(11),
|
41
|
-
start_date date,
|
42
|
-
amount number(11) default null,
|
43
|
-
constraint tariffs_pk primary key (tariff_id, start_date)
|
44
|
-
);
|
45
|
-
|
46
|
-
create table product_tariffs (
|
47
|
-
product_id number(11),
|
48
|
-
tariff_id number(11),
|
49
|
-
tariff_start_date date,
|
50
|
-
constraint product_tariffs_pk primary key (product_id, tariff_id, tariff_start_date)
|
51
|
-
);
|
52
|
-
|
53
|
-
create table suburbs (
|
54
|
-
city_id number(11),
|
55
|
-
suburb_id number(11),
|
56
|
-
name varchar2(50) not null,
|
57
|
-
constraint suburbs_pk primary key (city_id, suburb_id)
|
58
|
-
);
|
59
|
-
|
60
|
-
create sequence streets_seq start with 1000;
|
61
|
-
|
62
|
-
create table streets (
|
63
|
-
id number(11) primary key,
|
64
|
-
city_id number(11) not null,
|
65
|
-
suburb_id number(11) not null,
|
66
|
-
name varchar2(50) not null
|
67
|
-
);
|
68
|
-
|
69
|
-
create sequence users_seq start with 1000;
|
70
|
-
|
71
|
-
create table users (
|
72
|
-
id number(11) primary key,
|
73
|
-
name varchar2(50) not null
|
74
|
-
);
|
75
|
-
|
76
|
-
create sequence articles_seq start with 1000;
|
77
|
-
|
78
|
-
create table articles (
|
79
|
-
id number(11) primary key,
|
80
|
-
name varchar2(50) not null
|
81
|
-
);
|
82
|
-
|
83
|
-
create sequence readings_seq start with 1000;
|
84
|
-
|
85
|
-
create table readings (
|
86
|
-
id number(11) primary key,
|
87
|
-
user_id number(11) not null,
|
88
|
-
article_id number(11) not null,
|
89
|
-
rating number(11) not null
|
90
|
-
);
|
91
|
-
|
92
|
-
create sequence groups_seq start with 1000;
|
93
|
-
|
94
|
-
create table groups (
|
95
|
-
id number(11) primary key,
|
96
|
-
name varchar2(50) not null
|
97
|
-
);
|
98
|
-
|
99
|
-
create table memberships (
|
100
|
-
user_id number(11) not null,
|
101
|
-
group_id number(11) not null,
|
102
|
-
constraint memberships_pk primary key (user_id, group_id)
|
103
|
-
);
|
104
|
-
|
105
|
-
create sequence membership_statuses_seq start with 1000;
|
106
|
-
|
107
|
-
create table membership_statuses (
|
108
|
-
id number(11) primary key,
|
109
|
-
user_id number(11) not null,
|
110
|
-
group_id number(11) not null,
|
111
|
-
status varchar2(50) not null
|
112
|
-
);
|
113
|
-
|
114
|
-
create table departments (
|
115
|
-
department_id number(11) not null,
|
116
|
-
location_id number(11) not null,
|
117
|
-
constraint departments_pk primary key (department_id, location_id)
|
118
|
-
);
|
119
|
-
|
120
|
-
create sequence employees_seq start with 1000;
|
121
|
-
|
122
|
-
create table employees (
|
123
|
-
id number(11) not null primary key,
|
124
|
-
department_id number(11) default null,
|
125
|
-
location_id number(11) default null
|
126
|
-
);
|
127
|
-
|
128
|
-
create sequence comments_seq start with 1000;
|
129
|
-
|
130
|
-
create table comments (
|
131
|
-
id number(11) not null primary key,
|
132
|
-
person_id number(11) default null,
|
133
|
-
shown number(11) default null,
|
134
|
-
person_type varchar(100) default null,
|
135
|
-
hack_id number(11) default null
|
136
|
-
);
|
137
|
-
|
138
|
-
create sequence hacks_seq start with 1000;
|
139
|
-
|
140
|
-
create table hacks (
|
141
|
-
id number(11) not null primary key,
|
142
|
-
name varchar(50) not null
|
143
|
-
);
|
144
|
-
|
145
|
-
create table restaurants (
|
146
|
-
franchise_id number(11) not null,
|
147
|
-
store_id number(11) not null,
|
148
|
-
name varchar(100),
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
1
|
+
create sequence topics_seq start with 1000;
|
2
|
+
|
3
|
+
create table topics (
|
4
|
+
id number(11) primary key,
|
5
|
+
name varchar(50) default null,
|
6
|
+
feed_size number(11) default null,
|
7
|
+
);
|
8
|
+
|
9
|
+
create table topic_sources (
|
10
|
+
topic_id number(11),
|
11
|
+
platform varchar(50),
|
12
|
+
keywords varchar(50) default null,
|
13
|
+
);
|
14
|
+
|
15
|
+
create sequence reference_types_seq start with 1000;
|
16
|
+
|
17
|
+
create table reference_types (
|
18
|
+
reference_type_id number(11) primary key,
|
19
|
+
type_label varchar2(50) default null,
|
20
|
+
abbreviation varchar2(50) default null,
|
21
|
+
description varchar2(50) default null
|
22
|
+
);
|
23
|
+
|
24
|
+
create table reference_codes (
|
25
|
+
reference_type_id number(11),
|
26
|
+
reference_code number(11),
|
27
|
+
code_label varchar2(50) default null,
|
28
|
+
abbreviation varchar2(50) default null,
|
29
|
+
description varchar2(50) default null
|
30
|
+
);
|
31
|
+
|
32
|
+
create sequence products_seq start with 1000;
|
33
|
+
|
34
|
+
create table products (
|
35
|
+
id number(11) primary key,
|
36
|
+
name varchar2(50) default null
|
37
|
+
);
|
38
|
+
|
39
|
+
create table tariffs (
|
40
|
+
tariff_id number(11),
|
41
|
+
start_date date,
|
42
|
+
amount number(11) default null,
|
43
|
+
constraint tariffs_pk primary key (tariff_id, start_date)
|
44
|
+
);
|
45
|
+
|
46
|
+
create table product_tariffs (
|
47
|
+
product_id number(11),
|
48
|
+
tariff_id number(11),
|
49
|
+
tariff_start_date date,
|
50
|
+
constraint product_tariffs_pk primary key (product_id, tariff_id, tariff_start_date)
|
51
|
+
);
|
52
|
+
|
53
|
+
create table suburbs (
|
54
|
+
city_id number(11),
|
55
|
+
suburb_id number(11),
|
56
|
+
name varchar2(50) not null,
|
57
|
+
constraint suburbs_pk primary key (city_id, suburb_id)
|
58
|
+
);
|
59
|
+
|
60
|
+
create sequence streets_seq start with 1000;
|
61
|
+
|
62
|
+
create table streets (
|
63
|
+
id number(11) primary key,
|
64
|
+
city_id number(11) not null,
|
65
|
+
suburb_id number(11) not null,
|
66
|
+
name varchar2(50) not null
|
67
|
+
);
|
68
|
+
|
69
|
+
create sequence users_seq start with 1000;
|
70
|
+
|
71
|
+
create table users (
|
72
|
+
id number(11) primary key,
|
73
|
+
name varchar2(50) not null
|
74
|
+
);
|
75
|
+
|
76
|
+
create sequence articles_seq start with 1000;
|
77
|
+
|
78
|
+
create table articles (
|
79
|
+
id number(11) primary key,
|
80
|
+
name varchar2(50) not null
|
81
|
+
);
|
82
|
+
|
83
|
+
create sequence readings_seq start with 1000;
|
84
|
+
|
85
|
+
create table readings (
|
86
|
+
id number(11) primary key,
|
87
|
+
user_id number(11) not null,
|
88
|
+
article_id number(11) not null,
|
89
|
+
rating number(11) not null
|
90
|
+
);
|
91
|
+
|
92
|
+
create sequence groups_seq start with 1000;
|
93
|
+
|
94
|
+
create table groups (
|
95
|
+
id number(11) primary key,
|
96
|
+
name varchar2(50) not null
|
97
|
+
);
|
98
|
+
|
99
|
+
create table memberships (
|
100
|
+
user_id number(11) not null,
|
101
|
+
group_id number(11) not null,
|
102
|
+
constraint memberships_pk primary key (user_id, group_id)
|
103
|
+
);
|
104
|
+
|
105
|
+
create sequence membership_statuses_seq start with 1000;
|
106
|
+
|
107
|
+
create table membership_statuses (
|
108
|
+
id number(11) primary key,
|
109
|
+
user_id number(11) not null,
|
110
|
+
group_id number(11) not null,
|
111
|
+
status varchar2(50) not null
|
112
|
+
);
|
113
|
+
|
114
|
+
create table departments (
|
115
|
+
department_id number(11) not null,
|
116
|
+
location_id number(11) not null,
|
117
|
+
constraint departments_pk primary key (department_id, location_id)
|
118
|
+
);
|
119
|
+
|
120
|
+
create sequence employees_seq start with 1000;
|
121
|
+
|
122
|
+
create table employees (
|
123
|
+
id number(11) not null primary key,
|
124
|
+
department_id number(11) default null,
|
125
|
+
location_id number(11) default null
|
126
|
+
);
|
127
|
+
|
128
|
+
create sequence comments_seq start with 1000;
|
129
|
+
|
130
|
+
create table comments (
|
131
|
+
id number(11) not null primary key,
|
132
|
+
person_id number(11) default null,
|
133
|
+
shown number(11) default null,
|
134
|
+
person_type varchar(100) default null,
|
135
|
+
hack_id number(11) default null
|
136
|
+
);
|
137
|
+
|
138
|
+
create sequence hacks_seq start with 1000;
|
139
|
+
|
140
|
+
create table hacks (
|
141
|
+
id number(11) not null primary key,
|
142
|
+
name varchar(50) not null
|
143
|
+
);
|
144
|
+
|
145
|
+
create table restaurants (
|
146
|
+
franchise_id number(11) not null,
|
147
|
+
store_id number(11) not null,
|
148
|
+
name varchar(100),
|
149
|
+
constraint restaurants_pk primary key (franchise_id, store_id)
|
150
|
+
);
|
151
|
+
|
152
|
+
create table restaurants_suburbs (
|
153
|
+
franchise_id number(11) not null,
|
154
|
+
store_id number(11) not null,
|
155
|
+
city_id number(11) not null,
|
156
|
+
suburb_id number(11) not null
|
157
|
+
);
|
158
|
+
|
159
|
+
create sequence dorms_seq start with 1000;
|
160
|
+
|
161
|
+
create table dorms (
|
162
|
+
id number(11) not null,
|
163
|
+
constraint dorms_pk primary key (id)
|
164
|
+
);
|
165
|
+
|
166
|
+
create table rooms (
|
167
|
+
dorm_id number(11) not null,
|
168
|
+
room_id number(11) not null,
|
169
|
+
constraint rooms_pk primary key (dorm_id, room_id)
|
170
|
+
);
|
171
|
+
|
172
|
+
create sequence room_attributes_seq start with 1000;
|
173
|
+
|
174
|
+
create table room_attributes (
|
175
|
+
id number(11) not null,
|
176
|
+
name varchar(50),
|
177
|
+
constraint room_attributes_pk primary key (id)
|
178
|
+
);
|
179
|
+
|
180
|
+
create table room_attribute_assignments (
|
181
|
+
dorm_id number(11) not null,
|
182
|
+
room_id number(11) not null,
|
183
|
+
room_attribute_id number(11) not null
|
184
|
+
);
|
185
|
+
|
186
|
+
create sequence students_seq start with 1000;
|
187
|
+
|
188
|
+
create table students (
|
189
|
+
id number(11) not null,
|
190
|
+
constraint students_pk primary key (id)
|
191
|
+
);
|
192
|
+
|
193
|
+
create table room_assignments (
|
194
|
+
student_id number(11) not null,
|
195
|
+
dorm_id number(11) not null,
|
196
|
+
room_id number(11) not null
|
197
|
+
);
|
198
|
+
|
199
|
+
create table seats (
|
200
|
+
flight_number int not null,
|
201
|
+
seat int not null,
|
202
|
+
customer int,
|
203
|
+
primary key (flight_number, seat)
|
204
|
+
);
|
205
|
+
|
206
|
+
create table capitols (
|
207
|
+
country varchar2(2000) not null,
|
208
|
+
city varchar2(2000) not null,
|
209
|
+
primary key (country, city)
|
210
|
+
);
|
211
|
+
|
212
|
+
create table products_restaurants (
|
213
|
+
product_id number(11) not null,
|
214
|
+
franchise_id number(11) not null,
|
215
|
+
store_id number(11) not null
|
216
|
+
);
|
217
|
+
|
218
|
+
create table employees_groups (
|
219
|
+
employee_id int not null,
|
220
|
+
group_id int not null
|
221
|
+
);
|
222
|
+
|
@@ -1,210 +1,209 @@
|
|
1
|
-
create table topics (
|
2
|
-
id serial not null,
|
3
|
-
name varchar(50) default null,
|
4
|
-
feed_size int default null,
|
5
|
-
primary key (id)
|
6
|
-
);
|
7
|
-
|
8
|
-
create table topic_sources (
|
9
|
-
topic_id int not null,
|
10
|
-
platform varchar(50) not null,
|
11
|
-
keywords varchar(50) default null,
|
12
|
-
primary key (topic_id,platform)
|
13
|
-
);
|
14
|
-
|
15
|
-
create table reference_types (
|
16
|
-
reference_type_id serial not null,
|
17
|
-
type_label varchar(50) default null,
|
18
|
-
abbreviation varchar(50) default null,
|
19
|
-
description varchar(50) default null,
|
20
|
-
primary key (reference_type_id)
|
21
|
-
);
|
22
|
-
|
23
|
-
create table reference_codes (
|
24
|
-
reference_type_id int,
|
25
|
-
reference_code int not null,
|
26
|
-
code_label varchar(50) default null,
|
27
|
-
abbreviation varchar(50) default null,
|
28
|
-
description varchar(50) default null,
|
29
|
-
primary key (reference_type_id, reference_code)
|
30
|
-
);
|
31
|
-
|
32
|
-
create table products (
|
33
|
-
id serial not null,
|
34
|
-
name varchar(50) default null,
|
35
|
-
primary key (id),
|
36
|
-
created_at timestamp without time zone NOT NULL,
|
37
|
-
updated_at timestamp without time zone NOT NULL
|
38
|
-
);
|
39
|
-
|
40
|
-
create table tariffs (
|
41
|
-
tariff_id int not null,
|
42
|
-
start_date date not null,
|
43
|
-
amount int default null,
|
44
|
-
primary key (tariff_id, start_date),
|
45
|
-
created_at timestamp without time zone NOT NULL,
|
46
|
-
updated_at timestamp without time zone NOT NULL
|
47
|
-
);
|
48
|
-
|
49
|
-
create table product_tariffs (
|
50
|
-
product_id int not null,
|
51
|
-
tariff_id int not null,
|
52
|
-
tariff_start_date date not null,
|
53
|
-
primary key (product_id, tariff_id, tariff_start_date)
|
54
|
-
);
|
55
|
-
|
56
|
-
create table suburbs (
|
57
|
-
city_id int not null,
|
58
|
-
suburb_id int not null,
|
59
|
-
name varchar(50) not null,
|
60
|
-
primary key (city_id, suburb_id)
|
61
|
-
);
|
62
|
-
|
63
|
-
create table streets (
|
64
|
-
id serial not null,
|
65
|
-
city_id int not null,
|
66
|
-
suburb_id int not null,
|
67
|
-
name varchar(50) not null,
|
68
|
-
primary key (id)
|
69
|
-
);
|
70
|
-
|
71
|
-
create table users (
|
72
|
-
id serial not null,
|
73
|
-
name varchar(50) not null,
|
74
|
-
primary key (id)
|
75
|
-
);
|
76
|
-
|
77
|
-
create table articles (
|
78
|
-
id serial not null,
|
79
|
-
name varchar(50) not null,
|
80
|
-
primary key (id)
|
81
|
-
);
|
82
|
-
|
83
|
-
create table readings (
|
84
|
-
id serial not null,
|
85
|
-
user_id int not null,
|
86
|
-
article_id int not null,
|
87
|
-
rating int not null,
|
88
|
-
primary key (id)
|
89
|
-
);
|
90
|
-
|
91
|
-
create table groups (
|
92
|
-
id serial not null,
|
93
|
-
name varchar(50) not null,
|
94
|
-
primary key (id)
|
95
|
-
);
|
96
|
-
|
97
|
-
create table memberships (
|
98
|
-
user_id int not null,
|
99
|
-
group_id int not null,
|
100
|
-
primary key (user_id, group_id)
|
101
|
-
);
|
102
|
-
|
103
|
-
create table membership_statuses (
|
104
|
-
id serial not null,
|
105
|
-
user_id int not null,
|
106
|
-
group_id int not null,
|
107
|
-
status varchar(50) not null,
|
108
|
-
primary key (id)
|
109
|
-
);
|
110
|
-
|
111
|
-
create table departments (
|
112
|
-
department_id int not null,
|
113
|
-
location_id int not null,
|
114
|
-
primary key (department_id, location_id)
|
115
|
-
);
|
116
|
-
|
117
|
-
create table employees (
|
118
|
-
id serial not null,
|
119
|
-
department_id int default null,
|
120
|
-
location_id int default null,
|
121
|
-
primary key (id)
|
122
|
-
);
|
123
|
-
|
124
|
-
create table comments (
|
125
|
-
id serial not null,
|
126
|
-
person_id int default null,
|
127
|
-
shown int default null,
|
128
|
-
person_type varchar(100) default null,
|
129
|
-
hack_id int default null,
|
130
|
-
primary key (id)
|
131
|
-
);
|
132
|
-
|
133
|
-
create table hacks (
|
134
|
-
id serial not null,
|
135
|
-
name varchar(50) not null,
|
136
|
-
primary key (id)
|
137
|
-
);
|
138
|
-
|
139
|
-
create table restaurants (
|
140
|
-
franchise_id int not null,
|
141
|
-
store_id int not null,
|
142
|
-
name varchar(100),
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
);
|
1
|
+
create table topics (
|
2
|
+
id serial not null,
|
3
|
+
name varchar(50) default null,
|
4
|
+
feed_size int default null,
|
5
|
+
primary key (id)
|
6
|
+
);
|
7
|
+
|
8
|
+
create table topic_sources (
|
9
|
+
topic_id int not null,
|
10
|
+
platform varchar(50) not null,
|
11
|
+
keywords varchar(50) default null,
|
12
|
+
primary key (topic_id,platform)
|
13
|
+
);
|
14
|
+
|
15
|
+
create table reference_types (
|
16
|
+
reference_type_id serial not null,
|
17
|
+
type_label varchar(50) default null,
|
18
|
+
abbreviation varchar(50) default null,
|
19
|
+
description varchar(50) default null,
|
20
|
+
primary key (reference_type_id)
|
21
|
+
);
|
22
|
+
|
23
|
+
create table reference_codes (
|
24
|
+
reference_type_id int,
|
25
|
+
reference_code int not null,
|
26
|
+
code_label varchar(50) default null,
|
27
|
+
abbreviation varchar(50) default null,
|
28
|
+
description varchar(50) default null,
|
29
|
+
primary key (reference_type_id, reference_code)
|
30
|
+
);
|
31
|
+
|
32
|
+
create table products (
|
33
|
+
id serial not null,
|
34
|
+
name varchar(50) default null,
|
35
|
+
primary key (id),
|
36
|
+
created_at timestamp without time zone NOT NULL,
|
37
|
+
updated_at timestamp without time zone NOT NULL
|
38
|
+
);
|
39
|
+
|
40
|
+
create table tariffs (
|
41
|
+
tariff_id int not null,
|
42
|
+
start_date date not null,
|
43
|
+
amount int default null,
|
44
|
+
primary key (tariff_id, start_date),
|
45
|
+
created_at timestamp without time zone NOT NULL,
|
46
|
+
updated_at timestamp without time zone NOT NULL
|
47
|
+
);
|
48
|
+
|
49
|
+
create table product_tariffs (
|
50
|
+
product_id int not null,
|
51
|
+
tariff_id int not null,
|
52
|
+
tariff_start_date date not null,
|
53
|
+
primary key (product_id, tariff_id, tariff_start_date)
|
54
|
+
);
|
55
|
+
|
56
|
+
create table suburbs (
|
57
|
+
city_id int not null,
|
58
|
+
suburb_id int not null,
|
59
|
+
name varchar(50) not null,
|
60
|
+
primary key (city_id, suburb_id)
|
61
|
+
);
|
62
|
+
|
63
|
+
create table streets (
|
64
|
+
id serial not null,
|
65
|
+
city_id int not null,
|
66
|
+
suburb_id int not null,
|
67
|
+
name varchar(50) not null,
|
68
|
+
primary key (id)
|
69
|
+
);
|
70
|
+
|
71
|
+
create table users (
|
72
|
+
id serial not null,
|
73
|
+
name varchar(50) not null,
|
74
|
+
primary key (id)
|
75
|
+
);
|
76
|
+
|
77
|
+
create table articles (
|
78
|
+
id serial not null,
|
79
|
+
name varchar(50) not null,
|
80
|
+
primary key (id)
|
81
|
+
);
|
82
|
+
|
83
|
+
create table readings (
|
84
|
+
id serial not null,
|
85
|
+
user_id int not null,
|
86
|
+
article_id int not null,
|
87
|
+
rating int not null,
|
88
|
+
primary key (id)
|
89
|
+
);
|
90
|
+
|
91
|
+
create table groups (
|
92
|
+
id serial not null,
|
93
|
+
name varchar(50) not null,
|
94
|
+
primary key (id)
|
95
|
+
);
|
96
|
+
|
97
|
+
create table memberships (
|
98
|
+
user_id int not null,
|
99
|
+
group_id int not null,
|
100
|
+
primary key (user_id, group_id)
|
101
|
+
);
|
102
|
+
|
103
|
+
create table membership_statuses (
|
104
|
+
id serial not null,
|
105
|
+
user_id int not null,
|
106
|
+
group_id int not null,
|
107
|
+
status varchar(50) not null,
|
108
|
+
primary key (id)
|
109
|
+
);
|
110
|
+
|
111
|
+
create table departments (
|
112
|
+
department_id int not null,
|
113
|
+
location_id int not null,
|
114
|
+
primary key (department_id, location_id)
|
115
|
+
);
|
116
|
+
|
117
|
+
create table employees (
|
118
|
+
id serial not null,
|
119
|
+
department_id int default null,
|
120
|
+
location_id int default null,
|
121
|
+
primary key (id)
|
122
|
+
);
|
123
|
+
|
124
|
+
create table comments (
|
125
|
+
id serial not null,
|
126
|
+
person_id int default null,
|
127
|
+
shown int default null,
|
128
|
+
person_type varchar(100) default null,
|
129
|
+
hack_id int default null,
|
130
|
+
primary key (id)
|
131
|
+
);
|
132
|
+
|
133
|
+
create table hacks (
|
134
|
+
id serial not null,
|
135
|
+
name varchar(50) not null,
|
136
|
+
primary key (id)
|
137
|
+
);
|
138
|
+
|
139
|
+
create table restaurants (
|
140
|
+
franchise_id int not null,
|
141
|
+
store_id int not null,
|
142
|
+
name varchar(100),
|
143
|
+
primary key (franchise_id, store_id)
|
144
|
+
);
|
145
|
+
|
146
|
+
create table restaurants_suburbs (
|
147
|
+
franchise_id int not null,
|
148
|
+
store_id int not null,
|
149
|
+
city_id int not null,
|
150
|
+
suburb_id int not null
|
151
|
+
);
|
152
|
+
|
153
|
+
create table dorms (
|
154
|
+
id serial not null,
|
155
|
+
primary key (id)
|
156
|
+
);
|
157
|
+
|
158
|
+
create table rooms (
|
159
|
+
dorm_id int not null,
|
160
|
+
room_id int not null,
|
161
|
+
primary key (dorm_id, room_id)
|
162
|
+
);
|
163
|
+
|
164
|
+
create table room_attributes (
|
165
|
+
id serial not null,
|
166
|
+
name varchar(50),
|
167
|
+
primary key (id)
|
168
|
+
);
|
169
|
+
|
170
|
+
create table room_attribute_assignments (
|
171
|
+
dorm_id int not null,
|
172
|
+
room_id int not null,
|
173
|
+
room_attribute_id int not null
|
174
|
+
);
|
175
|
+
|
176
|
+
create table students (
|
177
|
+
id serial not null,
|
178
|
+
primary key (id)
|
179
|
+
);
|
180
|
+
|
181
|
+
create table room_assignments (
|
182
|
+
student_id int not null,
|
183
|
+
dorm_id int not null,
|
184
|
+
room_id int not null
|
185
|
+
);
|
186
|
+
|
187
|
+
create table seats (
|
188
|
+
flight_number int not null,
|
189
|
+
seat int not null,
|
190
|
+
customer int,
|
191
|
+
primary key (flight_number, seat)
|
192
|
+
);
|
193
|
+
|
194
|
+
create table capitols (
|
195
|
+
country text not null,
|
196
|
+
city text not null,
|
197
|
+
primary key (country, city)
|
198
|
+
);
|
199
|
+
|
200
|
+
create table products_restaurants (
|
201
|
+
product_id int not null,
|
202
|
+
franchise_id int not null,
|
203
|
+
store_id int not null
|
204
|
+
);
|
205
|
+
|
206
|
+
create table employees_groups (
|
207
|
+
employee_id int not null,
|
208
|
+
group_id int not null
|
209
|
+
);
|