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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +600 -623
  3. data/lib/composite_primary_keys.rb +113 -115
  4. data/lib/composite_primary_keys/associations/association.rb +23 -23
  5. data/lib/composite_primary_keys/associations/association_scope.rb +73 -77
  6. data/lib/composite_primary_keys/associations/collection_association.rb +15 -0
  7. data/lib/composite_primary_keys/associations/has_many_association.rb +69 -56
  8. data/lib/composite_primary_keys/associations/has_many_through_association.rb +30 -28
  9. data/lib/composite_primary_keys/associations/join_dependency.rb +87 -89
  10. data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
  11. data/lib/composite_primary_keys/associations/preloader/association.rb +90 -78
  12. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
  13. data/lib/composite_primary_keys/associations/singular_association.rb +15 -0
  14. data/lib/composite_primary_keys/attribute_methods.rb +9 -0
  15. data/lib/composite_primary_keys/attribute_methods/dirty.rb +29 -26
  16. data/lib/composite_primary_keys/attribute_methods/read.rb +19 -34
  17. data/lib/composite_primary_keys/attribute_methods/write.rb +30 -36
  18. data/lib/composite_primary_keys/attribute_set/builder.rb +20 -0
  19. data/lib/composite_primary_keys/base.rb +135 -129
  20. data/lib/composite_primary_keys/composite_arrays.rb +30 -30
  21. data/lib/composite_primary_keys/composite_predicates.rb +50 -50
  22. data/lib/composite_primary_keys/composite_relation.rb +48 -48
  23. data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +2 -4
  24. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +46 -60
  25. data/lib/composite_primary_keys/core.rb +69 -47
  26. data/lib/composite_primary_keys/fixtures.rb +22 -22
  27. data/lib/composite_primary_keys/persistence.rb +56 -60
  28. data/lib/composite_primary_keys/relation.rb +68 -56
  29. data/lib/composite_primary_keys/relation/calculations.rb +79 -75
  30. data/lib/composite_primary_keys/relation/finder_methods.rb +175 -196
  31. data/lib/composite_primary_keys/relation/query_methods.rb +40 -40
  32. data/lib/composite_primary_keys/sanitization.rb +52 -52
  33. data/lib/composite_primary_keys/validations/uniqueness.rb +36 -37
  34. data/lib/composite_primary_keys/version.rb +8 -8
  35. data/tasks/databases/oracle.rake +25 -25
  36. data/tasks/databases/sqlserver.rake +27 -40
  37. data/test/abstract_unit.rb +113 -113
  38. data/test/connections/databases.ci.yml +15 -15
  39. data/test/connections/databases.example.yml +18 -18
  40. data/test/connections/native_oracle/connection.rb +11 -11
  41. data/test/connections/native_oracle_enhanced/connection.rb +16 -16
  42. data/test/connections/native_sqlserver/connection.rb +11 -14
  43. data/test/fixtures/comment.rb +7 -7
  44. data/test/fixtures/db_definitions/db2-create-tables.sql +125 -126
  45. data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
  46. data/test/fixtures/db_definitions/mysql.sql +207 -208
  47. data/test/fixtures/db_definitions/oracle.drop.sql +45 -45
  48. data/test/fixtures/db_definitions/oracle.sql +222 -223
  49. data/test/fixtures/db_definitions/postgresql.sql +209 -210
  50. data/test/fixtures/db_definitions/sqlite.sql +196 -197
  51. data/test/fixtures/db_definitions/sqlserver.drop.sql +91 -94
  52. data/test/fixtures/db_definitions/sqlserver.sql +225 -232
  53. data/test/fixtures/dorm.rb +2 -2
  54. data/test/fixtures/employee.rb +5 -5
  55. data/test/fixtures/membership.rb +6 -6
  56. data/test/fixtures/membership_statuses.yml +16 -16
  57. data/test/fixtures/memberships.yml +10 -10
  58. data/test/fixtures/product_tariffs.yml +14 -14
  59. data/test/fixtures/reference_code.rb +7 -7
  60. data/test/fixtures/restaurants_suburb.rb +2 -2
  61. data/test/fixtures/suburb.rb +5 -5
  62. data/test/fixtures/topic.rb +5 -5
  63. data/test/fixtures/topic_source.rb +6 -6
  64. data/test/fixtures/topic_sources.yml +3 -3
  65. data/test/fixtures/topics.yml +8 -8
  66. data/test/fixtures/users.yml +10 -10
  67. data/test/test_associations.rb +295 -275
  68. data/test/test_attribute_methods.rb +63 -63
  69. data/test/test_attributes.rb +60 -60
  70. data/test/test_calculations.rb +37 -42
  71. data/test/test_callbacks.rb +99 -99
  72. data/test/test_create.rb +112 -112
  73. data/test/test_delete.rb +148 -152
  74. data/test/test_delete_all.rb +28 -26
  75. data/test/test_dumpable.rb +15 -15
  76. data/test/test_enum.rb +21 -20
  77. data/test/test_equal.rb +26 -26
  78. data/test/test_find.rb +118 -118
  79. data/test/test_habtm.rb +113 -113
  80. data/test/test_nested_attributes.rb +124 -124
  81. data/test/test_polymorphic.rb +26 -26
  82. data/test/test_predicates.rb +40 -40
  83. data/test/test_santiago.rb +23 -23
  84. data/test/test_suite.rb +33 -34
  85. data/test/test_touch.rb +23 -23
  86. data/test/test_tutorial_example.rb +21 -21
  87. data/test/test_update.rb +71 -71
  88. metadata +9 -13
  89. data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -20
  90. data/lib/composite_primary_keys/associations/has_and_belongs_to_many_association.rb +0 -59
  91. data/lib/composite_primary_keys/associations/join_dependency/join_part.rb +0 -39
  92. data/lib/composite_primary_keys/associations/preloader/has_and_belongs_to_many.rb +0 -46
  93. data/lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb +0 -17
  94. data/lib/composite_primary_keys/locking/optimistic.rb +0 -55
  95. 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
- lock_version number(11) default 0,
150
- constraint restaurants_pk primary key (franchise_id, store_id)
151
- );
152
-
153
- create table restaurants_suburbs (
154
- franchise_id number(11) not null,
155
- store_id number(11) not null,
156
- city_id number(11) not null,
157
- suburb_id number(11) not null
158
- );
159
-
160
- create sequence dorms_seq start with 1000;
161
-
162
- create table dorms (
163
- id number(11) not null,
164
- constraint dorms_pk primary key (id)
165
- );
166
-
167
- create table rooms (
168
- dorm_id number(11) not null,
169
- room_id number(11) not null,
170
- constraint rooms_pk primary key (dorm_id, room_id)
171
- );
172
-
173
- create sequence room_attributes_seq start with 1000;
174
-
175
- create table room_attributes (
176
- id number(11) not null,
177
- name varchar(50),
178
- constraint room_attributes_pk primary key (id)
179
- );
180
-
181
- create table room_attribute_assignments (
182
- dorm_id number(11) not null,
183
- room_id number(11) not null,
184
- room_attribute_id number(11) not null
185
- );
186
-
187
- create sequence students_seq start with 1000;
188
-
189
- create table students (
190
- id number(11) not null,
191
- constraint students_pk primary key (id)
192
- );
193
-
194
- create table room_assignments (
195
- student_id number(11) not null,
196
- dorm_id number(11) not null,
197
- room_id number(11) not null
198
- );
199
-
200
- create table seats (
201
- flight_number int not null,
202
- seat int not null,
203
- customer int,
204
- primary key (flight_number, seat)
205
- );
206
-
207
- create table capitols (
208
- country varchar2(2000) not null,
209
- city varchar2(2000) not null,
210
- primary key (country, city)
211
- );
212
-
213
- create table products_restaurants (
214
- product_id number(11) not null,
215
- franchise_id number(11) not null,
216
- store_id number(11) not null
217
- );
218
-
219
- create table employees_groups (
220
- employee_id int not null,
221
- group_id int not null
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
- lock_version int default 0,
144
- primary key (franchise_id, store_id)
145
- );
146
-
147
- create table restaurants_suburbs (
148
- franchise_id int not null,
149
- store_id int not null,
150
- city_id int not null,
151
- suburb_id int not null
152
- );
153
-
154
- create table dorms (
155
- id serial not null,
156
- primary key (id)
157
- );
158
-
159
- create table rooms (
160
- dorm_id int not null,
161
- room_id int not null,
162
- primary key (dorm_id, room_id)
163
- );
164
-
165
- create table room_attributes (
166
- id serial not null,
167
- name varchar(50),
168
- primary key (id)
169
- );
170
-
171
- create table room_attribute_assignments (
172
- dorm_id int not null,
173
- room_id int not null,
174
- room_attribute_id int not null
175
- );
176
-
177
- create table students (
178
- id serial not null,
179
- primary key (id)
180
- );
181
-
182
- create table room_assignments (
183
- student_id int not null,
184
- dorm_id int not null,
185
- room_id int not null
186
- );
187
-
188
- create table seats (
189
- flight_number int not null,
190
- seat int not null,
191
- customer int,
192
- primary key (flight_number, seat)
193
- );
194
-
195
- create table capitols (
196
- country text not null,
197
- city text not null,
198
- primary key (country, city)
199
- );
200
-
201
- create table products_restaurants (
202
- product_id int not null,
203
- franchise_id int not null,
204
- store_id int not null
205
- );
206
-
207
- create table employees_groups (
208
- employee_id int not null,
209
- group_id int not null
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
+ );