deckard 0.3.0 → 0.4.1
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 +4 -4
- data/CHANGELOG.md +28 -1
- data/README.md +26 -18
- data/lib/deckard/active_record/dump.rb +39 -11
- data/lib/deckard/active_record/load.rb +13 -10
- data/lib/deckard/active_record.rb +6 -6
- data/lib/deckard/dumper.rb +3 -3
- data/lib/deckard/loader.rb +4 -4
- data/lib/deckard/model_config.rb +19 -16
- data/lib/deckard/plan_report.rb +1 -1
- data/lib/deckard/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d5a064c82d88bfb7e1303ab4fcd7ab08936f78c78c9b27256a95fcb79e22520
|
|
4
|
+
data.tar.gz: 71320bd238bb13cae37b84fb3d6f2fadef423dd997b93e483514e8c163208be2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 165d0c5ad4bc499f3fcf8d7c54ae27cde30451c1ee4a9d55ad9f86884a163ff9104c44bcf58d64213489e75cde619f78b1145b07a894a9837711746c0e18280b
|
|
7
|
+
data.tar.gz: 4820249beabe3bb2c8bf61657cb34396b2a727a950d6b0850638105ad7a8dbbc4cc9f444d92affae1c9dc7efaeea11ecdf5a0820195723413fce8f21bc8901b2
|
data/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,34 @@ All notable changes to deckard are recorded here. The format follows
|
|
|
5
5
|
[Semantic Versioning](https://semver.org/). Before 1.0, minor versions may
|
|
6
6
|
change the stream format and the Ruby API.
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.4.1] - 2026-11-17
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- `natural_key` is now `match_by`, and `natural_keys` is now
|
|
15
|
+
`match_each_model_by`. The names say what the declaration does: the
|
|
16
|
+
destination matches an existing row by those attributes. There are no
|
|
17
|
+
aliases for the old names. `--plan` output uses `match_by` in JSON and
|
|
18
|
+
"match by" in text. The stream format is unchanged.
|
|
19
|
+
- Query a plain planned `has_many` once per batch of sibling records, not
|
|
20
|
+
once per record. Siblings now come before their collections
|
|
21
|
+
in the stream. Any other planned collection is still queried per record.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- Sync a primary key that is not auto-populated like any other field.
|
|
26
|
+
Deckard dropped every primary key, so loading such a row failed.
|
|
27
|
+
|
|
28
|
+
## [0.3.1] - 2026-10-10
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- Reject unknown names in `omit_associations` with a `ConfigurationError`,
|
|
33
|
+
so a typo cannot silently leave an association included in a dump.
|
|
34
|
+
|
|
35
|
+
## [0.3.0] - 2026-09-30
|
|
9
36
|
|
|
10
37
|
### Added
|
|
11
38
|
|
data/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Deckard copies selected ActiveRecord records, and the records they need,
|
|
4
4
|
from one Rails environment into another. Pick a record, and its plan says
|
|
5
|
-
what comes with it.
|
|
6
|
-
|
|
5
|
+
what comes with it. Deckard remaps foreign keys to the destination rows
|
|
6
|
+
and commits the load only when the stream ends cleanly.
|
|
7
7
|
Its usual job is pulling one production record and its graph into a local
|
|
8
8
|
development database to debug against real data.
|
|
9
9
|
|
|
@@ -34,7 +34,7 @@ class Order < ActiveRecord::Base
|
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
model "Customer" do
|
|
37
|
-
|
|
37
|
+
match_by :email
|
|
38
38
|
omit_fields :password_digest
|
|
39
39
|
end
|
|
40
40
|
end
|
|
@@ -97,11 +97,11 @@ The `replicate` block offers six methods:
|
|
|
97
97
|
```ruby
|
|
98
98
|
replicate do
|
|
99
99
|
associations :line_items # opt this has_many into dumps
|
|
100
|
-
|
|
100
|
+
match_by :number # reuse an existing destination row
|
|
101
101
|
omit_fields :internal_notes # keep a field out of the stream
|
|
102
102
|
omit_associations :warehouse # do not traverse this association
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
match_each_model_by "Product" => :sku, # how each reached class is matched
|
|
105
105
|
"Warehouse" => [:region, :code]
|
|
106
106
|
|
|
107
107
|
model "LineItem" do # the first four, for a class the dump reaches
|
|
@@ -110,15 +110,15 @@ replicate do
|
|
|
110
110
|
end
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
`match_each_model_by` gives reached classes their match keys in one table. A
|
|
114
|
+
`model` block is for the rest: a collection to bring along, a field to leave
|
|
115
|
+
out. A plan gives each class one key, so naming it in both places is a plan
|
|
116
|
+
problem, not an override.
|
|
117
117
|
|
|
118
|
-
Classes are named as strings, so the root never
|
|
118
|
+
Classes are named as strings, so the root never autoloads them,
|
|
119
119
|
and an STI subclass follows the entry for its nearest declared ancestor. Each
|
|
120
|
-
record travels with the
|
|
121
|
-
needs no plan of its own. That also means a
|
|
120
|
+
record travels with the match key its plan gave it, so the destination
|
|
121
|
+
needs no plan of its own. That also means a match key is repeated in every
|
|
122
122
|
plan whose dumps reach the class: a Customer line in Order's plan and one in
|
|
123
123
|
Invoice's, each saying how a customer is matched.
|
|
124
124
|
|
|
@@ -143,7 +143,7 @@ LineItem
|
|
|
143
143
|
associations adjustments
|
|
144
144
|
|
|
145
145
|
Customer
|
|
146
|
-
|
|
146
|
+
match by email
|
|
147
147
|
omit fields password_digest
|
|
148
148
|
```
|
|
149
149
|
|
|
@@ -181,6 +181,9 @@ terminal, a live object counter shows progress on both ends of the pipe.
|
|
|
181
181
|
bypassing validations and callbacks: it copies data, it does not run your
|
|
182
182
|
application. If the source dies mid-stream, nothing is committed.
|
|
183
183
|
|
|
184
|
+
Deckard syncs a primary key that is not auto-populated like any other
|
|
185
|
+
field. Give that model a match key if the same dump will be loaded twice.
|
|
186
|
+
|
|
184
187
|
Loading refuses to run when the application environment is production. Pass
|
|
185
188
|
`--force` to override.
|
|
186
189
|
|
|
@@ -196,7 +199,7 @@ plaintext and are re-encrypted with the destination's keys on load.
|
|
|
196
199
|
## Development
|
|
197
200
|
|
|
198
201
|
`bundle exec rake` runs the unit/integration suite (specs against a local
|
|
199
|
-
PostgreSQL
|
|
202
|
+
PostgreSQL server, lint, and a style ratchet); `bin/rspec spec/deckard/stream_spec.rb`
|
|
200
203
|
runs one file. The specs run against a small forum
|
|
201
204
|
schema managed with ActiveRecord's own migration and schema tooling under
|
|
202
205
|
`spec/db`; `bundle exec rake -T db` lists the database tasks, and
|
|
@@ -207,7 +210,12 @@ host-side checks and the full-stack test. See `docs/spec.md` for the v1.0
|
|
|
207
210
|
specification and `docs/traversal.md` for how a dump walks the graph.
|
|
208
211
|
|
|
209
212
|
Crow CI runs `bundle exec rake` on pull requests, default-branch pushes, and
|
|
210
|
-
manual runs using Ruby
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
manual runs using Ruby and an isolated PostgreSQL service. The workflow in
|
|
214
|
+
[`.crow/ruby.yaml`](.crow/ruby.yaml) defines the runtime versions and covers
|
|
215
|
+
specs, Standard lint, and the style ratchet. [`.crow/e2e.yaml`](.crow/e2e.yaml)
|
|
216
|
+
runs the end-to-end stream test. The performance suite remains a separate
|
|
217
|
+
local task.
|
|
218
|
+
|
|
219
|
+
See the [shared release guide](https://github.com/rsanheim/.github#readme) for
|
|
220
|
+
setup and operation, and the [Deckard quick reference](docs/releasing.md) for
|
|
221
|
+
the files to update in a release PR.
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
module Deckard
|
|
4
4
|
module ActiveRecord
|
|
5
|
-
# Dumps
|
|
6
|
-
#
|
|
5
|
+
# Dumps records by the root's plan (docs/traversal.md), and the records
|
|
6
|
+
# they reach by the same plan.
|
|
7
7
|
class Dump
|
|
8
8
|
# Stored generated columns (GENERATED ALWAYS AS ... STORED) are never
|
|
9
9
|
# dumped: the destination database computes them, and PostgreSQL
|
|
@@ -19,6 +19,30 @@ module Deckard
|
|
|
19
19
|
record.id
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
# Dumps sibling records the plan owns, then each planned collection of
|
|
23
|
+
# the ones this visit walked.
|
|
24
|
+
def self.dump_owned(records, dumper, plan)
|
|
25
|
+
walked = records.select { |record| new(record, dumper, plan, owned: true).call }
|
|
26
|
+
walked.group_by(&:class).each do |model, owners|
|
|
27
|
+
entry = plan.for(model)
|
|
28
|
+
(entry.extra_associations - entry.omitted_associations).each do |name|
|
|
29
|
+
reflection = model.reflect_on_association(name)
|
|
30
|
+
next unless reflection.collection?
|
|
31
|
+
|
|
32
|
+
# Deckard loads a plain has_many for all the siblings in one query;
|
|
33
|
+
# anything else is queried per record.
|
|
34
|
+
plain = reflection.macro == :has_many && reflection.scope.nil? && reflection.klass.default_scopes.empty? &&
|
|
35
|
+
(reflection.options.keys - %i[class_name foreign_key inverse_of dependent]).empty?
|
|
36
|
+
relations = if plain
|
|
37
|
+
[reflection.klass.where(reflection.foreign_key => owners.map(&:id))]
|
|
38
|
+
else
|
|
39
|
+
owners.map { |owner| owner.public_send(name) }
|
|
40
|
+
end
|
|
41
|
+
relations.each { |relation| relation.find_in_batches { |batch| dump_owned(batch, dumper, plan) } }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
22
46
|
def initialize(record, dumper, plan, owned:)
|
|
23
47
|
@record = record
|
|
24
48
|
@model = record.class
|
|
@@ -29,16 +53,25 @@ module Deckard
|
|
|
29
53
|
@entry = plan.for(@model)
|
|
30
54
|
end
|
|
31
55
|
|
|
56
|
+
# Dumps the record and, when owned, its singular owned records. Planned
|
|
57
|
+
# collections are left to dump_owned. True when this visit walked it.
|
|
32
58
|
def call
|
|
59
|
+
walked = false
|
|
33
60
|
@dumper.visit(@model.name, @source_id, walk: @owned) do
|
|
34
61
|
attributes = @record.attributes.except(*GENERATED_COLUMNS[@model], *@entry.omitted_fields)
|
|
35
62
|
dump_belongs_to(attributes)
|
|
36
|
-
@dumper.write(@model.name, @source_id, attributes, @entry.
|
|
63
|
+
@dumper.write(@model.name, @source_id, attributes, @entry.match_key)
|
|
37
64
|
next unless @owned
|
|
38
65
|
|
|
66
|
+
walked = true
|
|
39
67
|
owned = @model.reflect_on_all_associations(:has_one).map(&:name) | @entry.extra_associations
|
|
40
|
-
(owned - @entry.omitted_associations).each
|
|
68
|
+
(owned - @entry.omitted_associations).each do |name|
|
|
69
|
+
next if @model.reflect_on_association(name).collection?
|
|
70
|
+
|
|
71
|
+
self.class.dump_owned(Array(@record.public_send(name)), @dumper, @plan)
|
|
72
|
+
end
|
|
41
73
|
end
|
|
74
|
+
walked
|
|
42
75
|
end
|
|
43
76
|
|
|
44
77
|
private
|
|
@@ -61,8 +94,8 @@ module Deckard
|
|
|
61
94
|
end
|
|
62
95
|
next if @entry.omitted_fields.include?(foreign_key)
|
|
63
96
|
# A belongs_to whose primary_key option targets a non-primary-key
|
|
64
|
-
# column (belongs_to :account, primary_key: :login)
|
|
65
|
-
# value, not a source ID. It needs no remapping and must not be
|
|
97
|
+
# column (belongs_to :account, primary_key: :login) holds that
|
|
98
|
+
# column's value, not a source ID. It needs no remapping and must not be
|
|
66
99
|
# replaced with a destination primary key.
|
|
67
100
|
next unless reflection.association_primary_key(referenced.class) == referenced.class.primary_key
|
|
68
101
|
|
|
@@ -84,11 +117,6 @@ module Deckard
|
|
|
84
117
|
attributes[foreign_key] = [:id, reflection.klass.name, value] unless @entry.omitted_fields.include?(foreign_key)
|
|
85
118
|
true
|
|
86
119
|
end
|
|
87
|
-
|
|
88
|
-
def dump_owned(associated)
|
|
89
|
-
records = associated.respond_to?(:find_each) ? associated.find_each : Array(associated)
|
|
90
|
-
records.each { |record| self.class.new(record, @dumper, @plan, owned: true).call }
|
|
91
|
-
end
|
|
92
120
|
end
|
|
93
121
|
end
|
|
94
122
|
end
|
|
@@ -4,12 +4,12 @@ module Deckard
|
|
|
4
4
|
module ActiveRecord
|
|
5
5
|
# Loads one replicant tuple into a model's table.
|
|
6
6
|
class Load
|
|
7
|
-
def initialize(model, type, source_id, attributes,
|
|
7
|
+
def initialize(model, type, source_id, attributes, match_key)
|
|
8
8
|
@model = model
|
|
9
9
|
@type = type
|
|
10
10
|
@source_id = source_id
|
|
11
11
|
@attributes = attributes
|
|
12
|
-
@
|
|
12
|
+
@match_key = match_key
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def call
|
|
@@ -17,15 +17,18 @@ module Deckard
|
|
|
17
17
|
raise LoadError, "#{@model.name} has a composite primary key, which deckard does not support"
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
@
|
|
20
|
+
@match_key.empty? ? insert : load_by_match_key
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
private
|
|
24
24
|
|
|
25
25
|
# `because` says what led to the insert when it was not the only path,
|
|
26
|
-
# so a failure names the
|
|
26
|
+
# so a failure names the match key that matched nothing.
|
|
27
27
|
def insert(because = "")
|
|
28
|
-
|
|
28
|
+
# An auto-populated primary key is left to the destination database.
|
|
29
|
+
auto_populated = @model.columns_hash[@model.primary_key].auto_populated?
|
|
30
|
+
attributes = auto_populated ? @attributes.except(@model.primary_key) : @attributes
|
|
31
|
+
result = @model.insert_all!([attributes], returning: [@model.primary_key])
|
|
29
32
|
destination_id = result.rows.first.first
|
|
30
33
|
[destination_id, @model.find(destination_id)]
|
|
31
34
|
rescue ::ActiveRecord::ActiveRecordError => e
|
|
@@ -33,25 +36,25 @@ module Deckard
|
|
|
33
36
|
"#{@type} source_id=#{@source_id} #{because}could not be inserted: #{Deckard.error_detail(e)}"
|
|
34
37
|
end
|
|
35
38
|
|
|
36
|
-
def
|
|
37
|
-
lookup = @attributes.slice(*@
|
|
39
|
+
def load_by_match_key
|
|
40
|
+
lookup = @attributes.slice(*@match_key)
|
|
38
41
|
matches = @model.where(lookup).limit(2).to_a
|
|
39
42
|
|
|
40
43
|
case matches.size
|
|
41
44
|
when 0
|
|
42
|
-
insert("matched no destination row by
|
|
45
|
+
insert("matched no destination row by match key (#{lookup.keys.join(", ")}) and ")
|
|
43
46
|
when 1
|
|
44
47
|
record = matches.first
|
|
45
48
|
begin
|
|
46
49
|
record.update_columns(@attributes.except(@model.primary_key))
|
|
47
50
|
rescue ::ActiveRecord::ActiveRecordError => e
|
|
48
51
|
raise InsertError,
|
|
49
|
-
"#{@type} source_id=#{@source_id} could not be updated via
|
|
52
|
+
"#{@type} source_id=#{@source_id} could not be updated via match key: #{Deckard.error_detail(e)}"
|
|
50
53
|
end
|
|
51
54
|
[record.id, record]
|
|
52
55
|
else
|
|
53
56
|
raise LoadError,
|
|
54
|
-
"#{@type} source_id=#{@source_id}:
|
|
57
|
+
"#{@type} source_id=#{@source_id}: match key (#{lookup.keys.join(", ")}) matches more than one destination row"
|
|
55
58
|
end
|
|
56
59
|
end
|
|
57
60
|
end
|
|
@@ -16,7 +16,7 @@ module Deckard
|
|
|
16
16
|
# Records reached from this one are dumped by its plan directly, so an
|
|
17
17
|
# override of this method applies to roots only.
|
|
18
18
|
def dump_replicant(dumper)
|
|
19
|
-
Dump.
|
|
19
|
+
Dump.dump_owned([self], dumper, ModelConfig.plan_for(self.class))
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
module ClassMethods
|
|
@@ -25,11 +25,11 @@ module Deckard
|
|
|
25
25
|
ModelConfig.declare(name, &block)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
# Load one streamed replicant: reuse an existing row when its
|
|
29
|
-
# key matches, otherwise insert a new row
|
|
30
|
-
#
|
|
31
|
-
def load_replicant(type, source_id, attributes,
|
|
32
|
-
Load.new(self, type, source_id, attributes,
|
|
28
|
+
# Load one streamed replicant: reuse an existing row when its match
|
|
29
|
+
# key matches, otherwise insert a new row. Both paths bypass validations
|
|
30
|
+
# and callbacks.
|
|
31
|
+
def load_replicant(type, source_id, attributes, match_key)
|
|
32
|
+
Load.new(self, type, source_id, attributes, match_key).call
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
end
|
data/lib/deckard/dumper.rb
CHANGED
|
@@ -57,13 +57,13 @@ module Deckard
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
# Called by dump_replicant implementations to emit one replicant tuple.
|
|
60
|
-
#
|
|
60
|
+
# match_key names the attributes by which the destination matches an
|
|
61
61
|
# existing record to reuse; empty means always insert.
|
|
62
|
-
def write(type, id, attributes,
|
|
62
|
+
def write(type, id, attributes, match_key = [])
|
|
63
63
|
type = type.to_s
|
|
64
64
|
return unless @dumped.add?([type, id])
|
|
65
65
|
|
|
66
|
-
write_frame([type, id, attributes,
|
|
66
|
+
write_frame([type, id, attributes, match_key])
|
|
67
67
|
@counts[type] += 1
|
|
68
68
|
@after_write&.call(@counts)
|
|
69
69
|
end
|
data/lib/deckard/loader.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Deckard
|
|
4
4
|
# Reads a Deckard stream incrementally from an input IO, resolving
|
|
5
5
|
# [:id, type, source_id] reference tuples through the source-to-destination
|
|
6
|
-
# ID map and handing each replicant, with the
|
|
6
|
+
# ID map and handing each replicant, with the match key it travels
|
|
7
7
|
# with, to its class's load_replicant.
|
|
8
8
|
class Loader
|
|
9
9
|
attr_reader :counts
|
|
@@ -58,12 +58,12 @@ module Deckard
|
|
|
58
58
|
|
|
59
59
|
def load_replicant(frame)
|
|
60
60
|
unless frame.is_a?(Array) && frame.size == 4 && frame[0].is_a?(String) && frame[2].is_a?(Hash) && frame[3].is_a?(Array)
|
|
61
|
-
raise InvalidStream, "malformed stream frame (expected [type, id, attributes,
|
|
61
|
+
raise InvalidStream, "malformed stream frame (expected [type, id, attributes, match_key] tuple)"
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
type, source_id, attributes,
|
|
64
|
+
type, source_id, attributes, match_key = frame
|
|
65
65
|
resolved = resolve_references(type, source_id, attributes)
|
|
66
|
-
destination_id, _object = replicant_class(type).load_replicant(type, source_id, resolved,
|
|
66
|
+
destination_id, _object = replicant_class(type).load_replicant(type, source_id, resolved, match_key)
|
|
67
67
|
@id_map[[type, source_id]] = destination_id
|
|
68
68
|
@counts[type] += 1
|
|
69
69
|
@after_load&.call(@counts)
|
data/lib/deckard/model_config.rb
CHANGED
|
@@ -5,11 +5,11 @@ require "active_support/core_ext/string/inflections"
|
|
|
5
5
|
module Deckard
|
|
6
6
|
# A replication plan: a root model's `replicate do ... end` block. The plan
|
|
7
7
|
# is an entry for the root plus an entry for each class its dumps reach,
|
|
8
|
-
# declared through `
|
|
9
|
-
# the plan's entries. A class finds its entry through its
|
|
10
|
-
# STI subclass follows its nearest declared ancestor. See docs/traversal.md.
|
|
8
|
+
# declared through `match_each_model_by` or `model`, all in one table
|
|
9
|
+
# shared by the plan's entries. A class finds its entry through its
|
|
10
|
+
# ancestors, so an STI subclass follows its nearest declared ancestor. See docs/traversal.md.
|
|
11
11
|
class ModelConfig
|
|
12
|
-
attr_reader :name, :extra_associations, :
|
|
12
|
+
attr_reader :name, :extra_associations, :match_key, :omitted_fields, :omitted_associations
|
|
13
13
|
|
|
14
14
|
@plans = {}
|
|
15
15
|
|
|
@@ -35,7 +35,7 @@ module Deckard
|
|
|
35
35
|
@entries[name] = self if name
|
|
36
36
|
@resolved = {}
|
|
37
37
|
@extra_associations = []
|
|
38
|
-
@
|
|
38
|
+
@match_key = []
|
|
39
39
|
@omitted_fields = []
|
|
40
40
|
@omitted_associations = []
|
|
41
41
|
end
|
|
@@ -48,14 +48,14 @@ module Deckard
|
|
|
48
48
|
|
|
49
49
|
# DSL: attributes identifying an existing destination record to reuse.
|
|
50
50
|
# Declaring it twice in one plan is a problem, not an override.
|
|
51
|
-
def
|
|
52
|
-
@
|
|
53
|
-
@
|
|
51
|
+
def match_by(*attributes)
|
|
52
|
+
@redeclared_match_key = !@match_key.empty?
|
|
53
|
+
@match_key = attributes.map(&:to_s)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
# DSL: class name to
|
|
57
|
-
def
|
|
58
|
-
keys.each { |name, attributes| model(name) {
|
|
56
|
+
# DSL: class name to match key, for reached classes needing nothing else.
|
|
57
|
+
def match_each_model_by(keys)
|
|
58
|
+
keys.each { |name, attributes| model(name) { match_by(*attributes) } }
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
# DSL: fields to exclude from dumped attributes. Additive across calls.
|
|
@@ -105,15 +105,18 @@ module Deckard
|
|
|
105
105
|
"which deckard does not support; replicate :#{reflection.through_reflection.name} instead"
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
|
-
|
|
108
|
+
problems += @omitted_associations.filter_map do |name|
|
|
109
|
+
"#{model} has no #{name.inspect} association" unless model.reflect_on_association(name)
|
|
110
|
+
end
|
|
111
|
+
attributes = @match_key + @omitted_fields
|
|
109
112
|
unless attributes.empty? || model.abstract_class?
|
|
110
113
|
missing = attributes - model.attribute_names
|
|
111
114
|
problems += missing.map { |attribute| "#{model} has no #{attribute.inspect} attribute" }
|
|
112
115
|
end
|
|
113
|
-
problems += (@
|
|
114
|
-
"#{model} names #{attribute.inspect} as both a
|
|
116
|
+
problems += (@match_key & @omitted_fields).map do |attribute|
|
|
117
|
+
"#{model} names #{attribute.inspect} as both a match key attribute and an omitted field"
|
|
115
118
|
end
|
|
116
|
-
problems << "#{model} is given a
|
|
119
|
+
problems << "#{model} is given a match key more than once in the same plan" if @redeclared_match_key
|
|
117
120
|
problems
|
|
118
121
|
end
|
|
119
122
|
|
|
@@ -123,7 +126,7 @@ module Deckard
|
|
|
123
126
|
{
|
|
124
127
|
"model" => entry.name,
|
|
125
128
|
"associations" => entry.extra_associations.map(&:to_s),
|
|
126
|
-
"
|
|
129
|
+
"match_by" => entry.match_key,
|
|
127
130
|
"omit_fields" => entry.omitted_fields,
|
|
128
131
|
"omit_associations" => entry.omitted_associations.map(&:to_s)
|
|
129
132
|
}
|
data/lib/deckard/plan_report.rb
CHANGED
data/lib/deckard/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: deckard
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rob Sanheim
|
|
@@ -44,8 +44,7 @@ dependencies:
|
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
45
|
version: '3.2'
|
|
46
46
|
description: Copy selected ActiveRecord records and their associations between PostgreSQL
|
|
47
|
-
databases, with
|
|
48
|
-
loads.
|
|
47
|
+
databases, with remapped foreign keys and transactional loads.
|
|
49
48
|
email:
|
|
50
49
|
- rsanheim@gmail.com
|
|
51
50
|
executables:
|
|
@@ -90,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
90
89
|
- !ruby/object:Gem::Version
|
|
91
90
|
version: '0'
|
|
92
91
|
requirements: []
|
|
93
|
-
rubygems_version: 4.0.
|
|
92
|
+
rubygems_version: 4.0.20
|
|
94
93
|
specification_version: 4
|
|
95
94
|
summary: Stream ActiveRecord objects between Rails environments
|
|
96
95
|
test_files: []
|