directory_diff 0.4.11 → 0.4.12
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c2bfcffa269d189122f5a26e497e67413990319
|
4
|
+
data.tar.gz: a97ad9941677dcf9f4da9e40225a0080c3226fc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41cac991119fab2db6acf885eba8f4767d3159a40c4bf3ea49f3dfd5c7cf2c52ae2ae1f0e2fa505a968592cbce79983b868977e465fe56d19cda286fc422ad80
|
7
|
+
data.tar.gz: bf5a930f70ccc7af38f87a8607f83772b8ca16e0a602fedac351e28cd10db3433f48befbdcf392db3df5ceba8ca72db5d290d0d79a35bc44942b6f2f12eec9aa
|
@@ -64,11 +64,24 @@ module DirectoryDiff
|
|
64
64
|
original_assistant_value = new_employee[3]
|
65
65
|
end
|
66
66
|
|
67
|
+
# phone_number may be nil. we only use the csv to *set* phone numbers if
|
68
|
+
# it has a value. if it was nil, we backfill from current employee so that
|
69
|
+
# the new record apperas to the be same as the current record
|
70
|
+
phone_number = new_employee[2].presence
|
71
|
+
if phone_number.nil?
|
72
|
+
original_phone_number_value = nil
|
73
|
+
new_employee[2] = old_employee&.fetch(2)
|
74
|
+
else
|
75
|
+
original_phone_number_value = new_employee[2]
|
76
|
+
end
|
77
|
+
|
67
78
|
if old_employee.nil?
|
68
79
|
add_transform(:insert, new_employee)
|
69
80
|
elsif new_employee[0, 4] == old_employee[0, 4]
|
70
81
|
# restore assistant value after cleanup like missing assistants and own email
|
71
82
|
new_employee[3] = original_assistant_value
|
83
|
+
# restore phone number value
|
84
|
+
new_employee[2] = original_phone_number_value
|
72
85
|
add_transform(:noop, new_employee) unless options[:skip_noop]
|
73
86
|
else
|
74
87
|
add_transform(:update, new_employee)
|
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
require "activerecord_pg_stuff"
|
4
4
|
|
5
|
-
Arel::Predications.module_eval do
|
6
|
-
def contains(other)
|
7
|
-
Arel::Nodes::InfixOperation.new(:"@>", self, other)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
5
|
module DirectoryDiff
|
12
6
|
module Transformer
|
13
7
|
class TempTable
|
@@ -36,9 +30,14 @@ module DirectoryDiff
|
|
36
30
|
attributes_unchanged = employees[:name].eq(csv[:name])
|
37
31
|
.and(
|
38
32
|
employees[:phone_number].eq(csv[:phone_number])
|
33
|
+
.or(csv[:phone_number].eq(""))
|
34
|
+
# ☝🏽 Comparing to an empty string because we cast
|
35
|
+
# phone number to an empty string. The reason is
|
36
|
+
# comparing NULL = NULL is always false in SQL
|
39
37
|
)
|
40
38
|
.and(
|
41
|
-
employees[:assistants].
|
39
|
+
employees[:assistants].eq(csv[:assistants])
|
40
|
+
.or(csv[:assistants].eq("{}"))
|
42
41
|
)
|
43
42
|
|
44
43
|
# Creates joins between the temp table and the csv table and
|
@@ -59,7 +58,8 @@ module DirectoryDiff
|
|
59
58
|
|
60
59
|
connection.execute(SQL.cleanup_sql(csv.name))
|
61
60
|
|
62
|
-
csv_fields = [
|
61
|
+
csv_fields = %I[name email phone_number assistants extra].map { |c| csv[c] }
|
62
|
+
emp_fields = %I[name email phone_number assistants].map { |c| employees[c] }
|
63
63
|
|
64
64
|
# new records are records in the new directory that don't exist in
|
65
65
|
# the current directory
|
@@ -71,7 +71,8 @@ module DirectoryDiff
|
|
71
71
|
# exist in the new directory
|
72
72
|
deleted_records = employee_records
|
73
73
|
.select("'delete'::varchar operation, row_number")
|
74
|
-
.select(
|
74
|
+
.select(emp_fields)
|
75
|
+
.select("null extra")
|
75
76
|
.where({ csv.name => { email: nil } })
|
76
77
|
# changed records are records that have difference in name, phone
|
77
78
|
# number and/or assistants
|
@@ -169,7 +170,12 @@ module DirectoryDiff
|
|
169
170
|
if activerecord52?
|
170
171
|
rel = ActiveRecord::Relation.new(dec)
|
171
172
|
else
|
172
|
-
rel = ActiveRecord::Relation.new(
|
173
|
+
rel = ActiveRecord::Relation.new(
|
174
|
+
dec,
|
175
|
+
dec.arel_table,
|
176
|
+
dec.predicate_builder,
|
177
|
+
{}
|
178
|
+
)
|
173
179
|
end
|
174
180
|
rel.readonly!
|
175
181
|
block.call(rel)
|