kovyrin-composite_primary_keys 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +164 -0
- data/Manifest.txt +121 -0
- data/README.txt +41 -0
- data/README_DB2.txt +33 -0
- data/Rakefile +65 -0
- data/init.rb +2 -0
- data/install.rb +30 -0
- data/lib/adapter_helper/base.rb +63 -0
- data/lib/adapter_helper/mysql.rb +13 -0
- data/lib/adapter_helper/oracle.rb +12 -0
- data/lib/adapter_helper/postgresql.rb +13 -0
- data/lib/adapter_helper/sqlite3.rb +13 -0
- data/lib/composite_primary_keys/association_preload.rb +236 -0
- data/lib/composite_primary_keys/associations.rb +427 -0
- data/lib/composite_primary_keys/attribute_methods.rb +84 -0
- data/lib/composite_primary_keys/base.rb +341 -0
- data/lib/composite_primary_keys/calculations.rb +68 -0
- data/lib/composite_primary_keys/composite_arrays.rb +30 -0
- data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +21 -0
- data/lib/composite_primary_keys/connection_adapters/oracle_adapter.rb +15 -0
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +53 -0
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +15 -0
- data/lib/composite_primary_keys/fixtures.rb +8 -0
- data/lib/composite_primary_keys/migration.rb +20 -0
- data/lib/composite_primary_keys/reflection.rb +19 -0
- data/lib/composite_primary_keys/version.rb +8 -0
- data/lib/composite_primary_keys.rb +57 -0
- data/loader.rb +24 -0
- data/local/database_connections.rb.sample +10 -0
- data/local/paths.rb.sample +2 -0
- data/local/tasks.rb.sample +2 -0
- data/scripts/console.rb +48 -0
- data/scripts/txt2html +67 -0
- data/scripts/txt2js +59 -0
- data/tasks/activerecord_selection.rake +43 -0
- data/tasks/databases/mysql.rake +30 -0
- data/tasks/databases/oracle.rake +25 -0
- data/tasks/databases/postgresql.rake +26 -0
- data/tasks/databases/sqlite3.rake +28 -0
- data/tasks/databases.rake +12 -0
- data/tasks/deployment.rake +22 -0
- data/tasks/local_setup.rake +13 -0
- data/tasks/website.rake +18 -0
- data/test/README_tests.txt +67 -0
- data/test/abstract_unit.rb +96 -0
- data/test/connections/native_ibm_db/connection.rb +23 -0
- data/test/connections/native_mysql/connection.rb +13 -0
- data/test/connections/native_oracle/connection.rb +14 -0
- data/test/connections/native_postgresql/connection.rb +9 -0
- data/test/connections/native_sqlite/connection.rb +9 -0
- data/test/fixtures/article.rb +5 -0
- data/test/fixtures/articles.yml +6 -0
- data/test/fixtures/comment.rb +6 -0
- data/test/fixtures/comments.yml +16 -0
- data/test/fixtures/db_definitions/db2-create-tables.sql +113 -0
- data/test/fixtures/db_definitions/db2-drop-tables.sql +16 -0
- data/test/fixtures/db_definitions/mysql.sql +174 -0
- data/test/fixtures/db_definitions/oracle.drop.sql +39 -0
- data/test/fixtures/db_definitions/oracle.sql +188 -0
- data/test/fixtures/db_definitions/postgresql.sql +199 -0
- data/test/fixtures/db_definitions/sqlite.sql +160 -0
- data/test/fixtures/department.rb +5 -0
- data/test/fixtures/departments.yml +3 -0
- data/test/fixtures/employee.rb +4 -0
- data/test/fixtures/employees.yml +9 -0
- data/test/fixtures/group.rb +3 -0
- data/test/fixtures/groups.yml +3 -0
- data/test/fixtures/hack.rb +6 -0
- data/test/fixtures/hacks.yml +2 -0
- data/test/fixtures/membership.rb +7 -0
- data/test/fixtures/membership_status.rb +3 -0
- data/test/fixtures/membership_statuses.yml +10 -0
- data/test/fixtures/memberships.yml +6 -0
- data/test/fixtures/product.rb +7 -0
- data/test/fixtures/product_tariff.rb +5 -0
- data/test/fixtures/product_tariffs.yml +12 -0
- data/test/fixtures/products.yml +6 -0
- data/test/fixtures/reading.rb +4 -0
- data/test/fixtures/readings.yml +10 -0
- data/test/fixtures/reference_code.rb +7 -0
- data/test/fixtures/reference_codes.yml +28 -0
- data/test/fixtures/reference_type.rb +7 -0
- data/test/fixtures/reference_types.yml +9 -0
- data/test/fixtures/street.rb +3 -0
- data/test/fixtures/streets.yml +15 -0
- data/test/fixtures/suburb.rb +6 -0
- data/test/fixtures/suburbs.yml +9 -0
- data/test/fixtures/tariff.rb +6 -0
- data/test/fixtures/tariffs.yml +13 -0
- data/test/fixtures/user.rb +10 -0
- data/test/fixtures/users.yml +6 -0
- data/test/hash_tricks.rb +34 -0
- data/test/plugins/pagination.rb +405 -0
- data/test/plugins/pagination_helper.rb +135 -0
- data/test/test_associations.rb +160 -0
- data/test/test_attribute_methods.rb +22 -0
- data/test/test_attributes.rb +84 -0
- data/test/test_clone.rb +34 -0
- data/test/test_composite_arrays.rb +51 -0
- data/test/test_create.rb +68 -0
- data/test/test_delete.rb +96 -0
- data/test/test_dummy.rb +28 -0
- data/test/test_find.rb +73 -0
- data/test/test_ids.rb +97 -0
- data/test/test_miscellaneous.rb +39 -0
- data/test/test_pagination.rb +38 -0
- data/test/test_polymorphic.rb +31 -0
- data/test/test_santiago.rb +27 -0
- data/test/test_tutorial_examle.rb +26 -0
- data/test/test_update.rb +40 -0
- data/tmp/test.db +0 -0
- data/website/index.html +195 -0
- data/website/index.txt +159 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +126 -0
- data/website/template.js +3 -0
- data/website/template.rhtml +53 -0
- data/website/version-raw.js +4 -0
- data/website/version-raw.txt +2 -0
- data/website/version.js +4 -0
- data/website/version.txt +3 -0
- metadata +197 -0
@@ -0,0 +1,199 @@
|
|
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)
|
9
|
+
);
|
10
|
+
|
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
|
+
);
|
18
|
+
|
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)
|
25
|
+
);
|
26
|
+
|
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)
|
32
|
+
);
|
33
|
+
|
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)
|
39
|
+
);
|
40
|
+
|
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)
|
46
|
+
);
|
47
|
+
|
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)
|
56
|
+
);
|
57
|
+
|
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)
|
64
|
+
);
|
65
|
+
|
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)
|
72
|
+
);
|
73
|
+
|
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)
|
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)
|
90
|
+
);
|
91
|
+
|
92
|
+
create table memberships (
|
93
|
+
user_id int not null,
|
94
|
+
group_id int not null,
|
95
|
+
primary key (user_id, group_id)
|
96
|
+
);
|
97
|
+
|
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)
|
106
|
+
);
|
107
|
+
|
108
|
+
create table departments (
|
109
|
+
department_id int not null,
|
110
|
+
location_id int not null,
|
111
|
+
primary key (department_id, location_id)
|
112
|
+
);
|
113
|
+
|
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)
|
121
|
+
);
|
122
|
+
|
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)
|
131
|
+
);
|
132
|
+
|
133
|
+
create table hacks (
|
134
|
+
name varchar(50) not null,
|
135
|
+
primary key (name)
|
136
|
+
);
|
137
|
+
|
138
|
+
create table kitchen_sinks (
|
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
|
+
|
@@ -0,0 +1,160 @@
|
|
1
|
+
create table reference_types (
|
2
|
+
reference_type_id integer primary key,
|
3
|
+
type_label varchar(50) default null,
|
4
|
+
abbreviation varchar(50) default null,
|
5
|
+
description varchar(50) default null
|
6
|
+
);
|
7
|
+
|
8
|
+
create table reference_codes (
|
9
|
+
reference_type_id int(11),
|
10
|
+
reference_code int(11) not null,
|
11
|
+
code_label varchar(50) default null,
|
12
|
+
abbreviation varchar(50) default null,
|
13
|
+
description varchar(50) default null,
|
14
|
+
primary key (reference_type_id, reference_code)
|
15
|
+
);
|
16
|
+
|
17
|
+
create table products (
|
18
|
+
id int(11) not null primary key,
|
19
|
+
name varchar(50) default null
|
20
|
+
);
|
21
|
+
|
22
|
+
create table tariffs (
|
23
|
+
tariff_id int(11) not null,
|
24
|
+
start_date date not null,
|
25
|
+
amount integer(11) default null,
|
26
|
+
primary key (tariff_id, start_date)
|
27
|
+
);
|
28
|
+
|
29
|
+
create table product_tariffs (
|
30
|
+
product_id int(11) not null,
|
31
|
+
tariff_id int(11) not null,
|
32
|
+
tariff_start_date date not null,
|
33
|
+
primary key (product_id, tariff_id, tariff_start_date)
|
34
|
+
);
|
35
|
+
|
36
|
+
create table suburbs (
|
37
|
+
city_id int(11) not null,
|
38
|
+
suburb_id int(11) not null,
|
39
|
+
name varchar(50) not null,
|
40
|
+
primary key (city_id, suburb_id)
|
41
|
+
);
|
42
|
+
|
43
|
+
create table streets (
|
44
|
+
id integer not null primary key autoincrement,
|
45
|
+
city_id int(11) not null,
|
46
|
+
suburb_id int(11) not null,
|
47
|
+
name varchar(50) not null
|
48
|
+
);
|
49
|
+
|
50
|
+
create table users (
|
51
|
+
id integer not null primary key autoincrement,
|
52
|
+
name varchar(50) not null
|
53
|
+
);
|
54
|
+
|
55
|
+
create table articles (
|
56
|
+
id integer not null primary key autoincrement,
|
57
|
+
name varchar(50) not null
|
58
|
+
);
|
59
|
+
|
60
|
+
create table readings (
|
61
|
+
id integer not null primary key autoincrement,
|
62
|
+
user_id int(11) not null,
|
63
|
+
article_id int(11) not null,
|
64
|
+
rating int(11) not null
|
65
|
+
);
|
66
|
+
|
67
|
+
create table groups (
|
68
|
+
id integer not null primary key autoincrement,
|
69
|
+
name varchar(50) not null
|
70
|
+
);
|
71
|
+
|
72
|
+
create table memberships (
|
73
|
+
user_id int not null,
|
74
|
+
group_id int not null,
|
75
|
+
primary key (user_id, group_id)
|
76
|
+
);
|
77
|
+
|
78
|
+
create table membership_statuses (
|
79
|
+
id integer not null primary key autoincrement,
|
80
|
+
user_id int not null,
|
81
|
+
group_id int not null,
|
82
|
+
status varchar(50) not null
|
83
|
+
);
|
84
|
+
|
85
|
+
create table departments (
|
86
|
+
department_id integer not null,
|
87
|
+
location_id integer not null,
|
88
|
+
primary key (department_id, location_id)
|
89
|
+
);
|
90
|
+
|
91
|
+
create table employees (
|
92
|
+
id integer not null primary key autoincrement,
|
93
|
+
department_id integer null,
|
94
|
+
location_id integer null
|
95
|
+
);
|
96
|
+
|
97
|
+
create table comments (
|
98
|
+
id integer not null primary key autoincrement,
|
99
|
+
person_id varchar(100) null,
|
100
|
+
person_type varchar(100) null,
|
101
|
+
hack_id varchar(100) null
|
102
|
+
);
|
103
|
+
|
104
|
+
create table hacks (
|
105
|
+
name varchar(50) not null primary key
|
106
|
+
);
|
107
|
+
|
108
|
+
create table kitchen_sinks (
|
109
|
+
id_1 integer not null,
|
110
|
+
id_2 integer not null,
|
111
|
+
a_date date,
|
112
|
+
a_string varchar(100),
|
113
|
+
primary key (id_1, id_2)
|
114
|
+
);
|
115
|
+
|
116
|
+
create table restaurants (
|
117
|
+
franchise_id integer not null,
|
118
|
+
store_id integer not null,
|
119
|
+
name varchar(100),
|
120
|
+
primary key (franchise_id, store_id)
|
121
|
+
);
|
122
|
+
|
123
|
+
create table restaurants_suburbs (
|
124
|
+
franchise_id integer not null,
|
125
|
+
store_id integer not null,
|
126
|
+
city_id integer not null,
|
127
|
+
suburb_id integer not null
|
128
|
+
);
|
129
|
+
|
130
|
+
create table dorms (
|
131
|
+
id integer not null primary key autoincrement
|
132
|
+
);
|
133
|
+
|
134
|
+
create table rooms (
|
135
|
+
dorm_id integer not null,
|
136
|
+
room_id integer not null,
|
137
|
+
primary key (dorm_id, room_id)
|
138
|
+
);
|
139
|
+
|
140
|
+
create table room_attributes (
|
141
|
+
id integer not null primary key autoincrement,
|
142
|
+
name varchar(50)
|
143
|
+
);
|
144
|
+
|
145
|
+
create table room_attribute_assignments (
|
146
|
+
dorm_id integer not null,
|
147
|
+
room_id integer not null,
|
148
|
+
room_attribute_id integer not null
|
149
|
+
);
|
150
|
+
|
151
|
+
create table students (
|
152
|
+
id integer not null primary key autoincrement
|
153
|
+
);
|
154
|
+
|
155
|
+
create table room_assignments (
|
156
|
+
student_id integer not null,
|
157
|
+
dorm_id integer not null,
|
158
|
+
room_id integer not null
|
159
|
+
);
|
160
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class Membership < ActiveRecord::Base
|
2
|
+
# set_primary_keys *keys - turns on composite key functionality
|
3
|
+
set_primary_keys :user_id, :group_id
|
4
|
+
belongs_to :user
|
5
|
+
belongs_to :group
|
6
|
+
has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
7
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class Product < ActiveRecord::Base
|
2
|
+
set_primary_keys :id # redundant
|
3
|
+
has_many :product_tariffs, :foreign_key => :product_id
|
4
|
+
has_one :product_tariff, :foreign_key => :product_id
|
5
|
+
|
6
|
+
has_many :tariffs, :through => :product_tariffs, :foreign_key => [:tariff_id, :tariff_start_date]
|
7
|
+
end
|