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,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
- lock_version int default 0,
142
- primary key (franchise_id, store_id)
143
- );
144
-
145
- create table restaurants_suburbs (
146
- franchise_id int not null,
147
- store_id int not null,
148
- city_id int not null,
149
- suburb_id int not null
150
- );
151
-
152
- create table dorms (
153
- id int not null auto_increment,
154
- primary key(id)
155
- );
156
-
157
- create table rooms (
158
- dorm_id int not null,
159
- room_id int not null,
160
- primary key (dorm_id, room_id)
161
- );
162
-
163
- create table room_attributes (
164
- id int not null auto_increment,
165
- name varchar(50),
166
- primary key(id)
167
- );
168
-
169
- create table room_attribute_assignments (
170
- dorm_id int not null,
171
- room_id int not null,
172
- room_attribute_id int not null
173
- );
174
-
175
- create table students (
176
- id int not null auto_increment,
177
- primary key(id)
178
- );
179
-
180
- create table room_assignments (
181
- student_id int not null,
182
- dorm_id int not null,
183
- room_id int not null
184
- );
185
-
186
- create table seats (
187
- flight_number int not null,
188
- seat int not null,
189
- customer int,
190
- primary key (flight_number, seat)
191
- );
192
-
193
- create table capitols (
194
- country varchar(100) default null,
195
- city varchar(100) default null,
196
- primary key (country, city)
197
- );
198
-
199
- create table products_restaurants (
200
- product_id int not null,
201
- franchise_id int not null,
202
- store_id int not null
203
- );
204
-
205
- create table employees_groups (
206
- employee_id int not null,
207
- group_id int not null
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;