forklift_etl 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/LICENSE.txt +201 -0
- data/Rakefile +3 -1
- data/example/Gemfile +1 -1
- data/example/plan.rb +7 -7
- data/lib/forklift/base/logger.rb +1 -1
- data/lib/forklift/base/mailer.rb +3 -3
- data/lib/forklift/plan.rb +8 -8
- data/lib/forklift/transports/csv.rb +2 -2
- data/lib/forklift/transports/elasticsearch.rb +5 -5
- data/lib/forklift/transports/mysql.rb +6 -5
- data/lib/forklift/version.rb +1 -1
- data/readme.md +2 -2
- data/spec/integration/basic_spec.rb +1 -1
- data/spec/integration/csv_spec.rb +5 -5
- data/spec/integration/elasticsearch_spec.rb +11 -11
- data/spec/integration/multi_transport_spec.rb +6 -6
- data/spec/integration/mysql_spec.rb +8 -8
- data/spec/support/spec_client.rb +1 -1
- data/spec/support/spec_plan.rb +4 -4
- data/spec/support/spec_seeds.rb +8 -8
- data/spec/unit/misc/email_spec.rb +5 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjcxMzMwMTNkNzgxNDcyYWJmZWMyYWRiNWZlMGJkMDA3YzJlMGRjNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODQ5OTg3NGIwNDAyMTRiZDY2MzdmYWNlZjAzMTkwYTQ5MjI2ZmQ1ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmM4ZDRkMzNlYTdiOGFmNGZhZTJiZTI4NDVjNGVjOTFmYzc2ZGE5NTk3NDU5
|
10
|
+
ZGI0NGRlM2FiYjliYmQzZWQzYmM0N2U0NTU5NGFkNTJiZmJmZGY2NjZlYmMx
|
11
|
+
MDgzMDQ2Y2Q0NGUxYjg1ZmI5NDVjOGU5ZDY1MTc1YWI0MTgzZGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjMzMDgwNDM1NmQwYjI0Njg4YjU4NDYwNWU0Y2RlZTE3YzgzNjI3ZWJkOWE1
|
14
|
+
MGE5YjU5MjVjODA4NmY5ZTA4OWRkZDdiZTI0Y2E0YzBiYjNkM2FlNjQ5YjMz
|
15
|
+
NDY2OTAwMWFlYTJmMWE4OGE0MzBmN2MzZjgwYzY0ZDMxODdhNTM=
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/Rakefile
CHANGED
data/example/Gemfile
CHANGED
data/example/plan.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# plan = Forklift::Plan.new
|
2
2
|
# Or, you can pass configs
|
3
3
|
plan = Forklift::Plan.new ({
|
4
|
-
# :
|
4
|
+
# logger: {debug: true}
|
5
5
|
})
|
6
6
|
|
7
7
|
plan.do! {
|
@@ -31,7 +31,7 @@ plan.do! {
|
|
31
31
|
destination = plan.connections[:mysql][:destination]
|
32
32
|
table = 'es_import'
|
33
33
|
index = 'aaa'
|
34
|
-
query = { :
|
34
|
+
query = { query: { match_all: {} } } # pagination will happen automatically
|
35
35
|
destination.truncate!(table) if destination.tables.include? table
|
36
36
|
source.read(index, query) {|data| destination.write(data, table) }
|
37
37
|
}
|
@@ -71,14 +71,14 @@ plan.do! {
|
|
71
71
|
destination = plan.connections[:mysql][:destination]
|
72
72
|
|
73
73
|
email_args = {
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
74
|
+
to: "YOU@FAKE.com",
|
75
|
+
from: "Forklift",
|
76
|
+
subject: "value", "Forklift has moved your database @ #{Time.new}",
|
77
77
|
}
|
78
78
|
|
79
79
|
email_variables = {
|
80
|
-
:
|
81
|
-
:
|
80
|
+
total_users_count: destination.read('select count(1) as "count" from users')[0][:count],
|
81
|
+
new_users_count: destination.read('select count(1) as "count" from users where date(created_at) = date(NOW())')[0][:count],
|
82
82
|
}
|
83
83
|
|
84
84
|
email_template = "./template/email.erb"
|
data/lib/forklift/base/logger.rb
CHANGED
@@ -18,7 +18,7 @@ module Forklift
|
|
18
18
|
|
19
19
|
def logger
|
20
20
|
log_dir = "#{forklift.config[:project_root]}/log"
|
21
|
-
@logger ||= ::Lumberjack::Logger.new("#{log_dir}/forklift.log", :
|
21
|
+
@logger ||= ::Lumberjack::Logger.new("#{log_dir}/forklift.log", buffer_size: 0)
|
22
22
|
end
|
23
23
|
|
24
24
|
def log(message, severity="info")
|
data/lib/forklift/base/mailer.rb
CHANGED
@@ -24,9 +24,9 @@ module Forklift
|
|
24
24
|
|
25
25
|
def message_defaults
|
26
26
|
{
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
27
|
+
from: "Forklift",
|
28
|
+
subject: "Forklift has moved your database @ #{Time.new}",
|
29
|
+
body: "Forklift has moved your database @ #{Time.new}",
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
data/lib/forklift/plan.rb
CHANGED
@@ -52,10 +52,10 @@ module Forklift
|
|
52
52
|
error_handler = default_error_handler
|
53
53
|
error_handler = args[1] unless args[1].nil?
|
54
54
|
self.steps[name] = {
|
55
|
-
:
|
56
|
-
:
|
57
|
-
:block
|
58
|
-
:error_handler
|
55
|
+
ran: false,
|
56
|
+
to_run: false,
|
57
|
+
block: block,
|
58
|
+
error_handler: error_handler,
|
59
59
|
}
|
60
60
|
end
|
61
61
|
|
@@ -136,10 +136,10 @@ module Forklift
|
|
136
136
|
|
137
137
|
def default_config
|
138
138
|
return {
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
142
|
-
:
|
139
|
+
project_root: Dir.pwd,
|
140
|
+
logger: {
|
141
|
+
stdout: true,
|
142
|
+
debug: false,
|
143
143
|
},
|
144
144
|
}
|
145
145
|
end
|
@@ -20,7 +20,7 @@ module Forklift
|
|
20
20
|
|
21
21
|
def read(size=1000)
|
22
22
|
data = []
|
23
|
-
CSV.foreach(config[:file], :
|
23
|
+
CSV.foreach(config[:file], headers: true, converters: :all) do |row|
|
24
24
|
data << row.to_hash.symbolize_keys
|
25
25
|
if(data.length == size)
|
26
26
|
if block_given?
|
@@ -41,7 +41,7 @@ module Forklift
|
|
41
41
|
|
42
42
|
def write(data, append=true)
|
43
43
|
if (append == false)
|
44
|
-
FileUtils.rm(config[:file], {:
|
44
|
+
FileUtils.rm(config[:file], {force: true})
|
45
45
|
end
|
46
46
|
|
47
47
|
if( !File.exists?(config[:file]) )
|
@@ -52,18 +52,18 @@ module Forklift
|
|
52
52
|
|
53
53
|
data.each do |d|
|
54
54
|
object = {
|
55
|
-
:index
|
56
|
-
:
|
57
|
-
:type
|
55
|
+
index: index,
|
56
|
+
body: d,
|
57
|
+
type: type,
|
58
58
|
}
|
59
59
|
object[:id] = d[primary_key] if ( !d[primary_key].nil? && update == true )
|
60
60
|
client.index object
|
61
61
|
end
|
62
|
-
client.indices.refresh({ :
|
62
|
+
client.indices.refresh({ index: index })
|
63
63
|
end
|
64
64
|
|
65
65
|
def delete_index(index)
|
66
|
-
client.indices.delete({ :
|
66
|
+
client.indices.delete({ index: index }) if client.indices.exists({ index: index })
|
67
67
|
end
|
68
68
|
|
69
69
|
private
|
@@ -39,7 +39,7 @@ module Forklift
|
|
39
39
|
if prepared_query.downcase.include?("select") && !prepared_query.downcase.include?("limit")
|
40
40
|
prepared_query = "#{prepared_query} LIMIT #{offset}, #{limit}"
|
41
41
|
end
|
42
|
-
response = q(prepared_query, :
|
42
|
+
response = q(prepared_query, symbolize_keys: true)
|
43
43
|
response.each do |row|
|
44
44
|
data << row
|
45
45
|
end
|
@@ -231,10 +231,11 @@ module Forklift
|
|
231
231
|
values.each do |v|
|
232
232
|
part = "NULL"
|
233
233
|
if( [::String, ::Symbol].include?(v.class) )
|
234
|
-
v.
|
235
|
-
|
236
|
-
|
237
|
-
|
234
|
+
s = v.to_s
|
235
|
+
s.gsub!('\\') { '\\\\' }
|
236
|
+
s.gsub!('\"', '\/"')
|
237
|
+
s.gsub!('"', '\"')
|
238
|
+
part = "\"#{s}\""
|
238
239
|
elsif( [::Date, ::Time, ::DateTime].include?(v.class) )
|
239
240
|
s = v.to_s(:db)
|
240
241
|
part = "\"#{s}\""
|
data/lib/forklift/version.rb
CHANGED
data/readme.md
CHANGED
@@ -124,7 +124,7 @@ plan.do! do
|
|
124
124
|
destination = plan.connections[:mysql][:destination]
|
125
125
|
table = 'es_import'
|
126
126
|
index = 'aaa'
|
127
|
-
query = { :
|
127
|
+
query = { query: { match_all: {} } } # pagination will happen automatically
|
128
128
|
destination.truncate!(table) if destination.tables.include? table
|
129
129
|
source.read(index, query) {|data| destination.write(data, table) }
|
130
130
|
end
|
@@ -255,7 +255,7 @@ plan.do! do
|
|
255
255
|
destination = plan.connections[:mysql][:destination]
|
256
256
|
table = 'es_import'
|
257
257
|
index = 'aaa'
|
258
|
-
query = { :
|
258
|
+
query = { query: { match_all: {} } } # pagination will happen automatically
|
259
259
|
destination.truncate!(table) if destination.tables.include? table
|
260
260
|
source.read(index, query) {|data| destination.write(data, table) }
|
261
261
|
}
|
@@ -21,7 +21,7 @@ describe 'basics' do
|
|
21
21
|
|
22
22
|
it 'seeded the elasticsearch db' do
|
23
23
|
client = SpecClient.elasticsearch('forklift_test')
|
24
|
-
results = client.search({ index: 'forklift_test' , body: { :
|
24
|
+
results = client.search({ index: 'forklift_test' , body: { query: { match_all: {} } } })
|
25
25
|
expect(results['hits']['total']).to eql 5
|
26
26
|
end
|
27
27
|
end
|
@@ -40,8 +40,8 @@ describe 'csv' do
|
|
40
40
|
it "can write data (simple)" do
|
41
41
|
plan = SpecPlan.new
|
42
42
|
data = [
|
43
|
-
{:
|
44
|
-
{:
|
43
|
+
{thing: 1, when: Time.now},
|
44
|
+
{thing: 2, when: Time.now},
|
45
45
|
]
|
46
46
|
|
47
47
|
plan.do! {
|
@@ -62,14 +62,14 @@ describe 'csv' do
|
|
62
62
|
destination = plan.connections[:csv][:forklift_test_destination]
|
63
63
|
|
64
64
|
data = [
|
65
|
-
{:
|
66
|
-
{:
|
65
|
+
{thing: 1, when: Time.now},
|
66
|
+
{thing: 2, when: Time.now},
|
67
67
|
]
|
68
68
|
|
69
69
|
destination.write(data)
|
70
70
|
|
71
71
|
data = [
|
72
|
-
{:
|
72
|
+
{thing: 3, when: Time.now},
|
73
73
|
]
|
74
74
|
|
75
75
|
destination.write(data)
|
@@ -8,7 +8,7 @@ describe 'elasticsearch' do
|
|
8
8
|
|
9
9
|
it "can read data (raw)" do
|
10
10
|
index = 'forklift_test'
|
11
|
-
query = { :
|
11
|
+
query = { query: { match_all: {} } }
|
12
12
|
plan = SpecPlan.new
|
13
13
|
@rows = []
|
14
14
|
plan.do! {
|
@@ -23,7 +23,7 @@ describe 'elasticsearch' do
|
|
23
23
|
|
24
24
|
it "can read data (filtered)" do
|
25
25
|
index = 'forklift_test'
|
26
|
-
query = { :
|
26
|
+
query = { query: { match_all: {} } }
|
27
27
|
plan = SpecPlan.new
|
28
28
|
@rows = []
|
29
29
|
plan.do! {
|
@@ -40,7 +40,7 @@ describe 'elasticsearch' do
|
|
40
40
|
index = 'forklift_test'
|
41
41
|
plan = SpecPlan.new
|
42
42
|
data = [
|
43
|
-
{:
|
43
|
+
{id: 99, user_id: 99, product_id: 99, viewed_at: 99}
|
44
44
|
]
|
45
45
|
plan.do! {
|
46
46
|
destination = plan.connections[:elasticsearch][:forklift_test]
|
@@ -48,7 +48,7 @@ describe 'elasticsearch' do
|
|
48
48
|
}
|
49
49
|
|
50
50
|
destination = SpecClient.elasticsearch('forklift_test')
|
51
|
-
count = destination.count({ :
|
51
|
+
count = destination.count({ index: index })["count"]
|
52
52
|
|
53
53
|
expect(count).to eql 6
|
54
54
|
end
|
@@ -57,7 +57,7 @@ describe 'elasticsearch' do
|
|
57
57
|
index = 'forklift_test'
|
58
58
|
plan = SpecPlan.new
|
59
59
|
data = [
|
60
|
-
{:
|
60
|
+
{id: 1, user_id: 1, product_id: 1, viewed_at: 99}
|
61
61
|
]
|
62
62
|
plan.do! {
|
63
63
|
destination = plan.connections[:elasticsearch][:forklift_test]
|
@@ -65,9 +65,9 @@ describe 'elasticsearch' do
|
|
65
65
|
}
|
66
66
|
|
67
67
|
destination = SpecClient.elasticsearch('forklift_test')
|
68
|
-
count = destination.count({ :
|
68
|
+
count = destination.count({ index: index })["count"]
|
69
69
|
expect(count).to eql 5
|
70
|
-
result = destination.search({ :
|
70
|
+
result = destination.search({ index: index, body: { query: {term: {id: 1}} } })
|
71
71
|
expect(result["hits"]["total"]).to eql 1
|
72
72
|
obj = result["hits"]["hits"][0]["_source"]
|
73
73
|
expect(obj["id"]).to eql 1
|
@@ -81,15 +81,15 @@ describe 'elasticsearch' do
|
|
81
81
|
plan = SpecPlan.new
|
82
82
|
client = SpecClient.elasticsearch('forklift_test')
|
83
83
|
data = [
|
84
|
-
{:
|
84
|
+
{id: 1}
|
85
85
|
]
|
86
86
|
plan.do! {
|
87
87
|
destination = plan.connections[:elasticsearch][:forklift_test]
|
88
|
-
expect { client.search({ :
|
88
|
+
expect { client.search({ index: index }) }.to raise_error(/IndexMissingException/)
|
89
89
|
destination.write(data, index, true)
|
90
|
-
expect { client.search({ :
|
90
|
+
expect { client.search({ index: index }) }.to_not raise_error
|
91
91
|
destination.delete_index(index)
|
92
|
-
expect { client.search({ :
|
92
|
+
expect { client.search({ index: index }) }.to raise_error(/IndexMissingException/)
|
93
93
|
}
|
94
94
|
end
|
95
95
|
end
|
@@ -11,7 +11,7 @@ describe 'multiple trasport types' do
|
|
11
11
|
it 'can load in a full query' do
|
12
12
|
table = 'es_import'
|
13
13
|
index = 'forklift_test'
|
14
|
-
query = { :
|
14
|
+
query = { query: { match_all: {} } }
|
15
15
|
plan = SpecPlan.new
|
16
16
|
plan.do! {
|
17
17
|
source = plan.connections[:elasticsearch][:forklift_test]
|
@@ -27,7 +27,7 @@ describe 'multiple trasport types' do
|
|
27
27
|
it 'can load in a partial query' do
|
28
28
|
table = 'es_import'
|
29
29
|
index = 'forklift_test'
|
30
|
-
query = { :
|
30
|
+
query = { query: { match_all: {} }, sort: [{ id: {order: "asc" } }] }
|
31
31
|
plan = SpecPlan.new
|
32
32
|
plan.do! {
|
33
33
|
source = plan.connections[:elasticsearch][:forklift_test]
|
@@ -47,7 +47,7 @@ describe 'multiple trasport types' do
|
|
47
47
|
it 'can detect data types' do
|
48
48
|
table = 'es_import'
|
49
49
|
index = 'forklift_test'
|
50
|
-
query = { :
|
50
|
+
query = { query: { match_all: {} } }
|
51
51
|
plan = SpecPlan.new
|
52
52
|
plan.do! {
|
53
53
|
source = plan.connections[:elasticsearch][:forklift_test]
|
@@ -73,7 +73,7 @@ describe 'multiple trasport types' do
|
|
73
73
|
|
74
74
|
after(:each) do
|
75
75
|
es = SpecClient.elasticsearch('forklift_test')
|
76
|
-
es.indices.delete({ :
|
76
|
+
es.indices.delete({ index: 'users' }) if es.indices.exists({ index: 'users' })
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'can load in a full table' do
|
@@ -87,7 +87,7 @@ describe 'multiple trasport types' do
|
|
87
87
|
}
|
88
88
|
|
89
89
|
destination = SpecClient.elasticsearch('forklift_test')
|
90
|
-
count = destination.count({ :
|
90
|
+
count = destination.count({ index: index })["count"]
|
91
91
|
expect(count).to eql 5
|
92
92
|
end
|
93
93
|
|
@@ -104,7 +104,7 @@ describe 'multiple trasport types' do
|
|
104
104
|
}
|
105
105
|
|
106
106
|
destination = SpecClient.elasticsearch('forklift_test')
|
107
|
-
count = destination.count({ :
|
107
|
+
count = destination.count({ index: index })["count"]
|
108
108
|
expect(count).to eql 3
|
109
109
|
end
|
110
110
|
end
|
@@ -37,7 +37,7 @@ describe 'mysql' do
|
|
37
37
|
it "can write new data" do
|
38
38
|
table = "users"
|
39
39
|
data = [
|
40
|
-
{:
|
40
|
+
{email: 'other@example.com', first_name: 'other', last_name: 'n', created_at: Time.new.to_s(:db), updated_at: Time.new.to_s(:db)}
|
41
41
|
]
|
42
42
|
plan = SpecPlan.new
|
43
43
|
plan.do! {
|
@@ -53,7 +53,7 @@ describe 'mysql' do
|
|
53
53
|
it "can update existing data" do
|
54
54
|
table = "users"
|
55
55
|
data = [
|
56
|
-
{:
|
56
|
+
{id: 1, email: 'evan@example.com', first_name: 'New Name', last_name: 'T', created_at: Time.new.to_s(:db), updated_at: Time.new.to_s(:db)}
|
57
57
|
]
|
58
58
|
plan = SpecPlan.new
|
59
59
|
plan.do! {
|
@@ -77,9 +77,9 @@ describe 'mysql' do
|
|
77
77
|
|
78
78
|
it "can lazy-create a table with primary keys provided" do
|
79
79
|
data = [
|
80
|
-
{:
|
81
|
-
{:
|
82
|
-
{:
|
80
|
+
{id: 1, thing: 'stuff a', updated_at: Time.new},
|
81
|
+
{id: 2, thing: 'stuff b', updated_at: Time.new},
|
82
|
+
{id: 3, thing: 'stuff c', updated_at: Time.new},
|
83
83
|
]
|
84
84
|
table = "new_table"
|
85
85
|
plan = SpecPlan.new
|
@@ -106,9 +106,9 @@ describe 'mysql' do
|
|
106
106
|
|
107
107
|
it "can lazy-create a table without primary keys provided" do
|
108
108
|
data = [
|
109
|
-
{:
|
110
|
-
{:
|
111
|
-
{:
|
109
|
+
{thing: 'stuff a', updated_at: Time.new},
|
110
|
+
{thing: 'stuff b', updated_at: Time.new},
|
111
|
+
{thing: 'stuff c', updated_at: Time.new},
|
112
112
|
]
|
113
113
|
table = "new_table"
|
114
114
|
plan = SpecPlan.new
|
data/spec/support/spec_client.rb
CHANGED
data/spec/support/spec_plan.rb
CHANGED
data/spec/support/spec_seeds.rb
CHANGED
@@ -49,19 +49,19 @@ class SpecSeeds
|
|
49
49
|
conn = elasticsearch_connections[i]
|
50
50
|
index = elasticsearch_databases[i]
|
51
51
|
seed = File.join(File.dirname(__FILE__), '..', 'support', 'dumps', 'elasticsearch', "#{index}.json")
|
52
|
-
conn.indices.delete({ :
|
52
|
+
conn.indices.delete({ index: index }) if conn.indices.exists({ index: index })
|
53
53
|
if File.exists? seed
|
54
54
|
lines = JSON.parse(File.read(seed))
|
55
55
|
lines.each do |line|
|
56
56
|
object = {
|
57
|
-
:index
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
57
|
+
index: index,
|
58
|
+
body: line,
|
59
|
+
type: 'forklift',
|
60
|
+
id: line['id']
|
61
61
|
}
|
62
62
|
conn.index object # assumes ES is setup to allow index creation on write
|
63
63
|
end
|
64
|
-
conn.indices.refresh({ :
|
64
|
+
conn.indices.refresh({ index: index })
|
65
65
|
end
|
66
66
|
i = i + 1
|
67
67
|
end
|
@@ -71,8 +71,8 @@ class SpecSeeds
|
|
71
71
|
seed = File.join(File.dirname(__FILE__), '..', 'support', 'dumps', 'csv', "source.csv")
|
72
72
|
source = '/tmp/source.csv'
|
73
73
|
destination = '/tmp/destination.csv'
|
74
|
-
FileUtils.rm(source, {:
|
75
|
-
FileUtils.rm(destination, {:
|
74
|
+
FileUtils.rm(source, {force: true})
|
75
|
+
FileUtils.rm(destination, {force: true})
|
76
76
|
FileUtils.copy(seed, source)
|
77
77
|
end
|
78
78
|
|
@@ -10,13 +10,13 @@ describe 'misc forklift core' do
|
|
10
10
|
plan = SpecPlan.new
|
11
11
|
plan.do! {
|
12
12
|
email_args = {
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
13
|
+
to: "YOU@FAKE.com",
|
14
|
+
from: "Forklift",
|
15
|
+
subject: "Forklift has moved your database",
|
16
16
|
}
|
17
17
|
email_variables = {
|
18
|
-
:
|
19
|
-
:
|
18
|
+
total_users_count: 10,
|
19
|
+
new_users_count: 5,
|
20
20
|
}
|
21
21
|
email_template = "#{File.dirname(__FILE__)}/../../template/spec_email_template.erb"
|
22
22
|
@email = plan.mailer.send_template(email_args, email_template, email_variables).first
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forklift_etl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Tahler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- .travis.yml
|
124
124
|
- Gemfile
|
125
125
|
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
126
127
|
- Rakefile
|
127
128
|
- bin/forklift
|
128
129
|
- example/Gemfile
|