rubyrep 1.0.0
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 +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +137 -0
- data/README.txt +37 -0
- data/Rakefile +30 -0
- data/bin/rubyrep +8 -0
- data/config/hoe.rb +72 -0
- data/config/mysql_config.rb +25 -0
- data/config/postgres_config.rb +21 -0
- data/config/proxied_test_config.rb +14 -0
- data/config/redmine_config.rb +17 -0
- data/config/rep_config.rb +20 -0
- data/config/requirements.rb +32 -0
- data/config/test_config.rb +20 -0
- data/lib/rubyrep/base_runner.rb +195 -0
- data/lib/rubyrep/command_runner.rb +144 -0
- data/lib/rubyrep/committers/buffered_committer.rb +140 -0
- data/lib/rubyrep/committers/committers.rb +146 -0
- data/lib/rubyrep/configuration.rb +240 -0
- data/lib/rubyrep/connection_extenders/connection_extenders.rb +133 -0
- data/lib/rubyrep/connection_extenders/jdbc_extender.rb +284 -0
- data/lib/rubyrep/connection_extenders/mysql_extender.rb +168 -0
- data/lib/rubyrep/connection_extenders/postgresql_extender.rb +261 -0
- data/lib/rubyrep/database_proxy.rb +52 -0
- data/lib/rubyrep/direct_table_scan.rb +75 -0
- data/lib/rubyrep/generate_runner.rb +105 -0
- data/lib/rubyrep/initializer.rb +39 -0
- data/lib/rubyrep/logged_change.rb +326 -0
- data/lib/rubyrep/proxied_table_scan.rb +171 -0
- data/lib/rubyrep/proxy_block_cursor.rb +145 -0
- data/lib/rubyrep/proxy_connection.rb +318 -0
- data/lib/rubyrep/proxy_cursor.rb +44 -0
- data/lib/rubyrep/proxy_row_cursor.rb +43 -0
- data/lib/rubyrep/proxy_runner.rb +89 -0
- data/lib/rubyrep/replication_difference.rb +91 -0
- data/lib/rubyrep/replication_extenders/mysql_replication.rb +271 -0
- data/lib/rubyrep/replication_extenders/postgresql_replication.rb +204 -0
- data/lib/rubyrep/replication_extenders/replication_extenders.rb +26 -0
- data/lib/rubyrep/replication_helper.rb +104 -0
- data/lib/rubyrep/replication_initializer.rb +307 -0
- data/lib/rubyrep/replication_run.rb +48 -0
- data/lib/rubyrep/replication_runner.rb +138 -0
- data/lib/rubyrep/replicators/replicators.rb +37 -0
- data/lib/rubyrep/replicators/two_way_replicator.rb +334 -0
- data/lib/rubyrep/scan_progress_printers/progress_bar.rb +65 -0
- data/lib/rubyrep/scan_progress_printers/scan_progress_printers.rb +65 -0
- data/lib/rubyrep/scan_report_printers/scan_detail_reporter.rb +111 -0
- data/lib/rubyrep/scan_report_printers/scan_report_printers.rb +67 -0
- data/lib/rubyrep/scan_report_printers/scan_summary_reporter.rb +75 -0
- data/lib/rubyrep/scan_runner.rb +25 -0
- data/lib/rubyrep/session.rb +177 -0
- data/lib/rubyrep/sync_helper.rb +111 -0
- data/lib/rubyrep/sync_runner.rb +31 -0
- data/lib/rubyrep/syncers/syncers.rb +112 -0
- data/lib/rubyrep/syncers/two_way_syncer.rb +174 -0
- data/lib/rubyrep/table_scan.rb +54 -0
- data/lib/rubyrep/table_scan_helper.rb +38 -0
- data/lib/rubyrep/table_sorter.rb +70 -0
- data/lib/rubyrep/table_spec_resolver.rb +136 -0
- data/lib/rubyrep/table_sync.rb +68 -0
- data/lib/rubyrep/trigger_mode_switcher.rb +63 -0
- data/lib/rubyrep/type_casting_cursor.rb +31 -0
- data/lib/rubyrep/uninstall_runner.rb +92 -0
- data/lib/rubyrep/version.rb +9 -0
- data/lib/rubyrep.rb +68 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/sims/performance/big_rep_spec.rb +100 -0
- data/sims/performance/big_scan_spec.rb +57 -0
- data/sims/performance/big_sync_spec.rb +141 -0
- data/sims/performance/performance.rake +228 -0
- data/sims/sim_helper.rb +24 -0
- data/spec/base_runner_spec.rb +218 -0
- data/spec/buffered_committer_spec.rb +271 -0
- data/spec/command_runner_spec.rb +145 -0
- data/spec/committers_spec.rb +174 -0
- data/spec/configuration_spec.rb +198 -0
- data/spec/connection_extender_interface_spec.rb +138 -0
- data/spec/connection_extenders_registration_spec.rb +129 -0
- data/spec/database_proxy_spec.rb +48 -0
- data/spec/database_rake_spec.rb +40 -0
- data/spec/db_specific_connection_extenders_spec.rb +34 -0
- data/spec/db_specific_replication_extenders_spec.rb +38 -0
- data/spec/direct_table_scan_spec.rb +61 -0
- data/spec/generate_runner_spec.rb +84 -0
- data/spec/initializer_spec.rb +46 -0
- data/spec/logged_change_spec.rb +480 -0
- data/spec/postgresql_replication_spec.rb +48 -0
- data/spec/postgresql_support_spec.rb +57 -0
- data/spec/progress_bar_spec.rb +77 -0
- data/spec/proxied_table_scan_spec.rb +151 -0
- data/spec/proxy_block_cursor_spec.rb +197 -0
- data/spec/proxy_connection_spec.rb +399 -0
- data/spec/proxy_cursor_spec.rb +56 -0
- data/spec/proxy_row_cursor_spec.rb +66 -0
- data/spec/proxy_runner_spec.rb +70 -0
- data/spec/replication_difference_spec.rb +160 -0
- data/spec/replication_extender_interface_spec.rb +365 -0
- data/spec/replication_extenders_spec.rb +32 -0
- data/spec/replication_helper_spec.rb +121 -0
- data/spec/replication_initializer_spec.rb +477 -0
- data/spec/replication_run_spec.rb +166 -0
- data/spec/replication_runner_spec.rb +213 -0
- data/spec/replicators_spec.rb +31 -0
- data/spec/rubyrep_spec.rb +8 -0
- data/spec/scan_detail_reporter_spec.rb +119 -0
- data/spec/scan_progress_printers_spec.rb +68 -0
- data/spec/scan_report_printers_spec.rb +67 -0
- data/spec/scan_runner_spec.rb +50 -0
- data/spec/scan_summary_reporter_spec.rb +61 -0
- data/spec/session_spec.rb +212 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +295 -0
- data/spec/sync_helper_spec.rb +157 -0
- data/spec/sync_runner_spec.rb +78 -0
- data/spec/syncers_spec.rb +171 -0
- data/spec/table_scan_helper_spec.rb +29 -0
- data/spec/table_scan_spec.rb +49 -0
- data/spec/table_sorter_spec.rb +31 -0
- data/spec/table_spec_resolver_spec.rb +102 -0
- data/spec/table_sync_spec.rb +84 -0
- data/spec/trigger_mode_switcher_spec.rb +83 -0
- data/spec/two_way_replicator_spec.rb +551 -0
- data/spec/two_way_syncer_spec.rb +256 -0
- data/spec/type_casting_cursor_spec.rb +50 -0
- data/spec/uninstall_runner_spec.rb +86 -0
- data/tasks/database.rake +439 -0
- data/tasks/deployment.rake +29 -0
- data/tasks/environment.rake +9 -0
- data/tasks/java.rake +37 -0
- data/tasks/redmine_test.rake +47 -0
- data/tasks/rspec.rake +68 -0
- data/tasks/rubyrep.tailor +18 -0
- data/tasks/stats.rake +19 -0
- data/tasks/task_helper.rb +20 -0
- data.tar.gz.sig +0 -0
- metadata +243 -0
- metadata.gz.sig +0 -0
data/tasks/database.rake
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + "../lib/rubyrep"
|
|
2
|
+
require 'rake'
|
|
3
|
+
require 'rubyrep'
|
|
4
|
+
|
|
5
|
+
require File.dirname(__FILE__) + '/task_helper.rb'
|
|
6
|
+
require File.dirname(__FILE__) + '/../config/test_config'
|
|
7
|
+
|
|
8
|
+
# Creates the databases for the given configuration hash
|
|
9
|
+
def create_database(config)
|
|
10
|
+
begin
|
|
11
|
+
RR::ConnectionExtenders.db_connect(config)
|
|
12
|
+
rescue
|
|
13
|
+
case config[:adapter]
|
|
14
|
+
when 'postgresql'
|
|
15
|
+
`createdb "#{config[:database]}" -E utf8`
|
|
16
|
+
when 'mysql'
|
|
17
|
+
@charset = ENV['CHARSET'] || 'utf8'
|
|
18
|
+
@collation = ENV['COLLATION'] || 'utf8_general_ci'
|
|
19
|
+
begin
|
|
20
|
+
connection = RR::ConnectionExtenders.db_connect(config.merge({'database' => nil}))
|
|
21
|
+
connection.create_database(config[:database], {:charset => @charset, :collation => @collation})
|
|
22
|
+
RR::ConnectionExtenders.db_connect(config)
|
|
23
|
+
rescue
|
|
24
|
+
$stderr.puts $!
|
|
25
|
+
$stderr.puts "Couldn't create database for #{config.inspect}"
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
puts "adapter #{config[:adapter]} not supported"
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
puts "database #{config[:database]} already exists"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Drops the databases identified by the given configuration hash
|
|
36
|
+
def drop_database(config)
|
|
37
|
+
case config[:adapter]
|
|
38
|
+
when 'postgresql'
|
|
39
|
+
`dropdb "#{config[:database]}"`
|
|
40
|
+
when 'mysql'
|
|
41
|
+
connection = RR::ConnectionExtenders.db_connect(config.merge({'database' => nil}))
|
|
42
|
+
connection.drop_database config[:database]
|
|
43
|
+
else
|
|
44
|
+
puts "adapter #{config[:adapter]} not supported"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Creates the schema and tables for the postgres schema test
|
|
49
|
+
def create_postgres_schema(config)
|
|
50
|
+
return unless config[:adapter] == 'postgresql'
|
|
51
|
+
ActiveRecord::Base.establish_connection config
|
|
52
|
+
ActiveRecord::Schema.define do
|
|
53
|
+
execute <<-end_sql
|
|
54
|
+
create schema rr;
|
|
55
|
+
|
|
56
|
+
set search_path to rr;
|
|
57
|
+
end_sql
|
|
58
|
+
|
|
59
|
+
create_table :rr_simple do |t|
|
|
60
|
+
t.column :name, :string
|
|
61
|
+
end
|
|
62
|
+
execute "insert into rr_simple(id, name) values(1, 'bla')"
|
|
63
|
+
|
|
64
|
+
create_table :rr_referenced, :id => true do |t|
|
|
65
|
+
t.column :name, :string
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
create_table :rr_referencing, :id => true do |t|
|
|
69
|
+
t.column :rr_referenced_id, :integer
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
ActiveRecord::Base.connection.execute(<<-end_sql)
|
|
73
|
+
ALTER TABLE rr_referencing ADD CONSTRAINT rr_referenced_fkey
|
|
74
|
+
FOREIGN KEY (rr_referenced_id)
|
|
75
|
+
REFERENCES rr_referenced(id)
|
|
76
|
+
end_sql
|
|
77
|
+
|
|
78
|
+
create_table :rr_trigger_test, :id => false do |t|
|
|
79
|
+
t.column :first_id, :integer
|
|
80
|
+
t.column :second_id, :integer
|
|
81
|
+
t.column :name, :string
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil
|
|
85
|
+
ALTER TABLE rr_trigger_test ADD CONSTRAINT rr_trigger_test_pkey
|
|
86
|
+
PRIMARY KEY (first_id, second_id)
|
|
87
|
+
end_sql
|
|
88
|
+
|
|
89
|
+
create_table :rr_sequence_test do |t|
|
|
90
|
+
t.column :name, :string
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Drops the schema and tables that were created for the postgres schema test
|
|
96
|
+
def drop_postgres_schema(config)
|
|
97
|
+
return unless config[:adapter] == 'postgresql'
|
|
98
|
+
ActiveRecord::Base.establish_connection config
|
|
99
|
+
ActiveRecord::Schema.define do
|
|
100
|
+
execute "drop schema rr cascade"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Creates the sample schema in the database specified by the given
|
|
105
|
+
# configuration hash.
|
|
106
|
+
def create_sample_schema(config)
|
|
107
|
+
create_postgres_schema config
|
|
108
|
+
|
|
109
|
+
ActiveRecord::Base.establish_connection config
|
|
110
|
+
|
|
111
|
+
ActiveRecord::Schema.define do
|
|
112
|
+
create_table :scanner_text_key, :id => false do |t|
|
|
113
|
+
t.column :text_id, :string
|
|
114
|
+
t.column :name, :string
|
|
115
|
+
end rescue nil
|
|
116
|
+
|
|
117
|
+
ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil
|
|
118
|
+
ALTER TABLE scanner_text_key ADD CONSTRAINT scanner_text_key_pkey
|
|
119
|
+
PRIMARY KEY (text_id)
|
|
120
|
+
end_sql
|
|
121
|
+
|
|
122
|
+
create_table :scanner_records do |t|
|
|
123
|
+
t.column :name, :string, :null => false
|
|
124
|
+
end rescue nil
|
|
125
|
+
|
|
126
|
+
add_index :scanner_records, :name, :unique rescue nil
|
|
127
|
+
|
|
128
|
+
create_table :scanner_left_records_only do |t|
|
|
129
|
+
t.column :name, :string, :null => false
|
|
130
|
+
end rescue nil
|
|
131
|
+
|
|
132
|
+
create_table :extender_combined_key, :id => false do |t|
|
|
133
|
+
t.column :first_id, :integer
|
|
134
|
+
t.column :second_id, :integer
|
|
135
|
+
t.column :name, :string
|
|
136
|
+
end rescue nil
|
|
137
|
+
|
|
138
|
+
ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil
|
|
139
|
+
ALTER TABLE extender_combined_key ADD CONSTRAINT extender_combined_key_pkey
|
|
140
|
+
PRIMARY KEY (first_id, second_id)
|
|
141
|
+
end_sql
|
|
142
|
+
|
|
143
|
+
create_table :referenced_table, :id => false do |t|
|
|
144
|
+
t.column :first_id, :integer
|
|
145
|
+
t.column :second_id, :integer
|
|
146
|
+
t.column :name, :string
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil
|
|
150
|
+
ALTER TABLE referenced_table ADD CONSTRAINT referenced_table_pkey
|
|
151
|
+
PRIMARY KEY (first_id, second_id)
|
|
152
|
+
end_sql
|
|
153
|
+
|
|
154
|
+
create_table :referenced_table2, :id => true do |t|
|
|
155
|
+
t.column :name, :string
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
create_table :referencing_table, :id => true do |t|
|
|
159
|
+
t.column :first_fk, :integer
|
|
160
|
+
t.column :second_fk, :integer
|
|
161
|
+
t.column :third_fk, :integer
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil
|
|
165
|
+
ALTER TABLE referencing_table ADD CONSTRAINT referencing_table_fkey
|
|
166
|
+
FOREIGN KEY (first_fk, second_fk)
|
|
167
|
+
REFERENCES referenced_table(first_id, second_id)
|
|
168
|
+
end_sql
|
|
169
|
+
|
|
170
|
+
ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil
|
|
171
|
+
ALTER TABLE referencing_table ADD CONSTRAINT referencing_table2_fkey
|
|
172
|
+
FOREIGN KEY (third_fk)
|
|
173
|
+
REFERENCES referenced_table2(id)
|
|
174
|
+
end_sql
|
|
175
|
+
|
|
176
|
+
create_table :extender_inverted_combined_key, :id => false do |t|
|
|
177
|
+
t.column :first_id, :integer
|
|
178
|
+
t.column :second_id, :integer
|
|
179
|
+
end rescue nil
|
|
180
|
+
|
|
181
|
+
ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil
|
|
182
|
+
ALTER TABLE extender_inverted_combined_key
|
|
183
|
+
ADD CONSTRAINT extender_inverted_combined_key_pkey
|
|
184
|
+
PRIMARY KEY (second_id, first_id)
|
|
185
|
+
end_sql
|
|
186
|
+
|
|
187
|
+
create_table :extender_without_key, :id => false do |t|
|
|
188
|
+
t.column :first_id, :integer
|
|
189
|
+
t.column :second_id, :integer
|
|
190
|
+
end rescue nil
|
|
191
|
+
|
|
192
|
+
create_table :extender_one_record do |t|
|
|
193
|
+
t.column :name, :string
|
|
194
|
+
end rescue nil
|
|
195
|
+
|
|
196
|
+
create_table :extender_no_record do |t|
|
|
197
|
+
t.column :name, :string
|
|
198
|
+
end rescue nil
|
|
199
|
+
|
|
200
|
+
create_table :extender_type_check do |t|
|
|
201
|
+
t.column :decimal_test, :decimal, :precision => 10, :scale => 5
|
|
202
|
+
t.column :timestamp, :timestamp
|
|
203
|
+
t.column :multi_byte, :string
|
|
204
|
+
t.column :binary_test, :binary
|
|
205
|
+
t.column :text_test, :text
|
|
206
|
+
end rescue nil
|
|
207
|
+
|
|
208
|
+
create_table :table_with_manual_key, :id => false do |t|
|
|
209
|
+
t.column :id, :integer
|
|
210
|
+
t.column :name, :string
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
create_table :rr_pending_changes do |t|
|
|
214
|
+
t.column :change_table, :string
|
|
215
|
+
t.column :change_key, :string
|
|
216
|
+
t.column :change_new_key, :string
|
|
217
|
+
t.column :change_type, :string
|
|
218
|
+
t.column :change_time, :timestamp
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
create_table :rr_logged_events do |t|
|
|
222
|
+
t.column :activity, :string
|
|
223
|
+
t.column :change_table, :string
|
|
224
|
+
t.column :diff_type, :string
|
|
225
|
+
t.column :change_key, :string
|
|
226
|
+
t.column :left_change_type, :string
|
|
227
|
+
t.column :right_change_type, :string
|
|
228
|
+
t.column :description, :string
|
|
229
|
+
t.column :long_description, :string, :limit => RR::ReplicationInitializer::LONG_DESCRIPTION_SIZE
|
|
230
|
+
t.column :event_time, :timestamp
|
|
231
|
+
t.column :diff_dump, :string, :limit => RR::ReplicationInitializer::DIFF_DUMP_SIZE
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
create_table :rr_running_flags, :id => false do |t|
|
|
235
|
+
t.column :active, :integer
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
create_table :trigger_test, :id => false do |t|
|
|
239
|
+
t.column :first_id, :integer
|
|
240
|
+
t.column :second_id, :integer
|
|
241
|
+
t.column :name, :string
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
ActiveRecord::Base.connection.execute(<<-end_sql) rescue nil
|
|
245
|
+
ALTER TABLE trigger_test ADD CONSTRAINT trigger_test_pkey
|
|
246
|
+
PRIMARY KEY (first_id, second_id)
|
|
247
|
+
end_sql
|
|
248
|
+
|
|
249
|
+
create_table :sequence_test do |t|
|
|
250
|
+
t.column :name, :string
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
create_table :left_table do |t|
|
|
254
|
+
t.column :name, :string
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
create_table :right_table do |t|
|
|
258
|
+
t.column :name, :string
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
# Removes all tables from the sample scheme
|
|
264
|
+
# config: Hash of configuration values for the desired database connection
|
|
265
|
+
def drop_sample_schema(config)
|
|
266
|
+
drop_postgres_schema config
|
|
267
|
+
|
|
268
|
+
connection = RR::ConnectionExtenders.db_connect(config)
|
|
269
|
+
ActiveRecord::Base.connection = connection
|
|
270
|
+
|
|
271
|
+
ActiveRecord::Schema.define do
|
|
272
|
+
drop_table :extender_type_check rescue nil
|
|
273
|
+
drop_table :extender_no_record rescue nil
|
|
274
|
+
drop_table :extender_one_record rescue nil
|
|
275
|
+
drop_table :extender_without_key rescue nil
|
|
276
|
+
drop_table :extender_inverted_combined_key rescue nil
|
|
277
|
+
drop_table :extender_combined_key rescue nil
|
|
278
|
+
drop_table :scanner_left_records_only rescue nil
|
|
279
|
+
drop_table :scanner_records rescue nil
|
|
280
|
+
drop_table :scanner_text_key rescue nil
|
|
281
|
+
drop_table :referencing_table rescue nil
|
|
282
|
+
drop_table :referenced_table rescue nil
|
|
283
|
+
drop_table :referenced_table2 rescue nil
|
|
284
|
+
drop_table :table_with_manual_key
|
|
285
|
+
drop_table :rr_pending_changes rescue nil
|
|
286
|
+
drop_table :rr_running_flags rescue nil
|
|
287
|
+
drop_table :trigger_test rescue nil
|
|
288
|
+
drop_table :sequence_test rescue nil
|
|
289
|
+
drop_table :left_table rescue nil
|
|
290
|
+
drop_table :right_table rescue nil
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
ActiveRecord::Base.connection.disconnect!
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
class ExtenderCombinedKey < ActiveRecord::Base
|
|
297
|
+
set_table_name "extender_combined_key"
|
|
298
|
+
include CreateWithKey
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
class ScannerRecords < ActiveRecord::Base
|
|
302
|
+
include CreateWithKey
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
class ScannerLeftRecordsOnly < ActiveRecord::Base
|
|
306
|
+
set_table_name "scanner_left_records_only"
|
|
307
|
+
include CreateWithKey
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
class ExtenderOneRecord < ActiveRecord::Base
|
|
311
|
+
set_table_name "extender_one_record"
|
|
312
|
+
include CreateWithKey
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
class ExtenderTypeCheck < ActiveRecord::Base
|
|
316
|
+
set_table_name "extender_type_check"
|
|
317
|
+
include CreateWithKey
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# Inserts the row as per specified :column_name => value hash in the specified database and table
|
|
321
|
+
# Used to create data in tables where the standard ActiveRecord approach doesn't work
|
|
322
|
+
# (E. g. tables with primary keys in text format)
|
|
323
|
+
def create_row(connection, table, row)
|
|
324
|
+
sql = "insert into #{table}("
|
|
325
|
+
sql << row.keys.join(', ')
|
|
326
|
+
sql << ") values('"
|
|
327
|
+
sql << row.values.join("', '")
|
|
328
|
+
sql << "')"
|
|
329
|
+
connection.execute sql
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
# Deletes all records and creates the records being same in left and right DB
|
|
333
|
+
def delete_all_and_create_shared_sample_data(config)
|
|
334
|
+
ActiveRecord::Base.establish_connection config
|
|
335
|
+
ScannerRecords.delete_all
|
|
336
|
+
ScannerRecords.create_with_key :id => 1, :name => 'Alice - exists in both databases'
|
|
337
|
+
|
|
338
|
+
ExtenderOneRecord.delete_all
|
|
339
|
+
ExtenderOneRecord.create_with_key :id => 1, :name => 'Alice'
|
|
340
|
+
|
|
341
|
+
ExtenderTypeCheck.delete_all
|
|
342
|
+
ExtenderTypeCheck.create_with_key(
|
|
343
|
+
:id => 1,
|
|
344
|
+
:decimal_test => 1.234,
|
|
345
|
+
:timestamp => Time.local(2007,"nov",10,20,15,1),
|
|
346
|
+
:multi_byte => "よろしくお願(ねが)いします yoroshiku onegai shimasu: I humbly ask for your favor.",
|
|
347
|
+
:binary_test => Marshal.dump(['bla',:dummy,1,2,3])
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
connection = ActiveRecord::Base.connection
|
|
351
|
+
# The primary key of this table is in text format - ActiveRecord cannot be
|
|
352
|
+
# used to create the example data.
|
|
353
|
+
connection.execute "delete from scanner_text_key"
|
|
354
|
+
[ {:text_id => 'a', :name => 'Alice'},
|
|
355
|
+
{:text_id => 'b', :name => 'Bob'},
|
|
356
|
+
{:text_id => 'c', :name => 'Charlie'}
|
|
357
|
+
].each { |row| create_row connection, 'scanner_text_key', row}
|
|
358
|
+
|
|
359
|
+
# ActiveRecord also doesn't handle tables with combined primary keys
|
|
360
|
+
connection.execute("delete from extender_combined_key")
|
|
361
|
+
[
|
|
362
|
+
{:first_id => 1, :second_id => 1, :name => 'aa'},
|
|
363
|
+
{:first_id => 1, :second_id => 2, :name => 'ab'},
|
|
364
|
+
{:first_id => 2, :second_id => 1, :name => 'ba'},
|
|
365
|
+
{:first_id => 3, :second_id => 1}
|
|
366
|
+
].each { |row| create_row connection, 'extender_combined_key', row}
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
# Reinitializes the sample schema with the sample data
|
|
370
|
+
def create_sample_data
|
|
371
|
+
# Create records existing in both databases
|
|
372
|
+
[:left, :right].each do |database|
|
|
373
|
+
delete_all_and_create_shared_sample_data RR::Initializer.configuration.send(database)
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
# Create data in left table
|
|
377
|
+
ActiveRecord::Base.establish_connection RR::Initializer.configuration.left
|
|
378
|
+
ScannerRecords.create_with_key :id => 2, :name => 'Bob - left database version'
|
|
379
|
+
ScannerRecords.create_with_key :id => 3, :name => 'Charlie - exists in left database only'
|
|
380
|
+
ScannerRecords.create_with_key :id => 5, :name => 'Eve - exists in left database only'
|
|
381
|
+
|
|
382
|
+
ScannerLeftRecordsOnly.delete_all
|
|
383
|
+
ScannerLeftRecordsOnly.create_with_key :id => 1, :name => 'Alice'
|
|
384
|
+
ScannerLeftRecordsOnly.create_with_key :id => 2, :name => 'Bob'
|
|
385
|
+
|
|
386
|
+
# Create data in right table
|
|
387
|
+
ActiveRecord::Base.establish_connection RR::Initializer.configuration.right
|
|
388
|
+
ScannerRecords.create_with_key :id => 2, :name => 'Bob - right database version'
|
|
389
|
+
ScannerRecords.create_with_key :id => 4, :name => 'Dave - exists in right database only'
|
|
390
|
+
ScannerRecords.create_with_key :id => 6, :name => 'Fred - exists in right database only'
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
namespace :db do
|
|
394
|
+
namespace :test do
|
|
395
|
+
|
|
396
|
+
desc "Creates the test databases"
|
|
397
|
+
task :create do
|
|
398
|
+
create_database RR::Initializer.configuration.left rescue nil
|
|
399
|
+
create_database RR::Initializer.configuration.right rescue nil
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
desc "Drops the test databases"
|
|
403
|
+
task :drop do
|
|
404
|
+
drop_database RR::Initializer.configuration.left rescue nil
|
|
405
|
+
drop_database RR::Initializer.configuration.right rescue nil
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
desc "Rebuilds the test databases & schemas"
|
|
409
|
+
task :rebuild => [:drop_schema, :drop, :create, :create_schema, :populate]
|
|
410
|
+
|
|
411
|
+
desc "Create the sample schemas"
|
|
412
|
+
task :create_schema do
|
|
413
|
+
create_sample_schema RR::Initializer.configuration.left rescue nil
|
|
414
|
+
create_sample_schema RR::Initializer.configuration.right rescue nil
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
desc "Writes the sample data"
|
|
418
|
+
task :populate do
|
|
419
|
+
create_sample_data
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
desc "Drops the sample schemas"
|
|
423
|
+
task :drop_schema do
|
|
424
|
+
# Since Rails 2.2 ActiveRecord doesn't release the database connection
|
|
425
|
+
# anymore. Thus the dropping of the database fails.
|
|
426
|
+
# Workaround:
|
|
427
|
+
# Execute the schema removal in a sub process. Once the sub process
|
|
428
|
+
# exits, it's database connections die.
|
|
429
|
+
pid = Process.fork
|
|
430
|
+
if pid
|
|
431
|
+
Process.wait pid
|
|
432
|
+
else
|
|
433
|
+
drop_sample_schema RR::Initializer.configuration.left rescue nil
|
|
434
|
+
drop_sample_schema RR::Initializer.configuration.right rescue nil
|
|
435
|
+
Kernel.exit!
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
end
|
|
439
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
desc 'Release the website and new gem version'
|
|
2
|
+
task :deploy => [:check_version, :website, :release] do
|
|
3
|
+
puts "Remember to create SVN tag:"
|
|
4
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
|
5
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
|
6
|
+
puts "Suggested comment:"
|
|
7
|
+
puts "Tagging release #{CHANGES}"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
namespace :deploy do
|
|
11
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
|
12
|
+
task :local => [:website_generate, :install_gem]
|
|
13
|
+
|
|
14
|
+
task :check_version do
|
|
15
|
+
unless ENV['VERSION']
|
|
16
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
|
17
|
+
exit
|
|
18
|
+
end
|
|
19
|
+
unless ENV['VERSION'] == VERS
|
|
20
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
|
21
|
+
exit
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
|
26
|
+
task :install_gem_no_doc => [:clean, :package] do
|
|
27
|
+
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
|
28
|
+
end
|
|
29
|
+
end
|
data/tasks/java.rake
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
namespace :deploy do
|
|
2
|
+
|
|
3
|
+
BASH_FILE_CONTENT = <<'EOS'
|
|
4
|
+
#!/bin/bash
|
|
5
|
+
|
|
6
|
+
script_dir="`dirname \"$0\"`"
|
|
7
|
+
|
|
8
|
+
jruby_path="$script_dir"/jruby/bin/jruby
|
|
9
|
+
rubyrep_path="$script_dir"/bin/rubyrep
|
|
10
|
+
|
|
11
|
+
$jruby_path --server $rubyrep_path $*
|
|
12
|
+
EOS
|
|
13
|
+
|
|
14
|
+
BAT_FILE_CONTENT = <<'EOS'.gsub(/^(.*)$/,"\\1\r")
|
|
15
|
+
@echo off
|
|
16
|
+
set jruby_path=%~dp0jruby\bin\jruby.bat
|
|
17
|
+
set rubyrep_path=%~dp0bin\rubyrep
|
|
18
|
+
%jruby_path% --server %rubyrep_path% %1 %2 %3 %4 %5 %6 %7 %8 %9
|
|
19
|
+
EOS
|
|
20
|
+
|
|
21
|
+
desc "Create the java installation package"
|
|
22
|
+
task :java do
|
|
23
|
+
pkg_name = "rubyrep-#{RR::VERSION::STRING}"
|
|
24
|
+
|
|
25
|
+
system "rm -rf /tmp/#{pkg_name}"
|
|
26
|
+
system "hg archive /tmp/#{pkg_name}"
|
|
27
|
+
system "mkdir -p /tmp/#{pkg_name}/jruby"
|
|
28
|
+
system "cp -r #{JRUBY_HOME}/* /tmp/#{pkg_name}/jruby/"
|
|
29
|
+
system "cd /tmp/#{pkg_name}/jruby; rm -rf samples share/ri lib/ruby/gems/1.8/doc"
|
|
30
|
+
File.open("/tmp/#{pkg_name}/rubyrep.bat", 'w') {|f| f.write(BAT_FILE_CONTENT)}
|
|
31
|
+
File.open("/tmp/#{pkg_name}/rubyrep", 'w') {|f| f.write(BASH_FILE_CONTENT)}
|
|
32
|
+
system "chmod a+x /tmp/#{pkg_name}/rubyrep"
|
|
33
|
+
system "cd /tmp; rm -f #{pkg_name}.zip; zip -r #{pkg_name}.zip #{pkg_name} >/dev/null"
|
|
34
|
+
system "mkdir -p pkg"
|
|
35
|
+
system "cp /tmp/#{pkg_name}.zip pkg"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
def install_redmine(database, name = nil)
|
|
3
|
+
unless name
|
|
4
|
+
install_redmine database, 'leftmine'
|
|
5
|
+
install_redmine database, 'rightmine'
|
|
6
|
+
else
|
|
7
|
+
database = database.to_s
|
|
8
|
+
database.sub!(/^postgres$/, 'postgresql')
|
|
9
|
+
|
|
10
|
+
FileUtils.cd(File.expand_path("~"))
|
|
11
|
+
unless File.exists?(name)
|
|
12
|
+
system "svn checkout -r 2145 http://redmine.rubyforge.org/svn/trunk #{name}"
|
|
13
|
+
end
|
|
14
|
+
FileUtils.cd name
|
|
15
|
+
ENV['RAILS_ENV'] = 'production'
|
|
16
|
+
config = File.read('config/database.yml.example')
|
|
17
|
+
config.gsub! 'redmine', name
|
|
18
|
+
config.gsub! 'mysql', database
|
|
19
|
+
if database == 'postgresql'
|
|
20
|
+
config.gsub! 'root', 'postgres'
|
|
21
|
+
end
|
|
22
|
+
File.open('config/database.yml', 'w') { |f| f.write config }
|
|
23
|
+
system 'rake db:drop'
|
|
24
|
+
system 'rake db:create'
|
|
25
|
+
system 'rake db:migrate'
|
|
26
|
+
system 'echo |rake redmine:load_default_data'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
desc "Deploys two Redmine test installations"
|
|
31
|
+
namespace :deploy do
|
|
32
|
+
task :redmine do
|
|
33
|
+
|
|
34
|
+
database = ENV['RR_TEST_DB'] ? ENV['RR_TEST_DB'] : :postgres
|
|
35
|
+
install_redmine database
|
|
36
|
+
|
|
37
|
+
puts(<<EOS)
|
|
38
|
+
# Setup finished
|
|
39
|
+
# Start the redmine instances on ports 3000 and 3001 respectively
|
|
40
|
+
# with the following commands:
|
|
41
|
+
(cd ~/leftmine; ruby ./script/server -p 3000 -e production)
|
|
42
|
+
(cd ~/rightmine; ruby ./script/server -p 3001 -e production)
|
|
43
|
+
# Start the replication with
|
|
44
|
+
ruby ./bin/rubyrep replicate -c ./config/redmine_config.rb
|
|
45
|
+
EOS
|
|
46
|
+
end
|
|
47
|
+
end
|
data/tasks/rspec.rake
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'spec'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
require 'rubygems'
|
|
5
|
+
require 'spec'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'spec/rake/spectask'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
puts <<-EOS
|
|
11
|
+
To use rspec for testing you must install rspec gem:
|
|
12
|
+
gem install rspec
|
|
13
|
+
EOS
|
|
14
|
+
exit(0)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "Run the specs under spec/models"
|
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
|
20
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
namespace :spec do
|
|
24
|
+
desc "Generate specdocs for examples for inclusion in RDoc"
|
|
25
|
+
Spec::Rake::SpecTask.new('docs') do |t|
|
|
26
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
|
27
|
+
t.spec_opts = ["--format", "specdoc"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
desc "Run the specs with RCov"
|
|
31
|
+
Spec::Rake::SpecTask.new('rcov') do |t|
|
|
32
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
|
33
|
+
t.spec_files = FileList['spec/*_spec.rb']
|
|
34
|
+
t.rcov = true
|
|
35
|
+
t.rcov_opts = [
|
|
36
|
+
'--exclude', 'tasks/,spec/,gems/\(?!rubyrep\)',
|
|
37
|
+
'--xrefs'
|
|
38
|
+
]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
desc "Run the specs for all supported databases"
|
|
42
|
+
task :all_dbs do
|
|
43
|
+
[:postgres, :mysql].each do |test_db|
|
|
44
|
+
puts "Running specs for #{test_db.id2name}"
|
|
45
|
+
ENV['RR_TEST_DB'] = test_db.id2name
|
|
46
|
+
system "spec spec"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
desc "Run the specs for all supported databases and ruby platforms"
|
|
51
|
+
task :all_rubies do
|
|
52
|
+
puts "Running spec:all_dbs in standard ruby"
|
|
53
|
+
system "rake spec:all_dbs"
|
|
54
|
+
puts "Running spec:all_dbs in jruby"
|
|
55
|
+
system "export PATH=#{JRUBY_HOME}/bin:$PATH; rake spec:all_dbs"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
begin
|
|
59
|
+
require 'ruby-prof/task'
|
|
60
|
+
RubyProf::ProfileTask.new do |t|
|
|
61
|
+
t.test_files = FileList['spec/*_spec.rb']
|
|
62
|
+
t.output_dir = 'profile'
|
|
63
|
+
t.printer = :flat
|
|
64
|
+
t.min_percent = 1
|
|
65
|
+
end
|
|
66
|
+
rescue LoadError
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[DEFAULT]
|
|
2
|
+
verbose = True
|
|
3
|
+
|
|
4
|
+
[project]
|
|
5
|
+
target = svn:target
|
|
6
|
+
start-revision = 1
|
|
7
|
+
root-directory = /tmp/rubyrep_tailor
|
|
8
|
+
state-file = tailor.state
|
|
9
|
+
source = hg:source
|
|
10
|
+
|
|
11
|
+
[hg:source]
|
|
12
|
+
repository = .
|
|
13
|
+
subdir = hg
|
|
14
|
+
|
|
15
|
+
[svn:target]
|
|
16
|
+
repository = file:///tmp/rubyrep_tailor/svn_repository
|
|
17
|
+
module = rubyrep
|
|
18
|
+
subdir = svn
|
data/tasks/stats.rake
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'code_statistics' # This library is coming with the rails gem
|
|
3
|
+
desc "Report code statistics (KLOCs, etc)"
|
|
4
|
+
task :stats do
|
|
5
|
+
STATS_DIRECTORIES = [
|
|
6
|
+
%w(Libraries lib/),
|
|
7
|
+
%w(Unit\ tests spec/),
|
|
8
|
+
%w(Integration\ tests sims/)
|
|
9
|
+
].collect { |name, dir| [ name, "#{File.dirname(__FILE__)}/../#{dir}" ] }.select { |name, dir| File.directory?(dir) }
|
|
10
|
+
|
|
11
|
+
desc "Report code statistics (KLOCs, etc) from the application"
|
|
12
|
+
task :stats do
|
|
13
|
+
require 'code_statistics'
|
|
14
|
+
CodeStatistics.new(*STATS_DIRECTORIES).to_s
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
rescue LoadError
|
|
19
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# The standard ActiveRecord#create method ignores primary key attributes.
|
|
2
|
+
# This module provides a create method that allows manual setting of primary key values.
|
|
3
|
+
module CreateWithKey
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.extend(ClassMethods)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module ClassMethods
|
|
9
|
+
# The standard "create" method ignores primary key attributes
|
|
10
|
+
# This method set's _all_ attributes as provided
|
|
11
|
+
def create_with_key attributes
|
|
12
|
+
o = new
|
|
13
|
+
attributes.each do |key, value|
|
|
14
|
+
o[key] = value
|
|
15
|
+
end
|
|
16
|
+
o.save
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
data.tar.gz.sig
ADDED
|
Binary file
|