kovyrin-composite_primary_keys 2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/History.txt +164 -0
  2. data/Manifest.txt +121 -0
  3. data/README.txt +41 -0
  4. data/README_DB2.txt +33 -0
  5. data/Rakefile +65 -0
  6. data/init.rb +2 -0
  7. data/install.rb +30 -0
  8. data/lib/adapter_helper/base.rb +63 -0
  9. data/lib/adapter_helper/mysql.rb +13 -0
  10. data/lib/adapter_helper/oracle.rb +12 -0
  11. data/lib/adapter_helper/postgresql.rb +13 -0
  12. data/lib/adapter_helper/sqlite3.rb +13 -0
  13. data/lib/composite_primary_keys/association_preload.rb +236 -0
  14. data/lib/composite_primary_keys/associations.rb +427 -0
  15. data/lib/composite_primary_keys/attribute_methods.rb +84 -0
  16. data/lib/composite_primary_keys/base.rb +341 -0
  17. data/lib/composite_primary_keys/calculations.rb +68 -0
  18. data/lib/composite_primary_keys/composite_arrays.rb +30 -0
  19. data/lib/composite_primary_keys/connection_adapters/ibm_db_adapter.rb +21 -0
  20. data/lib/composite_primary_keys/connection_adapters/oracle_adapter.rb +15 -0
  21. data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +53 -0
  22. data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +15 -0
  23. data/lib/composite_primary_keys/fixtures.rb +8 -0
  24. data/lib/composite_primary_keys/migration.rb +20 -0
  25. data/lib/composite_primary_keys/reflection.rb +19 -0
  26. data/lib/composite_primary_keys/version.rb +8 -0
  27. data/lib/composite_primary_keys.rb +57 -0
  28. data/loader.rb +24 -0
  29. data/local/database_connections.rb.sample +10 -0
  30. data/local/paths.rb.sample +2 -0
  31. data/local/tasks.rb.sample +2 -0
  32. data/scripts/console.rb +48 -0
  33. data/scripts/txt2html +67 -0
  34. data/scripts/txt2js +59 -0
  35. data/tasks/activerecord_selection.rake +43 -0
  36. data/tasks/databases/mysql.rake +30 -0
  37. data/tasks/databases/oracle.rake +25 -0
  38. data/tasks/databases/postgresql.rake +26 -0
  39. data/tasks/databases/sqlite3.rake +28 -0
  40. data/tasks/databases.rake +12 -0
  41. data/tasks/deployment.rake +22 -0
  42. data/tasks/local_setup.rake +13 -0
  43. data/tasks/website.rake +18 -0
  44. data/test/README_tests.txt +67 -0
  45. data/test/abstract_unit.rb +96 -0
  46. data/test/connections/native_ibm_db/connection.rb +23 -0
  47. data/test/connections/native_mysql/connection.rb +13 -0
  48. data/test/connections/native_oracle/connection.rb +14 -0
  49. data/test/connections/native_postgresql/connection.rb +9 -0
  50. data/test/connections/native_sqlite/connection.rb +9 -0
  51. data/test/fixtures/article.rb +5 -0
  52. data/test/fixtures/articles.yml +6 -0
  53. data/test/fixtures/comment.rb +6 -0
  54. data/test/fixtures/comments.yml +16 -0
  55. data/test/fixtures/db_definitions/db2-create-tables.sql +113 -0
  56. data/test/fixtures/db_definitions/db2-drop-tables.sql +16 -0
  57. data/test/fixtures/db_definitions/mysql.sql +174 -0
  58. data/test/fixtures/db_definitions/oracle.drop.sql +39 -0
  59. data/test/fixtures/db_definitions/oracle.sql +188 -0
  60. data/test/fixtures/db_definitions/postgresql.sql +199 -0
  61. data/test/fixtures/db_definitions/sqlite.sql +160 -0
  62. data/test/fixtures/department.rb +5 -0
  63. data/test/fixtures/departments.yml +3 -0
  64. data/test/fixtures/employee.rb +4 -0
  65. data/test/fixtures/employees.yml +9 -0
  66. data/test/fixtures/group.rb +3 -0
  67. data/test/fixtures/groups.yml +3 -0
  68. data/test/fixtures/hack.rb +6 -0
  69. data/test/fixtures/hacks.yml +2 -0
  70. data/test/fixtures/membership.rb +7 -0
  71. data/test/fixtures/membership_status.rb +3 -0
  72. data/test/fixtures/membership_statuses.yml +10 -0
  73. data/test/fixtures/memberships.yml +6 -0
  74. data/test/fixtures/product.rb +7 -0
  75. data/test/fixtures/product_tariff.rb +5 -0
  76. data/test/fixtures/product_tariffs.yml +12 -0
  77. data/test/fixtures/products.yml +6 -0
  78. data/test/fixtures/reading.rb +4 -0
  79. data/test/fixtures/readings.yml +10 -0
  80. data/test/fixtures/reference_code.rb +7 -0
  81. data/test/fixtures/reference_codes.yml +28 -0
  82. data/test/fixtures/reference_type.rb +7 -0
  83. data/test/fixtures/reference_types.yml +9 -0
  84. data/test/fixtures/street.rb +3 -0
  85. data/test/fixtures/streets.yml +15 -0
  86. data/test/fixtures/suburb.rb +6 -0
  87. data/test/fixtures/suburbs.yml +9 -0
  88. data/test/fixtures/tariff.rb +6 -0
  89. data/test/fixtures/tariffs.yml +13 -0
  90. data/test/fixtures/user.rb +10 -0
  91. data/test/fixtures/users.yml +6 -0
  92. data/test/hash_tricks.rb +34 -0
  93. data/test/plugins/pagination.rb +405 -0
  94. data/test/plugins/pagination_helper.rb +135 -0
  95. data/test/test_associations.rb +160 -0
  96. data/test/test_attribute_methods.rb +22 -0
  97. data/test/test_attributes.rb +84 -0
  98. data/test/test_clone.rb +34 -0
  99. data/test/test_composite_arrays.rb +51 -0
  100. data/test/test_create.rb +68 -0
  101. data/test/test_delete.rb +96 -0
  102. data/test/test_dummy.rb +28 -0
  103. data/test/test_find.rb +73 -0
  104. data/test/test_ids.rb +97 -0
  105. data/test/test_miscellaneous.rb +39 -0
  106. data/test/test_pagination.rb +38 -0
  107. data/test/test_polymorphic.rb +31 -0
  108. data/test/test_santiago.rb +27 -0
  109. data/test/test_tutorial_examle.rb +26 -0
  110. data/test/test_update.rb +40 -0
  111. data/tmp/test.db +0 -0
  112. data/website/index.html +195 -0
  113. data/website/index.txt +159 -0
  114. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  115. data/website/stylesheets/screen.css +126 -0
  116. data/website/template.js +3 -0
  117. data/website/template.rhtml +53 -0
  118. data/website/version-raw.js +4 -0
  119. data/website/version-raw.txt +2 -0
  120. data/website/version.js +4 -0
  121. data/website/version.txt +3 -0
  122. 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,5 @@
1
+ class Department < ActiveRecord::Base
2
+ # set_primary_keys *keys - turns on composite key functionality
3
+ set_primary_keys :department_id, :location_id
4
+ has_many :employees, :foreign_key => [:department_id, :location_id]
5
+ end
@@ -0,0 +1,3 @@
1
+ department1-cpk:
2
+ department_id: 1
3
+ location_id: 1
@@ -0,0 +1,4 @@
1
+ class Employee < ActiveRecord::Base
2
+ belongs_to :department, :foreign_key => [:department_id, :location_id]
3
+ has_many :comments, :as => :person
4
+ end
@@ -0,0 +1,9 @@
1
+ employee1:
2
+ id: 1
3
+ department_id: 1
4
+ location_id: 1
5
+ employee2:
6
+ id: 2
7
+ department_id: 1
8
+ location_id: 1
9
+
@@ -0,0 +1,3 @@
1
+ class Group < ActiveRecord::Base
2
+ has_many :memberships
3
+ end
@@ -0,0 +1,3 @@
1
+ cpk:
2
+ id: 1
3
+ name: Composite Primary Keys
@@ -0,0 +1,6 @@
1
+ class Hack < ActiveRecord::Base
2
+ set_primary_keys :name
3
+ has_many :comments, :as => :person
4
+
5
+ has_one :first_comment, :as => :person, :class_name => "Comment"
6
+ end
@@ -0,0 +1,2 @@
1
+ andrew:
2
+ name: andrew
@@ -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,3 @@
1
+ class MembershipStatus < ActiveRecord::Base
2
+ belongs_to :membership, :foreign_key => [:user_id, :group_id]
3
+ end
@@ -0,0 +1,10 @@
1
+ santiago-cpk:
2
+ id: 1
3
+ user_id: 1
4
+ group_id: 1
5
+ status: Active
6
+ drnic-cpk:
7
+ id: 2
8
+ user_id: 2
9
+ group_id: 1
10
+ status: Owner
@@ -0,0 +1,6 @@
1
+ santiago-cpk:
2
+ user_id: 1
3
+ group_id: 1
4
+ drnic-cpk:
5
+ user_id: 2
6
+ group_id: 1
@@ -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