Move some common database import subroutines to Script::Utils
#3200
+162
−181
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We have some identical or very similar-looking subroutines duplicated between admin/MBImport.pl and admin/replication/ImportReplicationChanges:
empty
(to tell if a table is empty) andImportTable
(to import a table from a file). The two implementations of the latter function differ slightly.For the incremental dumps (
MusicBrainz::Script::Role::IncrementalDump
), I'd like to reuse theImportTable
function to import a dbmirror2 packet into some temporary tables (to parse it).We currently parse the old packets by hand; I'm surprised it works at all (it probably doesn't in some cases) because I don't believe it fully or properly implement's parsing of PostgreSQL's
COPY
text
format. dbmirror2 packets contain JSON, which may contain JSON escape sequences underneathCOPY
'stext
format escape sequences, and the mixing of these can be tricky to parse. It's much, much easier to let PostgreSQL do the parsing!Solution
This just adds two shared subroutines,
is_table_empty
andcopy_table_from_file
toScript::Utils
, and modifies admin/MBImport.pl and admin/replication/ImportReplicationChanges to use them.Testing
We have existing automated tests that make heavy use of these scripts.
I did not test the
--fix-broken-utf8
or--ignore-errors
flags specifically.