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,208 +1,207 @@
|
|
1
|
-
create table topics (
|
2
|
-
id int not null auto_increment,
|
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 int not null auto_increment,
|
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 not null,
|
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 int not null auto_increment,
|
34
|
-
name varchar(50) default null,
|
35
|
-
primary key (id)
|
36
|
-
);
|
37
|
-
|
38
|
-
create table tariffs (
|
39
|
-
tariff_id int not null,
|
40
|
-
start_date date not null,
|
41
|
-
amount integer(11) default null,
|
42
|
-
created_at timestamp,
|
43
|
-
updated_at timestamp,
|
44
|
-
primary key (tariff_id, start_date)
|
45
|
-
);
|
46
|
-
|
47
|
-
create table product_tariffs (
|
48
|
-
product_id int not null,
|
49
|
-
tariff_id int not null,
|
50
|
-
tariff_start_date date not null,
|
51
|
-
primary key (product_id, tariff_id, tariff_start_date)
|
52
|
-
);
|
53
|
-
|
54
|
-
create table suburbs (
|
55
|
-
city_id int not null,
|
56
|
-
suburb_id int not null,
|
57
|
-
name varchar(50) not null,
|
58
|
-
primary key (city_id, suburb_id)
|
59
|
-
);
|
60
|
-
|
61
|
-
create table streets (
|
62
|
-
id int not null auto_increment,
|
63
|
-
city_id int not null,
|
64
|
-
suburb_id int not null,
|
65
|
-
name varchar(50) not null,
|
66
|
-
primary key (id)
|
67
|
-
);
|
68
|
-
|
69
|
-
create table users (
|
70
|
-
id int not null auto_increment,
|
71
|
-
name varchar(50) not null,
|
72
|
-
primary key (id)
|
73
|
-
);
|
74
|
-
|
75
|
-
create table articles (
|
76
|
-
id int not null auto_increment,
|
77
|
-
name varchar(50) not null,
|
78
|
-
primary key (id)
|
79
|
-
);
|
80
|
-
|
81
|
-
create table readings (
|
82
|
-
id int not null auto_increment,
|
83
|
-
user_id int not null,
|
84
|
-
article_id int not null,
|
85
|
-
rating int not null,
|
86
|
-
primary key (id)
|
87
|
-
);
|
88
|
-
|
89
|
-
create table groups (
|
90
|
-
id int not null auto_increment,
|
91
|
-
name varchar(50) not null,
|
92
|
-
primary key (id)
|
93
|
-
);
|
94
|
-
|
95
|
-
create table memberships (
|
96
|
-
user_id int not null,
|
97
|
-
group_id int not null,
|
98
|
-
primary key (user_id,group_id)
|
99
|
-
);
|
100
|
-
|
101
|
-
create table membership_statuses (
|
102
|
-
id int not null auto_increment,
|
103
|
-
user_id int not null,
|
104
|
-
group_id int not null,
|
105
|
-
status varchar(50) not null,
|
106
|
-
primary key (id)
|
107
|
-
);
|
108
|
-
|
109
|
-
create table departments (
|
110
|
-
department_id int not null,
|
111
|
-
location_id int not null,
|
112
|
-
primary key (department_id, location_id)
|
113
|
-
);
|
114
|
-
|
115
|
-
create table employees (
|
116
|
-
id int not null auto_increment,
|
117
|
-
department_id int default null,
|
118
|
-
location_id int default null,
|
119
|
-
primary key (id)
|
120
|
-
);
|
121
|
-
|
122
|
-
create table comments (
|
123
|
-
id int not null auto_increment,
|
124
|
-
person_id int default null,
|
125
|
-
shown int default null,
|
126
|
-
person_type varchar(100) default null,
|
127
|
-
hack_id int default null,
|
128
|
-
primary key (id)
|
129
|
-
);
|
130
|
-
|
131
|
-
create table hacks (
|
132
|
-
id int not null auto_increment,
|
133
|
-
name varchar(50) not null,
|
134
|
-
primary key (id)
|
135
|
-
);
|
136
|
-
|
137
|
-
create table restaurants (
|
138
|
-
franchise_id int not null,
|
139
|
-
store_id int not null,
|
140
|
-
name varchar(100),
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
id
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
id
|
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
|
-
);
|
1
|
+
create table topics (
|
2
|
+
id int not null auto_increment,
|
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 int not null auto_increment,
|
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 not null,
|
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 int not null auto_increment,
|
34
|
+
name varchar(50) default null,
|
35
|
+
primary key (id)
|
36
|
+
);
|
37
|
+
|
38
|
+
create table tariffs (
|
39
|
+
tariff_id int not null,
|
40
|
+
start_date date not null,
|
41
|
+
amount integer(11) default null,
|
42
|
+
created_at timestamp,
|
43
|
+
updated_at timestamp,
|
44
|
+
primary key (tariff_id, start_date)
|
45
|
+
);
|
46
|
+
|
47
|
+
create table product_tariffs (
|
48
|
+
product_id int not null,
|
49
|
+
tariff_id int not null,
|
50
|
+
tariff_start_date date not null,
|
51
|
+
primary key (product_id, tariff_id, tariff_start_date)
|
52
|
+
);
|
53
|
+
|
54
|
+
create table suburbs (
|
55
|
+
city_id int not null,
|
56
|
+
suburb_id int not null,
|
57
|
+
name varchar(50) not null,
|
58
|
+
primary key (city_id, suburb_id)
|
59
|
+
);
|
60
|
+
|
61
|
+
create table streets (
|
62
|
+
id int not null auto_increment,
|
63
|
+
city_id int not null,
|
64
|
+
suburb_id int not null,
|
65
|
+
name varchar(50) not null,
|
66
|
+
primary key (id)
|
67
|
+
);
|
68
|
+
|
69
|
+
create table users (
|
70
|
+
id int not null auto_increment,
|
71
|
+
name varchar(50) not null,
|
72
|
+
primary key (id)
|
73
|
+
);
|
74
|
+
|
75
|
+
create table articles (
|
76
|
+
id int not null auto_increment,
|
77
|
+
name varchar(50) not null,
|
78
|
+
primary key (id)
|
79
|
+
);
|
80
|
+
|
81
|
+
create table readings (
|
82
|
+
id int not null auto_increment,
|
83
|
+
user_id int not null,
|
84
|
+
article_id int not null,
|
85
|
+
rating int not null,
|
86
|
+
primary key (id)
|
87
|
+
);
|
88
|
+
|
89
|
+
create table groups (
|
90
|
+
id int not null auto_increment,
|
91
|
+
name varchar(50) not null,
|
92
|
+
primary key (id)
|
93
|
+
);
|
94
|
+
|
95
|
+
create table memberships (
|
96
|
+
user_id int not null,
|
97
|
+
group_id int not null,
|
98
|
+
primary key (user_id,group_id)
|
99
|
+
);
|
100
|
+
|
101
|
+
create table membership_statuses (
|
102
|
+
id int not null auto_increment,
|
103
|
+
user_id int not null,
|
104
|
+
group_id int not null,
|
105
|
+
status varchar(50) not null,
|
106
|
+
primary key (id)
|
107
|
+
);
|
108
|
+
|
109
|
+
create table departments (
|
110
|
+
department_id int not null,
|
111
|
+
location_id int not null,
|
112
|
+
primary key (department_id, location_id)
|
113
|
+
);
|
114
|
+
|
115
|
+
create table employees (
|
116
|
+
id int not null auto_increment,
|
117
|
+
department_id int default null,
|
118
|
+
location_id int default null,
|
119
|
+
primary key (id)
|
120
|
+
);
|
121
|
+
|
122
|
+
create table comments (
|
123
|
+
id int not null auto_increment,
|
124
|
+
person_id int default null,
|
125
|
+
shown int default null,
|
126
|
+
person_type varchar(100) default null,
|
127
|
+
hack_id int default null,
|
128
|
+
primary key (id)
|
129
|
+
);
|
130
|
+
|
131
|
+
create table hacks (
|
132
|
+
id int not null auto_increment,
|
133
|
+
name varchar(50) not null,
|
134
|
+
primary key (id)
|
135
|
+
);
|
136
|
+
|
137
|
+
create table restaurants (
|
138
|
+
franchise_id int not null,
|
139
|
+
store_id int not null,
|
140
|
+
name varchar(100),
|
141
|
+
primary key (franchise_id, store_id)
|
142
|
+
);
|
143
|
+
|
144
|
+
create table restaurants_suburbs (
|
145
|
+
franchise_id int not null,
|
146
|
+
store_id int not null,
|
147
|
+
city_id int not null,
|
148
|
+
suburb_id int not null
|
149
|
+
);
|
150
|
+
|
151
|
+
create table dorms (
|
152
|
+
id int not null auto_increment,
|
153
|
+
primary key(id)
|
154
|
+
);
|
155
|
+
|
156
|
+
create table rooms (
|
157
|
+
dorm_id int not null,
|
158
|
+
room_id int not null,
|
159
|
+
primary key (dorm_id, room_id)
|
160
|
+
);
|
161
|
+
|
162
|
+
create table room_attributes (
|
163
|
+
id int not null auto_increment,
|
164
|
+
name varchar(50),
|
165
|
+
primary key(id)
|
166
|
+
);
|
167
|
+
|
168
|
+
create table room_attribute_assignments (
|
169
|
+
dorm_id int not null,
|
170
|
+
room_id int not null,
|
171
|
+
room_attribute_id int not null
|
172
|
+
);
|
173
|
+
|
174
|
+
create table students (
|
175
|
+
id int not null auto_increment,
|
176
|
+
primary key(id)
|
177
|
+
);
|
178
|
+
|
179
|
+
create table room_assignments (
|
180
|
+
student_id int not null,
|
181
|
+
dorm_id int not null,
|
182
|
+
room_id int not null
|
183
|
+
);
|
184
|
+
|
185
|
+
create table seats (
|
186
|
+
flight_number int not null,
|
187
|
+
seat int not null,
|
188
|
+
customer int,
|
189
|
+
primary key (flight_number, seat)
|
190
|
+
);
|
191
|
+
|
192
|
+
create table capitols (
|
193
|
+
country varchar(100) default null,
|
194
|
+
city varchar(100) default null,
|
195
|
+
primary key (country, city)
|
196
|
+
);
|
197
|
+
|
198
|
+
create table products_restaurants (
|
199
|
+
product_id int not null,
|
200
|
+
franchise_id int not null,
|
201
|
+
store_id int not null
|
202
|
+
);
|
203
|
+
|
204
|
+
create table employees_groups (
|
205
|
+
employee_id int not null,
|
206
|
+
group_id int not null
|
207
|
+
);
|
@@ -1,45 +1,45 @@
|
|
1
|
-
drop table topics;
|
2
|
-
drop sequence topics_seq;
|
3
|
-
drop table topic_sources;
|
4
|
-
drop table reference_types;
|
5
|
-
drop sequence reference_types_seq;
|
6
|
-
drop table reference_codes;
|
7
|
-
drop table products;
|
8
|
-
drop sequence products_seq;
|
9
|
-
drop table tariffs;
|
10
|
-
drop table product_tariffs;
|
11
|
-
drop table suburbs;
|
12
|
-
drop table streets;
|
13
|
-
drop sequence streets_seq;
|
14
|
-
drop table users;
|
15
|
-
drop sequence users_seq;
|
16
|
-
drop table articles;
|
17
|
-
drop sequence articles_seq;
|
18
|
-
drop table readings;
|
19
|
-
drop sequence readings_seq;
|
20
|
-
drop table groups;
|
21
|
-
drop sequence groups_seq;
|
22
|
-
drop table memberships;
|
23
|
-
drop table membership_statuses;
|
24
|
-
drop sequence membership_statuses_seq;
|
25
|
-
drop table departments;
|
26
|
-
drop table employees;
|
27
|
-
drop sequence employees_seq;
|
28
|
-
drop table comments;
|
29
|
-
drop sequence comments_seq;
|
30
|
-
drop table hacks;
|
31
|
-
drop sequence hacks_seq;
|
32
|
-
drop table restaurants;
|
33
|
-
drop table restaurants_suburbs;
|
34
|
-
drop table dorms;
|
35
|
-
drop sequence dorms_seq;
|
36
|
-
drop table rooms;
|
37
|
-
drop table room_attributes;
|
38
|
-
drop sequence room_attributes_seq;
|
39
|
-
drop table room_attribute_assignments;
|
40
|
-
drop table room_assignments;
|
41
|
-
drop table students;
|
42
|
-
drop sequence students_seq;
|
43
|
-
drop table seats;
|
44
|
-
drop table capitols;
|
45
|
-
drop table products_restaurants;
|
1
|
+
drop table topics;
|
2
|
+
drop sequence topics_seq;
|
3
|
+
drop table topic_sources;
|
4
|
+
drop table reference_types;
|
5
|
+
drop sequence reference_types_seq;
|
6
|
+
drop table reference_codes;
|
7
|
+
drop table products;
|
8
|
+
drop sequence products_seq;
|
9
|
+
drop table tariffs;
|
10
|
+
drop table product_tariffs;
|
11
|
+
drop table suburbs;
|
12
|
+
drop table streets;
|
13
|
+
drop sequence streets_seq;
|
14
|
+
drop table users;
|
15
|
+
drop sequence users_seq;
|
16
|
+
drop table articles;
|
17
|
+
drop sequence articles_seq;
|
18
|
+
drop table readings;
|
19
|
+
drop sequence readings_seq;
|
20
|
+
drop table groups;
|
21
|
+
drop sequence groups_seq;
|
22
|
+
drop table memberships;
|
23
|
+
drop table membership_statuses;
|
24
|
+
drop sequence membership_statuses_seq;
|
25
|
+
drop table departments;
|
26
|
+
drop table employees;
|
27
|
+
drop sequence employees_seq;
|
28
|
+
drop table comments;
|
29
|
+
drop sequence comments_seq;
|
30
|
+
drop table hacks;
|
31
|
+
drop sequence hacks_seq;
|
32
|
+
drop table restaurants;
|
33
|
+
drop table restaurants_suburbs;
|
34
|
+
drop table dorms;
|
35
|
+
drop sequence dorms_seq;
|
36
|
+
drop table rooms;
|
37
|
+
drop table room_attributes;
|
38
|
+
drop sequence room_attributes_seq;
|
39
|
+
drop table room_attribute_assignments;
|
40
|
+
drop table room_assignments;
|
41
|
+
drop table students;
|
42
|
+
drop sequence students_seq;
|
43
|
+
drop table seats;
|
44
|
+
drop table capitols;
|
45
|
+
drop table products_restaurants;
|