myreplicator 1.1.46 → 1.1.47
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/app/models/myreplicator/export.rb +26 -26
- data/lib/exporter/sql_commands.rb +18 -1
- data/lib/myreplicator/version.rb +1 -1
- metadata +4 -4
@@ -86,38 +86,42 @@ module Myreplicator
|
|
86
86
|
@file_name ||= "#{source_schema}_#{table_name}_#{Time.now.to_i}.tsv"
|
87
87
|
end
|
88
88
|
|
89
|
-
def destination_max_incremental_value
|
90
|
-
sql = SqlCommands.max_value_sql(:incremental_col => self.incremental_column,
|
91
|
-
:max_incremental_value => self.max_incremental_value,
|
92
|
-
:db => self.destination_schema,
|
93
|
-
:table => self.table_name)
|
94
|
-
puts sql
|
89
|
+
def destination_max_incremental_value
|
95
90
|
if self.export_to == 'vertica'
|
91
|
+
sql = SqlCommands.max_value_vsql(:incremental_col => self.incremental_column,
|
92
|
+
:max_incremental_value => self.max_incremental_value,
|
93
|
+
:db => self.destination_schema,
|
94
|
+
:incremental_col_type => self.incremental_column_type,
|
95
|
+
:table => self.table_name)
|
96
|
+
puts sql
|
96
97
|
begin
|
97
98
|
result = Myreplicator::DB.exec_sql('vertica',sql)
|
98
|
-
if result.rows.first[:
|
99
|
+
if result.rows.first[:max].blank?
|
99
100
|
return "0"
|
100
101
|
else
|
101
|
-
case result.rows.first[:
|
102
|
+
case result.rows.first[:max].class.to_s
|
102
103
|
when "DateTime"
|
103
|
-
return result.rows.first[:
|
104
|
+
return result.rows.first[:max].strftime('%Y-%m-%d %H:%M:%S')
|
104
105
|
else
|
105
|
-
return result.rows.first[:
|
106
|
+
return result.rows.first[:max].to_s
|
106
107
|
end
|
107
108
|
end
|
108
109
|
rescue Exception => e
|
109
110
|
puts "Vertica Table Not Existed"
|
110
111
|
end
|
111
112
|
else
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
113
|
+
begin
|
114
|
+
sql = SqlCommands.max_value_sql(:incremental_col => self.incremental_column,
|
115
|
+
:max_incremental_value => self.max_incremental_value,
|
116
|
+
:db => self.source_schema,
|
117
|
+
:incremental_col_type => self.incremental_column_type,
|
118
|
+
:table => self.table_name)
|
119
|
+
puts sql
|
120
|
+
result = Myreplicator::DB.exec_sql(self.destination_schema,sql)
|
121
|
+
if result.first.nil?
|
122
|
+
return "0"
|
119
123
|
else
|
120
|
-
return result.first.first
|
124
|
+
return result.first.first
|
121
125
|
end
|
122
126
|
end
|
123
127
|
end
|
@@ -128,17 +132,12 @@ module Myreplicator
|
|
128
132
|
sql = SqlCommands.max_value_sql(:incremental_col => self.incremental_column,
|
129
133
|
:max_incremental_value => self.max_incremental_value,
|
130
134
|
:db => self.source_schema,
|
135
|
+
:incremental_col_type => self.incremental_column_type,
|
131
136
|
:table => self.table_name)
|
132
137
|
result = exec_on_source(sql)
|
133
138
|
if result.first.nil?
|
134
|
-
return ""
|
139
|
+
return "0"
|
135
140
|
else
|
136
|
-
#case result.first.first.class.to_s
|
137
|
-
#when "Symbol", "Fixnum"
|
138
|
-
# return result.first.first.to_s
|
139
|
-
#else
|
140
|
-
# return result.first.first.to_s(:db)
|
141
|
-
#end
|
142
141
|
return result.first.first
|
143
142
|
end
|
144
143
|
end
|
@@ -172,7 +171,8 @@ module Myreplicator
|
|
172
171
|
##
|
173
172
|
def connection_factory type
|
174
173
|
config = Myreplicator.configs[self.source_schema]
|
175
|
-
|
174
|
+
puts self.source_schema
|
175
|
+
puts config
|
176
176
|
case type
|
177
177
|
when :ssh
|
178
178
|
if config.has_key? "ssh_password"
|
@@ -237,6 +237,10 @@ module Myreplicator
|
|
237
237
|
sql = ""
|
238
238
|
|
239
239
|
if options[:incremental_col]
|
240
|
+
|
241
|
+
if options[:incremental_col_type] == "datetime" && options[:max_incremental_value] == '0'
|
242
|
+
options[:max_incremental_value] = "1900-01-01 00:00:00"
|
243
|
+
end
|
240
244
|
sql = "SELECT COALESCE(max(#{options[:incremental_col]}),'#{options[:max_incremental_value]}') FROM #{options[:db]}.#{options[:table]}"
|
241
245
|
else
|
242
246
|
raise Myreplicator::Exceptions::MissingArgs.new("Missing Incremental Column Parameter")
|
@@ -244,6 +248,19 @@ module Myreplicator
|
|
244
248
|
|
245
249
|
return sql
|
246
250
|
end
|
247
|
-
|
251
|
+
|
252
|
+
def self.max_value_vsql *args
|
253
|
+
options = args.extract_options!
|
254
|
+
sql = ""
|
255
|
+
|
256
|
+
if options[:incremental_col]
|
257
|
+
sql = "SELECT max(#{options[:incremental_col]}) FROM #{options[:db]}.#{options[:table]}"
|
258
|
+
else
|
259
|
+
raise Myreplicator::Exceptions::MissingArgs.new("Missing Incremental Column Parameter")
|
260
|
+
end
|
261
|
+
|
262
|
+
return sql
|
263
|
+
end
|
264
|
+
|
248
265
|
end
|
249
266
|
end
|
data/lib/myreplicator/version.rb
CHANGED
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.47
|
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-06-
|
12
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -352,7 +352,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
352
352
|
version: '0'
|
353
353
|
segments:
|
354
354
|
- 0
|
355
|
-
hash:
|
355
|
+
hash: 3374412953550352773
|
356
356
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
357
357
|
none: false
|
358
358
|
requirements:
|
@@ -361,7 +361,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
361
361
|
version: '0'
|
362
362
|
segments:
|
363
363
|
- 0
|
364
|
-
hash:
|
364
|
+
hash: 3374412953550352773
|
365
365
|
requirements: []
|
366
366
|
rubyforge_project:
|
367
367
|
rubygems_version: 1.8.24
|