myreplicator 1.1.52 → 1.1.53

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.
@@ -122,7 +122,9 @@ module Myreplicator
122
122
  :table => @export_obj.table_name,
123
123
  :filepath => filepath,
124
124
  :destination_schema => @export_obj.destination_schema,
125
- :enclosed_by => Myreplicator.configs[@export_obj.source_schema]["enclosed_by"]}
125
+ :enclosed_by => Myreplicator.configs[@export_obj.source_schema]["enclosed_by"],
126
+ :export_id => @export_obj.id
127
+ }
126
128
 
127
129
  schema_status = Myreplicator::MysqlExporter.schema_changed?(options)
128
130
  Kernel.p "===== schema_status ====="
@@ -132,14 +134,16 @@ module Myreplicator
132
134
  else
133
135
  options[:incremental_col] = @export_obj.incremental_column
134
136
  options[:incremental_col_type] = @export_obj.incremental_column_type
135
- #options[:incremental_val] = @export_obj.max_incremental_value
136
137
  options[:export_type] = @export_obj.export_type
137
138
  options[:incremental_val] = [@export_obj.destination_max_incremental_value, @export_obj.max_incremental_value].min
139
+ #options[:incremental_val] = @export_obj.max_incremental_value
138
140
  end
139
141
 
140
142
  #Kernel.p "===== incremental_export_into_outfile OPTIONS ====="
141
143
  #Kernel.p options
142
- cmd = SqlCommands.mysql_export_outfile(options)
144
+ cmd = SqlCommands.mysql_export_outfile(options)
145
+ #Kernel.p "===== incremental_export_into_outfile CMD ====="
146
+ #puts cmd
143
147
  exporting_state_trans
144
148
  puts "Exporting..."
145
149
  result = execute_export(cmd, metadata)
@@ -112,16 +112,64 @@ module Myreplicator
112
112
  puts cmd
113
113
  return cmd
114
114
  end
115
+
116
+ ##
117
+ # exp:
118
+ # SELECT
119
+ # customer_id,firstname,REPLACE(UPPER(`lastname`), 'NULL', 'ABC'),email,..,REPLACE(`modified_date`, '0000-00-00','1900-01-01'),..
120
+ # FROM king.customer WHERE customer_id in ( 261085,348081,477336 );
121
+ ##
122
+
123
+ def self.get_columns * args
124
+ options = args.extract_options!
125
+ #Kernel.p "===== GET COLUMNS OPTIONS ====="
126
+ #Kernel.p options
127
+ #
128
+ exp = Myreplicator::Export.find(options[:export_id])
129
+ #
130
+ mysql_schema = Myreplicator::Loader.mysql_table_definition(options)
131
+ mysql_schema_simple_form = Myreplicator::MysqlExporter.get_mysql_schema_rows mysql_schema
132
+ columns = Myreplicator::VerticaLoader.get_mysql_inserted_columns mysql_schema_simple_form
133
+ #Kernel.p "===== table's columns====="
134
+ #Kernel.p columns
135
+
136
+ json = JSON.parse(exp.removing_special_chars)
137
+ #Kernel.p exp.removing_special_chars
138
+ #Kernel.p json
139
+ result = []
140
+ columns.each do |column|
141
+ if !json[column].blank?
142
+ puts json[column]
143
+ replaces = json[column]
144
+ sql = ""
145
+ replaces.each do |k,v|
146
+ if sql.blank?
147
+ sql = "REPLACE(#{column}, '#{k}', '#{v}')"
148
+ else
149
+ sql = "REPLACE(#{sql}, '#{k}', '#{v}')"
150
+ end
151
+ #puts sql
152
+ end
153
+ result << sql
154
+ else
155
+ result << column
156
+ end
157
+ end
158
+ return result
159
+ end
115
160
 
116
161
  ##
117
162
  # Mysql export data into outfile option
118
163
  # Provided for tables that need special delimiters
119
164
  ##
120
165
 
121
- def self.get_outfile_sql options
122
- Kernel.p "===== SELECT * INTO OUTFILE OPTIONS====="
123
- Kernel.p options
124
- sql = "SELECT * INTO OUTFILE '#{options[:filepath]}' "
166
+ def self.get_outfile_sql *args
167
+ options = args.extract_options!
168
+ #Kernel.p "===== SELECT * INTO OUTFILE OPTIONS====="
169
+ #Kernel.p options
170
+ columns = get_columns options
171
+ sql = "SELECT #{columns.join(',')} INTO OUTFILE '#{options[:filepath]}' "
172
+ #sql = "SELECT * INTO OUTFILE '#{options[:filepath]}' "
125
173
 
126
174
  if options[:enclosed_by].blank?
127
175
  sql += " FIELDS TERMINATED BY '\\0' ESCAPED BY '' LINES TERMINATED BY ';~~;\n'"
@@ -155,17 +203,17 @@ module Myreplicator
155
203
  # Location of the output file needs to have 777 perms
156
204
  ##
157
205
  def self.mysql_export_outfile *args
158
- #Kernel.p "===== mysql_export_outfile OPTIONS ====="
159
-
206
+ Kernel.p "===== mysql_export_outfile OPTIONS ====="
207
+
160
208
  options = args.extract_options!
161
- #Kernel.p options
209
+ Kernel.p options
162
210
  options.reverse_merge! :flags => []
163
211
  db = options[:source_schema]
164
212
 
165
213
  # Database host when ssh'ed into the db server
166
214
  db_host = "127.0.0.1"
167
- #Kernel.p "===== mysql_export_outfile ssh_configs ====="
168
- #Kernel.p ssh_configs(db)
215
+ Kernel.p "===== mysql_export_outfile ssh_configs ====="
216
+ Kernel.p ssh_configs(db)
169
217
  if !ssh_configs(db)["ssh_db_host"].blank?
170
218
  db_host = ssh_configs(db)["ssh_db_host"]
171
219
  elsif !db_configs(db)["host"].blank?
@@ -382,7 +382,7 @@ module Myreplicator
382
382
 
383
383
  puts sql
384
384
 
385
- desc = DB.exec_sql(options[:source_schema], sql)
385
+ desc = Myreplicator::DB.exec_sql(options[:source_schema], sql)
386
386
  puts desc
387
387
  return desc
388
388
  end
@@ -1,3 +1,3 @@
1
1
  module Myreplicator
2
- VERSION = "1.1.52"
2
+ VERSION = "1.1.53"
3
3
  end
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.52
4
+ version: 1.1.53
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-07-15 00:00:00.000000000 Z
12
+ date: 2013-07-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -354,7 +354,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
354
354
  version: '0'
355
355
  segments:
356
356
  - 0
357
- hash: -3879134053226116075
357
+ hash: 2486983726368324823
358
358
  required_rubygems_version: !ruby/object:Gem::Requirement
359
359
  none: false
360
360
  requirements:
@@ -363,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
363
363
  version: '0'
364
364
  segments:
365
365
  - 0
366
- hash: -3879134053226116075
366
+ hash: 2486983726368324823
367
367
  requirements: []
368
368
  rubyforge_project:
369
369
  rubygems_version: 1.8.24