forklift_etl 1.1.9 → 1.1.10
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/Gemfile.lock +1 -1
- data/lib/forklift/patterns/mysql_patterns.rb +13 -7
- data/lib/forklift/plan.rb +1 -0
- data/lib/forklift/transports/mysql.rb +16 -1
- data/lib/forklift/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
@@ -107,21 +107,27 @@ module Forklift
|
|
107
107
|
# The high water method will stub a row in all tables with a `default_matcher` column prentending to have a record from `time`
|
108
108
|
# This enabled partial forklift funs which will only extract data "later than X"
|
109
109
|
# TODO: assumes all columns have a default NULL setting
|
110
|
-
def self.write_high_water_mark(db, time, matcher=
|
110
|
+
def self.write_high_water_mark(db, time, matcher=db.default_matcher)
|
111
111
|
db.tables.each do |table|
|
112
|
-
columns, types = db.columns(table,
|
112
|
+
columns, types = db.columns(table, db.current_database, true)
|
113
113
|
if columns.include?(matcher)
|
114
114
|
row = {}
|
115
115
|
i = 0
|
116
116
|
while( i < columns.length )
|
117
117
|
if(columns[i] == matcher)
|
118
|
-
row[
|
119
|
-
elsif( types[i] =~ /text/
|
120
|
-
row[
|
118
|
+
row[columns[i]] = time.to_s(:db)
|
119
|
+
elsif( types[i] =~ /text/ )
|
120
|
+
row[columns[i]] = "~~stub~~"
|
121
|
+
elsif( types[i] =~ /varchar/ )
|
122
|
+
row[columns[i]] = "~~stub~~".to_sym
|
121
123
|
elsif( types[i] =~ /float/ || types[i] =~ /int/ )
|
122
|
-
row[
|
124
|
+
row[columns[i]] = 0
|
125
|
+
elsif( types[i] =~ /datetime/ || types[i] =~ /timetsamp/ )
|
126
|
+
row[columns[i]] = time.to_s(:db)
|
127
|
+
elsif( types[i] =~ /date/ )
|
128
|
+
row[columns[i]] = time.to_s(:db).split(" ").first
|
123
129
|
else
|
124
|
-
row[
|
130
|
+
row[columns[i]] = "NULL"
|
125
131
|
end
|
126
132
|
i = i + 1
|
127
133
|
end
|
data/lib/forklift/plan.rb
CHANGED
@@ -99,7 +99,22 @@ module Forklift
|
|
99
99
|
q(delete_q)
|
100
100
|
end
|
101
101
|
insert_q = insert_q[0...-1]
|
102
|
-
|
102
|
+
|
103
|
+
begin
|
104
|
+
q(insert_q)
|
105
|
+
rescue Mysql2::Error => ex
|
106
|
+
# UTF8 Safety. Open a PR if you don't want UTF8 data...
|
107
|
+
# https://github.com/taskrabbit/demoji
|
108
|
+
raise ex unless ex.message.match /Incorrect string value:/
|
109
|
+
safer_insert_q = ""
|
110
|
+
for i in (0...insert_q.length)
|
111
|
+
char = insert_q[i]
|
112
|
+
char = '???' if char.ord > forklift.config[:char_bytecode_max]
|
113
|
+
safer_insert_q << char
|
114
|
+
end
|
115
|
+
q(safer_insert_q)
|
116
|
+
end
|
117
|
+
|
103
118
|
forklift.logger.log "wrote #{data.length} rows to `#{database}`.`#{table}`"
|
104
119
|
end
|
105
120
|
end
|
data/lib/forklift/version.rb
CHANGED