myreplicator 1.1.31 → 1.1.32
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.
|
@@ -15,9 +15,16 @@ class CreateMyreplicatorExports < ActiveRecord::Migration
|
|
|
15
15
|
t.text :error
|
|
16
16
|
t.boolean :active, :default => true
|
|
17
17
|
t.integer :exporter_pid
|
|
18
|
+
t.integer :transporter_pid
|
|
19
|
+
t.integer :loader_pid
|
|
18
20
|
t.datetime :export_started_at, :default => nil
|
|
19
21
|
t.datetime :export_finished_at, :default => nil
|
|
22
|
+
t.datetime :load_started_at, :default => nil
|
|
23
|
+
t.datetime :load_finished_at, :default => nil
|
|
24
|
+
t.datetime :transfer_started_at, :default => nil
|
|
25
|
+
t.datetime :transfer_finished_at, :default => nil
|
|
20
26
|
t.timestamps
|
|
27
|
+
t.boolean :analyze_constraints, :default => false
|
|
21
28
|
end
|
|
22
29
|
add_index :myreplicator_exports, [:source_schema, :destination_schema, :table_name], :unique => true, :name => "unique_index"
|
|
23
30
|
end
|
|
@@ -151,22 +151,21 @@ module Myreplicator
|
|
|
151
151
|
Loader.cleanup metadata #Remove incremental file
|
|
152
152
|
Kernel.p "===== Remove incremental file ====="
|
|
153
153
|
end
|
|
154
|
+
elsif get_analyze_constraints(ops) > 0 # check for primary key/unique keys violations
|
|
155
|
+
exp = Export.find(metadata.export_id)
|
|
156
|
+
Loader.clear_older_files metadata
|
|
157
|
+
Loader.cleanup metadata
|
|
158
|
+
Kernel.p "===== DROP CURRENT TABLE ====="
|
|
159
|
+
sql = "DROP TABLE IF EXISTS #{options[:db]}.#{options[:destination_schema]}.#{options[:table]} CASCADE;"
|
|
160
|
+
# run the export. The next time loader runs, it will load the file
|
|
161
|
+
exp.export
|
|
154
162
|
else
|
|
155
163
|
temp_table = create_temp_table ops
|
|
156
164
|
options[:table] = temp_table
|
|
157
165
|
Kernel.p "===== COPY TO TEMP TABLE #{temp_table} ====="
|
|
158
166
|
vertica_copy options
|
|
159
167
|
exp = Export.find(metadata.export_id)
|
|
160
|
-
if exp.export_type == '
|
|
161
|
-
options.reverse_merge!(:temp_table => "#{temp_table}")
|
|
162
|
-
options[:table] = options[:table_name]
|
|
163
|
-
Kernel.p "===== MERGE ====="
|
|
164
|
-
vertica_merge options
|
|
165
|
-
#drop the temp table
|
|
166
|
-
Kernel.p "===== DROP TEMP TABLE ====="
|
|
167
|
-
sql = "DROP TABLE IF EXISTS #{options[:db]}.#{options[:destination_schema]}.#{temp_table} CASCADE;"
|
|
168
|
-
Myreplicator::DB.exec_sql("vertica",sql)
|
|
169
|
-
elsif exp.export_type == 'all'
|
|
168
|
+
if exp.export_type == 'all'
|
|
170
169
|
options.reverse_merge!(:temp_table => "#{temp_table}")
|
|
171
170
|
options[:table] = options[:table_name]
|
|
172
171
|
Kernel.p "===== DROP CURRENT TABLE ====="
|
|
@@ -175,6 +174,15 @@ module Myreplicator
|
|
|
175
174
|
sql = "ALTER TABLE #{options[:db]}.#{options[:destination_schema]}.#{options[:temp_table]} RENAME TO \"#{options[:table]}\";"
|
|
176
175
|
Kernel.p sql
|
|
177
176
|
Myreplicator::DB.exec_sql("vertica",sql)
|
|
177
|
+
elsif exp.export_type == 'incremental'
|
|
178
|
+
options.reverse_merge!(:temp_table => "#{temp_table}")
|
|
179
|
+
options[:table] = options[:table_name]
|
|
180
|
+
Kernel.p "===== MERGE ====="
|
|
181
|
+
vertica_merge options
|
|
182
|
+
#drop the temp table
|
|
183
|
+
Kernel.p "===== DROP TEMP TABLE ====="
|
|
184
|
+
sql = "DROP TABLE IF EXISTS #{options[:db]}.#{options[:destination_schema]}.#{temp_table} CASCADE;"
|
|
185
|
+
Myreplicator::DB.exec_sql("vertica",sql)
|
|
178
186
|
end
|
|
179
187
|
end
|
|
180
188
|
end
|
|
@@ -270,7 +278,7 @@ module Myreplicator
|
|
|
270
278
|
def get_mysql_keys mysql_schema_simple_form
|
|
271
279
|
result = []
|
|
272
280
|
mysql_schema_simple_form.each do |col|
|
|
273
|
-
if col["column_key"] == "PRI"
|
|
281
|
+
if col["column_key"] == "PRI" || col["column_key"] == "UNI"
|
|
274
282
|
result << col["column_name"]
|
|
275
283
|
end
|
|
276
284
|
end
|
|
@@ -280,7 +288,7 @@ module Myreplicator
|
|
|
280
288
|
def get_mysql_none_keys mysql_schema_simple_form
|
|
281
289
|
result = []
|
|
282
290
|
mysql_schema_simple_form.each do |col|
|
|
283
|
-
if col["column_key"]
|
|
291
|
+
if col["column_key"] != "PRI" && col["column_key"] != "UNI"
|
|
284
292
|
result << col["column_name"]
|
|
285
293
|
end
|
|
286
294
|
end
|
|
@@ -413,6 +421,20 @@ module Myreplicator
|
|
|
413
421
|
end
|
|
414
422
|
end
|
|
415
423
|
end
|
|
424
|
+
|
|
425
|
+
def get_analyze_constraints *args
|
|
426
|
+
options = args.extract_options!
|
|
427
|
+
exp = Export.find(options[:export_id])
|
|
428
|
+
begin
|
|
429
|
+
if exp.analyze_constraints == 1
|
|
430
|
+
sql = "SELECT analyze_constraints('#{options[:vertica_db]}.#{options[:vertica_schema]}.#{options[:table]}');"
|
|
431
|
+
result = Myreplicator::DB.exec_sql("vertica",sql)
|
|
432
|
+
return result.entries.size
|
|
433
|
+
end
|
|
434
|
+
rescue Exception => e
|
|
435
|
+
puts e.message
|
|
436
|
+
end
|
|
437
|
+
end
|
|
416
438
|
=begin
|
|
417
439
|
def create_all_tables db
|
|
418
440
|
tables = Myreplicator::DB.get_tables(db)
|
|
@@ -7,7 +7,7 @@ module Myreplicator
|
|
|
7
7
|
sql += "#{options[:table]} ("
|
|
8
8
|
|
|
9
9
|
index = 1
|
|
10
|
-
primary_set = false
|
|
10
|
+
#primary_set = false
|
|
11
11
|
|
|
12
12
|
options[:columns].each do |column|
|
|
13
13
|
sql += "\"#{column['column_name']}\" "
|
|
@@ -15,22 +15,40 @@ module Myreplicator
|
|
|
15
15
|
sql += data_type(column['data_type'], column['column_type'])
|
|
16
16
|
sql += " "
|
|
17
17
|
|
|
18
|
-
if column['column_key'] == "PRI"
|
|
19
|
-
sql += key(column['column_key']) + " " unless primary_set # set only one primary key
|
|
20
|
-
primary_set = true
|
|
21
|
-
end
|
|
22
|
-
|
|
23
18
|
sql += nullable(column['is_nullable'])
|
|
24
19
|
sql += " "
|
|
25
20
|
|
|
26
21
|
if index < options[:columns].size
|
|
27
22
|
sql += ", "
|
|
28
|
-
else
|
|
29
|
-
sql += ");"
|
|
30
23
|
end
|
|
31
24
|
index += 1
|
|
32
25
|
end
|
|
33
|
-
|
|
26
|
+
|
|
27
|
+
# Add primary key
|
|
28
|
+
primary_set = false
|
|
29
|
+
options[:columns].each do |column|
|
|
30
|
+
if column['column_key'] == "PRI"
|
|
31
|
+
if !primary_set
|
|
32
|
+
sql += ", PRIMARY KEY (" + "\"#{column['column_name']}\" "
|
|
33
|
+
else
|
|
34
|
+
sql += ", " + "\"#{column['column_name']}\" "
|
|
35
|
+
end
|
|
36
|
+
primary_set = true
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
if primary_set
|
|
40
|
+
sql += ") "
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Add unique key
|
|
44
|
+
options[:columns].each do |column|
|
|
45
|
+
if column['column_key'] == "UNI"
|
|
46
|
+
sql += ", UNIQUE (" + "\"#{column['column_name']}\" "
|
|
47
|
+
sql += ") "
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
sql += ");"
|
|
34
52
|
puts sql
|
|
35
53
|
|
|
36
54
|
return sql
|
|
@@ -46,13 +64,13 @@ module Myreplicator
|
|
|
46
64
|
end
|
|
47
65
|
|
|
48
66
|
def self.data_type type, col_type
|
|
49
|
-
type = VerticaTypes.convert type, col_type
|
|
67
|
+
type = Myreplicator::VerticaTypes.convert type, col_type
|
|
50
68
|
result = " #{type} "
|
|
51
69
|
return result
|
|
52
70
|
end
|
|
53
71
|
|
|
54
72
|
def self.key col_key
|
|
55
|
-
col_key = VerticaTypes.convert_key col_key
|
|
73
|
+
col_key = Myreplicator::VerticaTypes.convert_key col_key
|
|
56
74
|
return "#{col_key} "
|
|
57
75
|
end
|
|
58
76
|
end
|
data/lib/myreplicator/version.rb
CHANGED
|
@@ -8868,3 +8868,5 @@ Connecting to database specified by database.yml
|
|
|
8868
8868
|
Connecting to database specified by database.yml
|
|
8869
8869
|
Connecting to database specified by database.yml
|
|
8870
8870
|
Connecting to database specified by database.yml
|
|
8871
|
+
Connecting to database specified by database.yml
|
|
8872
|
+
Connecting to database specified by database.yml
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: myreplicator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.32
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-04-
|
|
12
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
@@ -359,7 +359,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
359
359
|
version: '0'
|
|
360
360
|
segments:
|
|
361
361
|
- 0
|
|
362
|
-
hash:
|
|
362
|
+
hash: -984056559556813446
|
|
363
363
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
364
364
|
none: false
|
|
365
365
|
requirements:
|
|
@@ -368,7 +368,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
368
368
|
version: '0'
|
|
369
369
|
segments:
|
|
370
370
|
- 0
|
|
371
|
-
hash:
|
|
371
|
+
hash: -984056559556813446
|
|
372
372
|
requirements: []
|
|
373
373
|
rubyforge_project:
|
|
374
374
|
rubygems_version: 1.8.24
|