pipeforge 0.1.0
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +14 -0
- data/LICENSE +21 -0
- data/README.md +168 -0
- data/guides/matching-columns.md +126 -0
- data/guides/measuring-values.md +121 -0
- data/guides/running-the-migration.md +145 -0
- data/lib/pipeforge/adapter_registry.rb +37 -0
- data/lib/pipeforge/adapters/activerecord/adapter.rb +7 -0
- data/lib/pipeforge/adapters/activerecord/model_record.rb +202 -0
- data/lib/pipeforge/adapters/activerecord/schema_reader.rb +142 -0
- data/lib/pipeforge/adapters/activerecord/target.rb +277 -0
- data/lib/pipeforge/cast_result.rb +13 -0
- data/lib/pipeforge/column_limits_checker.rb +152 -0
- data/lib/pipeforge/column_value_analyzer/column_summary_builder.rb +163 -0
- data/lib/pipeforge/column_value_analyzer/distinct_values.rb +61 -0
- data/lib/pipeforge/column_value_analyzer/listed_values.rb +26 -0
- data/lib/pipeforge/column_value_analyzer.rb +96 -0
- data/lib/pipeforge/configuration.rb +209 -0
- data/lib/pipeforge/error_catalog.rb +184 -0
- data/lib/pipeforge/errors.rb +229 -0
- data/lib/pipeforge/header_analyzer/matcher.rb +170 -0
- data/lib/pipeforge/header_analyzer/pair_scorer.rb +116 -0
- data/lib/pipeforge/header_analyzer/tokenizer.rb +43 -0
- data/lib/pipeforge/header_analyzer.rb +129 -0
- data/lib/pipeforge/mapped_columns.rb +208 -0
- data/lib/pipeforge/migration.rb +189 -0
- data/lib/pipeforge/resolved_mapped_column.rb +13 -0
- data/lib/pipeforge/run_processor/chunk_processor.rb +141 -0
- data/lib/pipeforge/run_processor/row_transformer.rb +35 -0
- data/lib/pipeforge/run_processor/schema_checker.rb +67 -0
- data/lib/pipeforge/run_processor.rb +99 -0
- data/lib/pipeforge/source/csv_reader.rb +212 -0
- data/lib/pipeforge/source/reusable_io.rb +71 -0
- data/lib/pipeforge/target_schema.rb +47 -0
- data/lib/pipeforge/utilities.rb +58 -0
- data/lib/pipeforge/version.rb +5 -0
- data/lib/pipeforge.rb +22 -0
- metadata +97 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "smarter_csv"
|
|
4
|
+
|
|
5
|
+
module Pipeforge
|
|
6
|
+
module Source
|
|
7
|
+
# The CSV source reader. It reads a CSV file in chunks of raw rows, using smarter_csv, and
|
|
8
|
+
# gives the core the source interface: +headers+ and +each_chunk+. The migration
|
|
9
|
+
# builds one for its source, and every stage (header analysis, column values analysis, run) reads the
|
|
10
|
+
# file through it.
|
|
11
|
+
#
|
|
12
|
+
# The header is read once and kept. The rows are read again on every +each_chunk+ call.
|
|
13
|
+
#
|
|
14
|
+
# Text is kept as written, with these exceptions: surrounding spaces and tabs are trimmed
|
|
15
|
+
# from values and headers, and a cell that is empty or only whitespace arrives as nil. No
|
|
16
|
+
# numbers are converted. Blank lines and rows whose cells are all empty are dropped before
|
|
17
|
+
# they reach the caller.
|
|
18
|
+
#
|
|
19
|
+
# The header is checked before any row is read (see +headers+), and a row with more cells
|
|
20
|
+
# than the header stops the read (see +each_chunk+). A row with fewer cells is filled with nil.
|
|
21
|
+
class CsvReader
|
|
22
|
+
EMPTY_VALUE = /\A[[:space:]]*\z/
|
|
23
|
+
|
|
24
|
+
# Called by the gem for a row it cannot use (an unclosed quote, or more cells than the
|
|
25
|
+
# header). Stops the scan with an {Error} that carries the line where the row
|
|
26
|
+
# starts.
|
|
27
|
+
STOP_ON_BAD_ROW = lambda do |bad_row|
|
|
28
|
+
line = bad_row[:file_line_number]
|
|
29
|
+
|
|
30
|
+
if bad_row[:error_class] == SmarterCSV::HeaderSizeMismatch
|
|
31
|
+
raise Error.single(**Error::ENTRIES.fetch(:source_row_too_long).call(line: line))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
raise Error.single(**Error::ENTRIES.fetch(:malformed_row).call(line: line, reason: bad_row[:error_message]))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The options every read passes to smarter_csv. Trimming is the gem's default.
|
|
38
|
+
OPTIONS = {
|
|
39
|
+
convert_values_to_numeric: false,
|
|
40
|
+
remove_empty_values: false,
|
|
41
|
+
nil_values_matching: EMPTY_VALUE,
|
|
42
|
+
downcase_header: false,
|
|
43
|
+
keep_original_headers: true,
|
|
44
|
+
on_bad_row: STOP_ON_BAD_ROW,
|
|
45
|
+
missing_headers: :raise,
|
|
46
|
+
verbose: :quiet
|
|
47
|
+
}.freeze
|
|
48
|
+
|
|
49
|
+
# The options for reading only the header: one row at a time, and a repeated name is
|
|
50
|
+
# reported by the gem instead of being renamed, so the names are read as written.
|
|
51
|
+
# A first data row with more cells than the header is not given invented names (the gem would add
|
|
52
|
+
# symbols such as +:column_3+): it stops here with the same error as the other reads.
|
|
53
|
+
HEADER_OPTIONS = OPTIONS.merge(
|
|
54
|
+
chunk_size: 1,
|
|
55
|
+
duplicate_header_suffix: nil
|
|
56
|
+
).freeze
|
|
57
|
+
|
|
58
|
+
# @param source_io [ReusableIO] the CSV source; nothing is read until +headers+ or
|
|
59
|
+
# +each_chunk+ is called
|
|
60
|
+
def initialize(source_io:)
|
|
61
|
+
@source_io = source_io
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Yields each chunk of the file, in order. The header is checked first, so a file with an
|
|
65
|
+
# unusable header yields nothing. Each call reads the whole file again.
|
|
66
|
+
#
|
|
67
|
+
# The block is optional: without one the rows are only read and counted.
|
|
68
|
+
#
|
|
69
|
+
# @param offset [Integer] the number of data rows to drop from the start of the file
|
|
70
|
+
# @param chunk_size [Integer] the most rows in a chunk; the +execution.chunk_size+ setting when not given
|
|
71
|
+
# @param columns [Array<String>, nil] the only columns to give in each row; nil gives them all.
|
|
72
|
+
# Which rows are dropped, kept and counted does not depend on it.
|
|
73
|
+
# @yieldparam rows [Array<Hash{String => String, nil}>] header => raw text, or nil when empty
|
|
74
|
+
# @return [Integer] the number of data rows read, the dropped ones included. Blank lines and rows
|
|
75
|
+
# with only empty cells are not rows.
|
|
76
|
+
# @raise [Error] the header cannot be used (see +headers+), a row cannot be parsed (+malformed_row+) or
|
|
77
|
+
# has more cells than the header (+source_row_too_long+)
|
|
78
|
+
def each_chunk(offset: 0, chunk_size: Configuration.execution.chunk_size, columns: nil)
|
|
79
|
+
headers
|
|
80
|
+
rows_read = 0
|
|
81
|
+
# The gem's own line counters also count the header and the lines it drops, so the rows are counted here.
|
|
82
|
+
counted_rows = SmarterCSV::Reader.new(@source_io, OPTIONS).each.lazy.map do |row|
|
|
83
|
+
rows_read += 1
|
|
84
|
+
row
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# The chunks are cut here and not by the gem's own each_chunk, which cuts them from the start of the file:
|
|
88
|
+
# an offset would then leave the first chunk after it shorter than chunk_size.
|
|
89
|
+
# Lazy: the rows are read one chunk at a time, not all at once.
|
|
90
|
+
rows = counted_rows.drop(offset)
|
|
91
|
+
rows.each_slice(chunk_size) do |chunk|
|
|
92
|
+
# The columns are cut after the rows are read, so a row is dropped, kept and counted the same with or
|
|
93
|
+
# without them, and a row with more cells than the header still stops the read.
|
|
94
|
+
yield only_columns(rows: chunk, columns: columns) if block_given?
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
rows_read
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Yields each data row of the file, in order, one at a time. The header is checked first, so a file with
|
|
101
|
+
# an unusable header yields nothing. Blank rows and rows with only empty cells are not rows. Each call
|
|
102
|
+
# reads the whole file again.
|
|
103
|
+
#
|
|
104
|
+
# The block is optional: without one the rows are only read and counted.
|
|
105
|
+
#
|
|
106
|
+
# @yieldparam row [Hash{String => String, nil}] header => raw text, or nil when empty
|
|
107
|
+
# @return [Integer] the number of data rows read
|
|
108
|
+
# @raise [Error] the header cannot be used (see +headers+), a row cannot be parsed (+malformed_row+) or
|
|
109
|
+
# has more cells than the header (+source_row_too_long+)
|
|
110
|
+
def each_row
|
|
111
|
+
headers
|
|
112
|
+
rows_read = 0
|
|
113
|
+
|
|
114
|
+
SmarterCSV::Reader.new(@source_io, OPTIONS).each do |row|
|
|
115
|
+
rows_read += 1
|
|
116
|
+
yield row if block_given?
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
rows_read
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# The column names in file order, trimmed. They are read from the first line of the file
|
|
123
|
+
# without reading the rest of it (the first data row is parsed too, because the gem needs
|
|
124
|
+
# it, so a malformed first row stops this as well), and then kept: later calls give the same
|
|
125
|
+
# frozen list without reading the file.
|
|
126
|
+
#
|
|
127
|
+
# The header is checked: a name that appears twice and a blank cell are mistakes, and
|
|
128
|
+
# every one is listed in one error.
|
|
129
|
+
#
|
|
130
|
+
# @return [Array<String>]
|
|
131
|
+
# @raise [Error] there is no header line to read (+source_empty+), a header cell is blank or a name
|
|
132
|
+
# appears twice (+source_header_blank+, +source_header_duplicated+), or the first data row cannot be parsed
|
|
133
|
+
# (+malformed_row+) or has more cells than the header (+source_row_too_long+)
|
|
134
|
+
def headers
|
|
135
|
+
if @headers.nil?
|
|
136
|
+
header_names = read_header_names
|
|
137
|
+
reject_unusable_header(header_names: header_names)
|
|
138
|
+
@headers = header_names.freeze
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
@headers
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
# The rows with only the given columns in each; all of them when no columns are given.
|
|
147
|
+
def only_columns(rows:, columns:)
|
|
148
|
+
return rows if columns.nil?
|
|
149
|
+
|
|
150
|
+
rows.map { |row| row.slice(*columns) }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# The real names, as written: a repeated name comes back repeated and a blank cell as "".
|
|
154
|
+
# Empty when the file has no header line to read.
|
|
155
|
+
def read_header_names
|
|
156
|
+
header_reader = SmarterCSV::Reader.new(@source_io, HEADER_OPTIONS)
|
|
157
|
+
read_first_chunk(header_reader: header_reader)
|
|
158
|
+
|
|
159
|
+
header_reader.headers
|
|
160
|
+
rescue SmarterCSV::EmptyFileError, SmarterCSV::NoColSepDetected
|
|
161
|
+
[]
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# The gem reports a repeated name only after it has read the names, so the names are
|
|
165
|
+
# kept and the report is ignored here; the check below decides what a repeat means.
|
|
166
|
+
def read_first_chunk(header_reader:)
|
|
167
|
+
header_reader.each_chunk { break }
|
|
168
|
+
rescue SmarterCSV::DuplicateHeaders
|
|
169
|
+
nil
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Raises when there is no header, or collects every blank cell and repeated name.
|
|
173
|
+
def reject_unusable_header(header_names:)
|
|
174
|
+
if header_names.empty?
|
|
175
|
+
raise Error.single(**Error::ENTRIES.fetch(:source_empty).call)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
errors = blank_cell_errors(header_names: header_names) + repeated_name_errors(header_names: header_names)
|
|
179
|
+
return if errors.empty?
|
|
180
|
+
|
|
181
|
+
raise Error.new(errors: errors)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def blank_cell_errors(header_names:)
|
|
185
|
+
errors = []
|
|
186
|
+
|
|
187
|
+
header_names.each_with_index do |header_name, index|
|
|
188
|
+
next unless header_name.empty?
|
|
189
|
+
|
|
190
|
+
errors << Error::ENTRIES.fetch(:source_header_blank).call(position: index + 1)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
errors
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# One entry for each name that appears more than once. A blank cell is not a name.
|
|
197
|
+
def repeated_name_errors(header_names:)
|
|
198
|
+
counts = Hash.new(0)
|
|
199
|
+
header_names.each { |header_name| counts[header_name] += 1 unless header_name.empty? }
|
|
200
|
+
errors = []
|
|
201
|
+
|
|
202
|
+
counts.each do |header_name, count|
|
|
203
|
+
next if count == 1
|
|
204
|
+
|
|
205
|
+
errors << Error::ENTRIES.fetch(:source_header_duplicated).call(source_column_name: header_name, count: count)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
errors
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pipeforge
|
|
4
|
+
module Source
|
|
5
|
+
# The source of a migration: the IO the consumer gave, wrapped so it can be read again and
|
|
6
|
+
# again. A migration builds one when it is created, and every part that reads the source
|
|
7
|
+
# works with it.
|
|
8
|
+
#
|
|
9
|
+
# smarter_csv closes the file it reads when it finishes, so without this wrapper the
|
|
10
|
+
# consumer's IO would be closed after the first pass and could not be read again. The wrapper
|
|
11
|
+
# offers the methods smarter_csv reads with and no +close+.
|
|
12
|
+
#
|
|
13
|
+
# The IO must respond to +read+, +rewind+ and +seek+; the wrapper checks that when it is
|
|
14
|
+
# built.
|
|
15
|
+
#
|
|
16
|
+
# @example
|
|
17
|
+
# source_io = Pipeforge::Source::ReusableIO.new(io: File.open("data/users.csv"))
|
|
18
|
+
class ReusableIO
|
|
19
|
+
# The methods the IO must have.
|
|
20
|
+
REQUIRED_METHODS = %i[read rewind seek].freeze
|
|
21
|
+
|
|
22
|
+
# @param io [IO] the source to read through, for example +File.open("data/users.csv")+
|
|
23
|
+
# @raise [ArgumentError] the IO lacks a method a migration needs; every missing method is named in
|
|
24
|
+
# the message
|
|
25
|
+
def initialize(io:)
|
|
26
|
+
reject_missing_methods(io: io)
|
|
27
|
+
@io = io
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# smarter_csv calls this with the record separator as its only argument, so the signature
|
|
31
|
+
# is fixed by the gem.
|
|
32
|
+
def gets(*args)
|
|
33
|
+
@io.gets(*args)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def read(*args)
|
|
37
|
+
@io.read(*args)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def rewind
|
|
41
|
+
@io.rewind
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# smarter_csv reads text in this encoding when the IO reports one.
|
|
45
|
+
def external_encoding
|
|
46
|
+
@io.external_encoding
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def eof?
|
|
50
|
+
@io.eof?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
# Raises ArgumentError, naming every method the IO does not have.
|
|
56
|
+
def reject_missing_methods(io:)
|
|
57
|
+
missing_method_names = []
|
|
58
|
+
|
|
59
|
+
REQUIRED_METHODS.each do |method_name|
|
|
60
|
+
missing_method_names << method_name unless io.respond_to?(method_name)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
return if missing_method_names.empty?
|
|
64
|
+
|
|
65
|
+
raise ArgumentError, ArgumentMessages::MESSAGES.fetch(:source_missing_methods).call(
|
|
66
|
+
required_method_names: REQUIRED_METHODS, missing_method_names: missing_method_names
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pipeforge
|
|
4
|
+
# The structure of the target table, as a target reports it. It holds metadata only:
|
|
5
|
+
# no rows, counts or cell values.
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# schema = Pipeforge::TargetSchema.new(table_name: "users", model_name: "User", columns: columns)
|
|
9
|
+
# schema.columns.map(&:name) # => ["id", "email", "company_id"]
|
|
10
|
+
TargetSchema = Data.define(:table_name, :model_name, :columns)
|
|
11
|
+
|
|
12
|
+
# One column of the target table that can be given a source column. A column Pipeforge would
|
|
13
|
+
# never load into (the primary key, an ignored column, a generated column) is not in the
|
|
14
|
+
# schema at all; the adapter leaves it out.
|
|
15
|
+
# type the type name the column values stage checks against (integer, string, ...)
|
|
16
|
+
# sql_type the type as the table writes it
|
|
17
|
+
# limit, max_length, precision, scale the size information that goes with the type
|
|
18
|
+
# is_signed for an integer column, true when it holds negative numbers and false when it does not
|
|
19
|
+
# (an unsigned integer); nil for every other column, which has no sign
|
|
20
|
+
# default the value filled in when none is given, as the model sees it (a default
|
|
21
|
+
# set in the model counts, and an enum shows its label)
|
|
22
|
+
# enum_labels nil, or for an enum column the labels the model accepts (["draft", "placed"]), as
|
|
23
|
+
# text; the values the database stores for them are not part of the schema
|
|
24
|
+
# required whether a row cannot be loaded without a source column for this column.
|
|
25
|
+
# The adapter decides, from whether the column refuses an empty value
|
|
26
|
+
# and has no default (what the framework fills in by itself counts as
|
|
27
|
+
# a default)
|
|
28
|
+
# foreign_key a ForeignKey when the column points to a row of another table, else nil
|
|
29
|
+
# polymorphic a PolymorphicColumn when the column is the id column or the type column of a polymorphic
|
|
30
|
+
# association, else nil
|
|
31
|
+
TargetColumn = Data.define(
|
|
32
|
+
:name, :type, :sql_type, :limit, :is_signed, :max_length, :precision, :scale, :default, :enum_labels,
|
|
33
|
+
:required, :foreign_key, :polymorphic
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# A column that points to a row of another table.
|
|
37
|
+
# association_name the name of the association (company)
|
|
38
|
+
# parent_table_name the table it points to (companies)
|
|
39
|
+
ForeignKey = Data.define(:association_name, :parent_table_name)
|
|
40
|
+
|
|
41
|
+
# A column of a polymorphic association, whose parent can be of different classes: the id column holds the id of
|
|
42
|
+
# the parent and the type column holds the name of its class (+"Post"+), so the two go together and a column
|
|
43
|
+
# alone does not point to one table.
|
|
44
|
+
# association_name the name of the association (commentable)
|
|
45
|
+
# role "id" for the column that holds the id of the parent, "type" for the one that holds its class
|
|
46
|
+
PolymorphicColumn = Data.define(:association_name, :role)
|
|
47
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pipeforge
|
|
4
|
+
# Small helpers that Ruby's core and standard library do not provide. Native methods are
|
|
5
|
+
# used directly and do not belong here; add a helper only when no native call does the job.
|
|
6
|
+
module Utilities
|
|
7
|
+
# The largest finite number a 4-byte (single precision) float holds.
|
|
8
|
+
SINGLE_FLOAT_MAX = 3.4028234663852886e38
|
|
9
|
+
|
|
10
|
+
# The most significand bits of a float column that is single precision (24); a column with a
|
|
11
|
+
# larger limit, or none, is double precision.
|
|
12
|
+
SINGLE_FLOAT_LIMIT = 24
|
|
13
|
+
|
|
14
|
+
# The largest finite number a float column of that size holds. No native call gives it: Ruby's
|
|
15
|
+
# +Float::MAX+ is the double precision maximum only.
|
|
16
|
+
#
|
|
17
|
+
# @param limit [Integer, nil] the +limit+ of the float column: 24 or less for single precision
|
|
18
|
+
# (4 bytes), anything larger or nil for double precision (8 bytes)
|
|
19
|
+
# @return [Float]
|
|
20
|
+
def self.largest_float(limit:)
|
|
21
|
+
return SINGLE_FLOAT_MAX if !limit.nil? && limit <= SINGLE_FLOAT_LIMIT
|
|
22
|
+
|
|
23
|
+
Float::MAX
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Whether a value is a whole number of at least 1. Used for a count that must be positive (a chunk size, a
|
|
27
|
+
# threshold).
|
|
28
|
+
#
|
|
29
|
+
# @param value [Object]
|
|
30
|
+
# @return [Boolean]
|
|
31
|
+
def self.positive_whole_number?(value:)
|
|
32
|
+
value.is_a?(Integer) && value >= 1
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Whether a value is a whole number of at least 0. Used for a count that may be zero (an offset).
|
|
36
|
+
#
|
|
37
|
+
# @param value [Object]
|
|
38
|
+
# @return [Boolean]
|
|
39
|
+
def self.non_negative_whole_number?(value:)
|
|
40
|
+
value.is_a?(Integer) && value >= 0
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Whether a value counts as empty: nil, a string with nothing but whitespace, or another
|
|
44
|
+
# object that is itself empty (an empty array, hash or set). Anything else is not empty,
|
|
45
|
+
# including false and 0, so a value mapped to false is loaded as false. (ActiveSupport's
|
|
46
|
+
# +blank?+ is not used because it returns true for false.)
|
|
47
|
+
#
|
|
48
|
+
# @param value [Object]
|
|
49
|
+
# @return [Boolean]
|
|
50
|
+
def self.blank?(value:)
|
|
51
|
+
return true if value.nil?
|
|
52
|
+
return value.strip.empty? if value.is_a?(String)
|
|
53
|
+
return value.empty? if value.respond_to?(:empty?)
|
|
54
|
+
|
|
55
|
+
false
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/pipeforge.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Pipeforge, a relational data migration library: one gem with the core and its adapters. The core names no
|
|
4
|
+
# database library: the target is reached through an adapter, which is loaded here, when the gem is required.
|
|
5
|
+
# See docs/architecture/overview.md.
|
|
6
|
+
require_relative "pipeforge/version"
|
|
7
|
+
require_relative "pipeforge/errors"
|
|
8
|
+
require_relative "pipeforge/error_catalog"
|
|
9
|
+
require_relative "pipeforge/utilities"
|
|
10
|
+
require_relative "pipeforge/cast_result"
|
|
11
|
+
require_relative "pipeforge/resolved_mapped_column"
|
|
12
|
+
require_relative "pipeforge/adapter_registry"
|
|
13
|
+
require_relative "pipeforge/configuration"
|
|
14
|
+
require_relative "pipeforge/migration"
|
|
15
|
+
|
|
16
|
+
# Read the settings once, now that the gem is loaded; a file that cannot be used stops here.
|
|
17
|
+
Pipeforge::Configuration.load
|
|
18
|
+
|
|
19
|
+
# The adapter is the one the settings name. A library it needs that is missing stops here.
|
|
20
|
+
Pipeforge::Migration.install_target(
|
|
21
|
+
target_class: Pipeforge::AdapterRegistry.resolve(name: Pipeforge::Configuration.target.adapter)
|
|
22
|
+
)
|
metadata
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pipeforge
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- venky
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: smarter_csv
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.19'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.19'
|
|
26
|
+
description: Matches the columns of a CSV source to a target table by name, measures
|
|
27
|
+
the values, and loads them through the application's models. ActiveRecord is supported;
|
|
28
|
+
the application brings the library of its adapter.
|
|
29
|
+
email:
|
|
30
|
+
- developervenkatesh6@gmail.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- CHANGELOG.md
|
|
36
|
+
- LICENSE
|
|
37
|
+
- README.md
|
|
38
|
+
- guides/matching-columns.md
|
|
39
|
+
- guides/measuring-values.md
|
|
40
|
+
- guides/running-the-migration.md
|
|
41
|
+
- lib/pipeforge.rb
|
|
42
|
+
- lib/pipeforge/adapter_registry.rb
|
|
43
|
+
- lib/pipeforge/adapters/activerecord/adapter.rb
|
|
44
|
+
- lib/pipeforge/adapters/activerecord/model_record.rb
|
|
45
|
+
- lib/pipeforge/adapters/activerecord/schema_reader.rb
|
|
46
|
+
- lib/pipeforge/adapters/activerecord/target.rb
|
|
47
|
+
- lib/pipeforge/cast_result.rb
|
|
48
|
+
- lib/pipeforge/column_limits_checker.rb
|
|
49
|
+
- lib/pipeforge/column_value_analyzer.rb
|
|
50
|
+
- lib/pipeforge/column_value_analyzer/column_summary_builder.rb
|
|
51
|
+
- lib/pipeforge/column_value_analyzer/distinct_values.rb
|
|
52
|
+
- lib/pipeforge/column_value_analyzer/listed_values.rb
|
|
53
|
+
- lib/pipeforge/configuration.rb
|
|
54
|
+
- lib/pipeforge/error_catalog.rb
|
|
55
|
+
- lib/pipeforge/errors.rb
|
|
56
|
+
- lib/pipeforge/header_analyzer.rb
|
|
57
|
+
- lib/pipeforge/header_analyzer/matcher.rb
|
|
58
|
+
- lib/pipeforge/header_analyzer/pair_scorer.rb
|
|
59
|
+
- lib/pipeforge/header_analyzer/tokenizer.rb
|
|
60
|
+
- lib/pipeforge/mapped_columns.rb
|
|
61
|
+
- lib/pipeforge/migration.rb
|
|
62
|
+
- lib/pipeforge/resolved_mapped_column.rb
|
|
63
|
+
- lib/pipeforge/run_processor.rb
|
|
64
|
+
- lib/pipeforge/run_processor/chunk_processor.rb
|
|
65
|
+
- lib/pipeforge/run_processor/row_transformer.rb
|
|
66
|
+
- lib/pipeforge/run_processor/schema_checker.rb
|
|
67
|
+
- lib/pipeforge/source/csv_reader.rb
|
|
68
|
+
- lib/pipeforge/source/reusable_io.rb
|
|
69
|
+
- lib/pipeforge/target_schema.rb
|
|
70
|
+
- lib/pipeforge/utilities.rb
|
|
71
|
+
- lib/pipeforge/version.rb
|
|
72
|
+
homepage: https://github.com/venkydev02/Pipeforge
|
|
73
|
+
licenses:
|
|
74
|
+
- MIT
|
|
75
|
+
metadata:
|
|
76
|
+
source_code_uri: https://github.com/venkydev02/Pipeforge
|
|
77
|
+
changelog_uri: https://github.com/venkydev02/Pipeforge/blob/master/CHANGELOG.md
|
|
78
|
+
bug_tracker_uri: https://github.com/venkydev02/Pipeforge/issues
|
|
79
|
+
rubygems_mfa_required: 'true'
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '3.3'
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubygems_version: 3.6.9
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: A deterministic relational data migration library.
|
|
97
|
+
test_files: []
|