composite_primary_keys 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +10 -0
- data/lib/composite_primary_keys/association_preload.rb +67 -61
- data/lib/composite_primary_keys/associations.rb +428 -409
- data/lib/composite_primary_keys/attribute_methods.rb +3 -3
- data/lib/composite_primary_keys/base.rb +128 -110
- data/lib/composite_primary_keys/calculations.rb +8 -8
- data/lib/composite_primary_keys/composite_arrays.rb +6 -5
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +44 -2
- data/lib/composite_primary_keys/fixtures.rb +2 -3
- data/lib/composite_primary_keys/version.rb +1 -1
- data/scripts/console.rb +34 -11
- data/test/fixtures/db_definitions/db2-create-tables.sql +2 -2
- data/test/fixtures/db_definitions/mysql.sql +156 -155
- data/test/fixtures/db_definitions/oracle.drop.sql +4 -1
- data/test/fixtures/db_definitions/oracle.sql +117 -119
- data/test/fixtures/db_definitions/postgresql.sql +164 -98
- data/test/fixtures/db_definitions/sqlite.sql +74 -73
- data/test/fixtures/street.rb +2 -2
- data/test/fixtures/streets.yml +14 -14
- data/test/test_associations.rb +0 -5
- data/test/test_attribute_methods.rb +2 -2
- data/test/test_create.rb +68 -68
- data/test/test_delete.rb +19 -10
- data/test/test_ids.rb +7 -0
- data/tmp/test.db +0 -0
- data/website/template.js +3 -3
- metadata +2 -2
@@ -33,4 +33,7 @@ drop sequence dorms_seq;
|
|
33
33
|
drop table rooms;
|
34
34
|
drop table room_attributes;
|
35
35
|
drop sequence room_attributes_seq;
|
36
|
-
drop table room_attribute_assignments;
|
36
|
+
drop table room_attribute_assignments;
|
37
|
+
drop table room_assignments;
|
38
|
+
drop table students;
|
39
|
+
drop sequence students_seq;
|
@@ -1,190 +1,188 @@
|
|
1
|
+
create sequence reference_types_seq start with 1000;
|
2
|
+
|
1
3
|
create table reference_types (
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
reference_type_id number(11) primary key,
|
5
|
+
type_label varchar2(50) default null,
|
6
|
+
abbreviation varchar2(50) default null,
|
7
|
+
description varchar2(50) default null
|
6
8
|
);
|
7
9
|
|
8
|
-
create sequence reference_types_seq
|
9
|
-
start with 1000;
|
10
|
-
|
11
10
|
create table reference_codes (
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
constraint reference_codes_pk primary key(reference_type_id, reference_code)
|
11
|
+
reference_type_id number(11),
|
12
|
+
reference_code number(11),
|
13
|
+
code_label varchar2(50) default null,
|
14
|
+
abbreviation varchar2(50) default null,
|
15
|
+
description varchar2(50) default null
|
18
16
|
);
|
19
17
|
|
18
|
+
create sequence products_seq start with 1000;
|
19
|
+
|
20
20
|
create table products (
|
21
|
-
|
22
|
-
|
21
|
+
id number(11) primary key,
|
22
|
+
name varchar2(50) default null
|
23
23
|
);
|
24
24
|
|
25
|
-
create sequence products_seq
|
26
|
-
start with 1000;
|
27
|
-
|
28
25
|
create table tariffs (
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
tariff_id number(11),
|
27
|
+
start_date date,
|
28
|
+
amount number(11) default null,
|
29
|
+
constraint tariffs_pk primary key (tariff_id, start_date)
|
33
30
|
);
|
34
31
|
|
35
32
|
create table product_tariffs (
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
product_id number(11),
|
34
|
+
tariff_id number(11),
|
35
|
+
tariff_start_date date,
|
36
|
+
constraint product_tariffs_pk primary key (product_id, tariff_id, tariff_start_date)
|
40
37
|
);
|
41
38
|
|
42
39
|
create table suburbs (
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
city_id number(11),
|
41
|
+
suburb_id number(11),
|
42
|
+
name varchar2(50) not null,
|
43
|
+
constraint suburbs_pk primary key (city_id, suburb_id)
|
47
44
|
);
|
48
45
|
|
46
|
+
create sequence streets_seq start with 1000;
|
47
|
+
|
49
48
|
create table streets (
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
id number(11) primary key,
|
50
|
+
city_id number(11) not null,
|
51
|
+
suburb_id number(11) not null,
|
52
|
+
name varchar2(50) not null
|
54
53
|
);
|
55
54
|
|
56
|
-
create sequence
|
57
|
-
start with 1000;
|
55
|
+
create sequence users_seq start with 1000;
|
58
56
|
|
59
57
|
create table users (
|
60
|
-
|
61
|
-
|
58
|
+
id number(11) primary key,
|
59
|
+
name varchar2(50) not null
|
62
60
|
);
|
63
61
|
|
64
|
-
create sequence
|
65
|
-
start with 1000;
|
62
|
+
create sequence articles_seq start with 1000;
|
66
63
|
|
67
64
|
create table articles (
|
68
|
-
|
69
|
-
|
65
|
+
id number(11) primary key,
|
66
|
+
name varchar2(50) not null
|
70
67
|
);
|
71
68
|
|
72
|
-
create sequence
|
73
|
-
start with 1000;
|
74
|
-
|
69
|
+
create sequence readings_seq start with 1000;
|
75
70
|
|
76
71
|
create table readings (
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
id number(11) primary key,
|
73
|
+
user_id number(11) not null,
|
74
|
+
article_id number(11) not null,
|
75
|
+
rating number(11) not null
|
81
76
|
);
|
82
77
|
|
83
|
-
create sequence
|
84
|
-
start with 1000;
|
85
|
-
|
78
|
+
create sequence groups_seq start with 1000;
|
86
79
|
|
87
80
|
create table groups (
|
88
|
-
|
89
|
-
|
81
|
+
id number(11) primary key,
|
82
|
+
name varchar2(50) not null
|
90
83
|
);
|
91
84
|
|
92
|
-
create sequence groups_seq
|
93
|
-
start with 1000;
|
94
|
-
|
95
|
-
|
96
85
|
create table memberships (
|
97
|
-
|
98
|
-
|
99
|
-
|
86
|
+
user_id number(11) not null,
|
87
|
+
group_id number(11) not null,
|
88
|
+
constraint memberships_pk primary key (user_id, group_id)
|
100
89
|
);
|
101
90
|
|
91
|
+
create sequence membership_statuses_seq start with 1000;
|
92
|
+
|
102
93
|
create table membership_statuses (
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
94
|
+
id number(11) primary key,
|
95
|
+
user_id number(11) not null,
|
96
|
+
group_id number(11) not null,
|
97
|
+
status varchar2(50) not null
|
107
98
|
);
|
108
99
|
|
109
|
-
create
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
department_id number(11) NOT NULL,
|
114
|
-
location_id number(11) NOT NULL,
|
115
|
-
constraint departments_pk primary key(department_id, location_id)
|
100
|
+
create table departments (
|
101
|
+
department_id number(11) not null,
|
102
|
+
location_id number(11) not null,
|
103
|
+
constraint departments_pk primary key (department_id, location_id)
|
116
104
|
);
|
117
105
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
106
|
+
create sequence employees_seq start with 1000;
|
107
|
+
|
108
|
+
create table employees (
|
109
|
+
id number(11) not null primary key,
|
110
|
+
department_id number(11) default null,
|
111
|
+
location_id number(11) default null
|
122
112
|
);
|
123
113
|
|
124
|
-
create sequence
|
125
|
-
start with 1000;
|
114
|
+
create sequence comments_seq start with 1000;
|
126
115
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
116
|
+
create table comments (
|
117
|
+
id number(11) not null primary key,
|
118
|
+
person_id varchar(100) default null,
|
119
|
+
person_type varchar(100) default null,
|
120
|
+
hack_id varchar(100) default null
|
132
121
|
);
|
133
122
|
|
134
|
-
create
|
135
|
-
|
136
|
-
|
137
|
-
CREATE TABLE hacks (
|
138
|
-
name varchar(50) NOT NULL PRIMARY KEY
|
123
|
+
create table hacks (
|
124
|
+
name varchar(50) not null primary key
|
139
125
|
);
|
140
126
|
|
141
127
|
create table kitchen_sinks (
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
128
|
+
id_1 number(11) not null,
|
129
|
+
id_2 number(11) not null,
|
130
|
+
a_date date,
|
131
|
+
a_string varchar(100),
|
132
|
+
constraint kitchen_sinks_pk primary key (id_1, id_2)
|
147
133
|
);
|
148
134
|
|
149
135
|
create table restaurants (
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
136
|
+
franchise_id number(11) not null,
|
137
|
+
store_id number(11) not null,
|
138
|
+
name varchar(100),
|
139
|
+
constraint restaurants_pk primary key (franchise_id, store_id)
|
154
140
|
);
|
155
141
|
|
156
142
|
create table restaurants_suburbs (
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
143
|
+
franchise_id number(11) not null,
|
144
|
+
store_id number(11) not null,
|
145
|
+
city_id number(11) not null,
|
146
|
+
suburb_id number(11) not null
|
161
147
|
);
|
162
148
|
|
149
|
+
create sequence dorms_seq start with 1000;
|
150
|
+
|
163
151
|
create table dorms (
|
164
|
-
|
165
|
-
|
152
|
+
id number(11) not null,
|
153
|
+
constraint dorms_pk primary key (id)
|
166
154
|
);
|
167
155
|
|
168
|
-
create sequence dorms_seq
|
169
|
-
start with 1000;
|
170
|
-
|
171
156
|
create table rooms (
|
172
|
-
|
173
|
-
|
174
|
-
|
157
|
+
dorm_id number(11) not null,
|
158
|
+
room_id number(11) not null,
|
159
|
+
constraint rooms_pk primary key (dorm_id, room_id)
|
175
160
|
);
|
176
161
|
|
162
|
+
create sequence room_attributes_seq start with 1000;
|
163
|
+
|
177
164
|
create table room_attributes (
|
178
|
-
|
179
|
-
|
180
|
-
|
165
|
+
id number(11) not null,
|
166
|
+
name varchar(50),
|
167
|
+
constraint room_attributes_pk primary key (id)
|
181
168
|
);
|
182
169
|
|
183
|
-
create sequence room_attributes_seq
|
184
|
-
start with 1000;
|
185
|
-
|
186
170
|
create table room_attribute_assignments (
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
);
|
171
|
+
dorm_id number(11) not null,
|
172
|
+
room_id number(11) not null,
|
173
|
+
room_attribute_id number(11) not null
|
174
|
+
);
|
175
|
+
|
176
|
+
create sequence students_seq start with 1000;
|
177
|
+
|
178
|
+
create table students (
|
179
|
+
id number(11) not null,
|
180
|
+
constraint students_pk primary key (id)
|
181
|
+
);
|
182
|
+
|
183
|
+
create table room_assignments (
|
184
|
+
student_id number(11) not null,
|
185
|
+
dorm_id number(11) not null,
|
186
|
+
room_id number(11) not null
|
187
|
+
);
|
188
|
+
|
@@ -1,133 +1,199 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
create sequence public.reference_types_seq start 1000;
|
2
|
+
|
3
|
+
create table reference_types (
|
4
|
+
reference_type_id int default nextval('public.reference_types_seq'),
|
5
|
+
type_label varchar(50) default null,
|
6
|
+
abbreviation varchar(50) default null,
|
7
|
+
description varchar(50) default null,
|
8
|
+
primary key (reference_type_id)
|
8
9
|
);
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
PRIMARY KEY (reference_type_id,reference_code)
|
11
|
+
create table reference_codes (
|
12
|
+
reference_type_id int,
|
13
|
+
reference_code int not null,
|
14
|
+
code_label varchar(50) default null,
|
15
|
+
abbreviation varchar(50) default null,
|
16
|
+
description varchar(50) default null
|
17
17
|
);
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
create sequence public.products_seq start 1000;
|
20
|
+
|
21
|
+
create table products (
|
22
|
+
id int not null default nextval('public.products_seq'),
|
23
|
+
name varchar(50) default null,
|
24
|
+
primary key (id)
|
24
25
|
);
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
create table tariffs (
|
28
|
+
tariff_id int not null,
|
29
|
+
start_date date not null,
|
30
|
+
amount int default null,
|
31
|
+
primary key (tariff_id, start_date)
|
31
32
|
);
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
create table product_tariffs (
|
35
|
+
product_id int not null,
|
36
|
+
tariff_id int not null,
|
37
|
+
tariff_start_date date not null,
|
38
|
+
primary key (product_id, tariff_id, tariff_start_date)
|
38
39
|
);
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
create table suburbs (
|
42
|
+
city_id int not null,
|
43
|
+
suburb_id int not null,
|
44
|
+
name varchar(50) not null,
|
45
|
+
primary key (city_id, suburb_id)
|
45
46
|
);
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
create sequence public.streets_seq start 1000;
|
49
|
+
|
50
|
+
create table streets (
|
51
|
+
id int not null default nextval('public.streets_seq'),
|
52
|
+
city_id int not null,
|
53
|
+
suburb_id int not null,
|
54
|
+
name varchar(50) not null,
|
55
|
+
primary key (id)
|
54
56
|
);
|
55
57
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
create sequence public.users_seq start 1000;
|
59
|
+
|
60
|
+
create table users (
|
61
|
+
id int not null default nextval('public.users_seq'),
|
62
|
+
name varchar(50) not null,
|
63
|
+
primary key (id)
|
61
64
|
);
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
create sequence public.articles_seq start 1000;
|
67
|
+
|
68
|
+
create table articles (
|
69
|
+
id int not null default nextval('public.articles_seq'),
|
70
|
+
name varchar(50) not null,
|
71
|
+
primary key (id)
|
68
72
|
);
|
69
73
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
create sequence public.readings_seq start 1000;
|
75
|
+
|
76
|
+
create table readings (
|
77
|
+
id int not null default nextval('public.readings_seq'),
|
78
|
+
user_id int not null,
|
79
|
+
article_id int not null,
|
80
|
+
rating int not null,
|
81
|
+
primary key (id)
|
77
82
|
);
|
78
83
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
+
create sequence public.groups_seq start 1000;
|
85
|
+
|
86
|
+
create table groups (
|
87
|
+
id int not null default nextval('public.groups_seq'),
|
88
|
+
name varchar(50) not null,
|
89
|
+
primary key (id)
|
84
90
|
);
|
85
91
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
92
|
+
create table memberships (
|
93
|
+
user_id int not null,
|
94
|
+
group_id int not null,
|
95
|
+
primary key (user_id, group_id)
|
90
96
|
);
|
91
97
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
98
|
+
create sequence public.membership_statuses_seq start 1000;
|
99
|
+
|
100
|
+
create table membership_statuses (
|
101
|
+
id int not null default nextval('public.membership_statuses_seq'),
|
102
|
+
user_id int not null,
|
103
|
+
group_id int not null,
|
104
|
+
status varchar(50) not null,
|
105
|
+
primary key (id)
|
99
106
|
);
|
100
107
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
108
|
+
create table departments (
|
109
|
+
department_id int not null,
|
110
|
+
location_id int not null,
|
111
|
+
primary key (department_id, location_id)
|
105
112
|
);
|
106
113
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
114
|
+
create sequence public.employees_seq start 1000;
|
115
|
+
|
116
|
+
create table employees (
|
117
|
+
id int not null default nextval('public.employees_seq'),
|
118
|
+
department_id int default null,
|
119
|
+
location_id int default null,
|
120
|
+
primary key (id)
|
112
121
|
);
|
113
122
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
123
|
+
create sequence public.comments_seq start 1000;
|
124
|
+
|
125
|
+
create table comments (
|
126
|
+
id int not null default nextval('public.comments_seq'),
|
127
|
+
person_id varchar(100) default null,
|
128
|
+
person_type varchar(100) default null,
|
129
|
+
hack_id varchar(100) default null,
|
130
|
+
primary key (id)
|
120
131
|
);
|
121
132
|
|
122
|
-
|
123
|
-
|
124
|
-
|
133
|
+
create table hacks (
|
134
|
+
name varchar(50) not null,
|
135
|
+
primary key (name)
|
125
136
|
);
|
126
137
|
|
127
138
|
create table kitchen_sinks (
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
);
|
139
|
+
id_1 int not null,
|
140
|
+
id_2 int not null,
|
141
|
+
a_date date,
|
142
|
+
a_string varchar(100),
|
143
|
+
primary key (id_1, id_2)
|
144
|
+
);
|
145
|
+
|
146
|
+
create table restaurants (
|
147
|
+
franchise_id int not null,
|
148
|
+
store_id int not null,
|
149
|
+
name varchar(100),
|
150
|
+
primary key (franchise_id, store_id)
|
151
|
+
);
|
152
|
+
|
153
|
+
create table restaurants_suburbs (
|
154
|
+
franchise_id int not null,
|
155
|
+
store_id int not null,
|
156
|
+
city_id int not null,
|
157
|
+
suburb_id int not null
|
158
|
+
);
|
159
|
+
|
160
|
+
create sequence public.dorms_seq start 1000;
|
161
|
+
|
162
|
+
create table dorms (
|
163
|
+
id int not null default nextval('public.dorms_seq'),
|
164
|
+
primary key (id)
|
165
|
+
);
|
166
|
+
|
167
|
+
create table rooms (
|
168
|
+
dorm_id int not null,
|
169
|
+
room_id int not null,
|
170
|
+
primary key (dorm_id, room_id)
|
171
|
+
);
|
172
|
+
|
173
|
+
create sequence public.room_attributes_seq start 1000;
|
174
|
+
|
175
|
+
create table room_attributes (
|
176
|
+
id int not null default nextval('public.room_attributes_seq'),
|
177
|
+
name varchar(50),
|
178
|
+
primary key (id)
|
179
|
+
);
|
180
|
+
|
181
|
+
create table room_attribute_assignments (
|
182
|
+
dorm_id int not null,
|
183
|
+
room_id int not null,
|
184
|
+
room_attribute_id int not null
|
185
|
+
);
|
186
|
+
|
187
|
+
create sequence public.students_seq start 1000;
|
188
|
+
|
189
|
+
create table students (
|
190
|
+
id int not null default nextval('public.students_seq'),
|
191
|
+
primary key (id)
|
192
|
+
);
|
193
|
+
|
194
|
+
create table room_assignments (
|
195
|
+
student_id int not null,
|
196
|
+
dorm_id int not null,
|
197
|
+
room_id int not null
|
198
|
+
);
|
199
|
+
|