New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an --initial-sql
flag to InitDb.pl; allow configuring the REPLICATION_TYPE
for create_test_db.sh
#3197
base: master
Are you sure you want to change the base?
Conversation
37842e3
to
54b817a
Compare
is($result, $f1_path, 'scalar file is found by direct path'); | ||
|
||
$result = find_mbdump_file('artist', $dir1); | ||
is($result, $f1_path, 'scalar file is found in directory'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you prefer lowercase for these labels? I generally start them with uppercase because they look like full sentences to me the way we print them, but obviously this is mega minor anyway :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess because they read more like fragments than full sentences to me. :) And some of them start with undef
or variable names which would be weird to capitalize...
I don't have a particular preference though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTMBDNT, I'd like @yvanzo to check it too. I had no idea script/setup_development_db.sh
even existed!
This merges the separate implementations of `find_file` contained in admin/MBImport.pl and admin/replication/ImportReplicationChanges into `Script::Utils`, and adds tests for said function. The main difference between the two was that MBImport.pl's implementation would return an array of matching files, rather than the first match. We now use Perl's `wantarray` built-in to distinguish between the two cases.
In case the search paths overlap (e.g., we may find the file via a direct path, and then again via a parent directory).
It works the same, except it doesn't check `mbdump/` subdirectories nor does it support returning a scalar result. `find_mbdump_file` calls it internally.
Support specifying a path prefix in the first `$file` paremeter: e.g., `caa/CreateTables.sql` in the added test case includes a `caa/` path prefix, but will now be found in the search path `/tmp/foo/sql/caa/CreateTables.sql`.
Allows specifying which SQL script to initialize a clean database with. Prior to this commit, admin/sql/InsertDefaultRows.sql was always used (and this could not be disabled!). One current use case of this is that we can initialize test databases with t/sql/initial.sql instead; and in that file, we no longer have to worry about disabling triggers (because the `initial-sql` script is run before triggers are added) or specifying `ON CONFLICT` handlers (which were to avoid conflicts with existing data that was in admin/sql/InsertDefaultRows.sql). The triggers issue is particularly relevant for mirror databases, where certain triggers do not exist. We can now initialize mirror test databases with t/sql/initial.sql, where previously it would error on the `DISABLE TRIGGER a_ins_instrument` line. But removing that line means we *must* run this script before creating triggers, hence the lines I've reordered in create_test_db.sh, and the changes I've made to the Selenium test scripts.
With the `--initial-sql` flag to InitDb.pl, we only have to drop the existing schemas if the database already exists (and otherwise create the pgtap extension).
`ON_ERROR_STOP` must be set in order for psql to return a non-zero exit code on statement failures. This is not much of an issue now that `IF NOT EXISTS` was added, but I thought I'd fix it anyway given that the intent of the code is to capture errors.
I've never once used this, and its purpose seems to have been overtaken by the sample database dumps.
54b817a
to
0db1479
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About testing. What has been tested so far? Is there a setup that you would like us to test in particular?
Only minor comments otherwise.
if [ -z "$SIR_DIR" ]; then | ||
SIR_DIR="$MB_SERVER_ROOT"/../sir | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip for setting a variable to a default value:
if [ -z "$SIR_DIR" ]; then | |
SIR_DIR="$MB_SERVER_ROOT"/../sir | |
fi | |
SIR_DIR="${SIR_DIR:=$MB_SERVER_ROOT/../sir}" |
if [ -z "$ARTWORK_INDEXER_DIR" ]; then | ||
ARTWORK_INDEXER_DIR="$MB_SERVER_ROOT"/../artwork-indexer | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above:
if [ -z "$ARTWORK_INDEXER_DIR" ]; then | |
ARTWORK_INDEXER_DIR="$MB_SERVER_ROOT"/../artwork-indexer | |
fi | |
ARTWORK_INDEXER_DIR="${ARTWORK_INDEXER_DIR:=$MB_SERVER_ROOT/../artwork-indexer}" |
@@ -0,0 +1,50 @@ | |||
#!/usr/bin/env bash | |||
|
|||
set -o errexit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be safer to enable all the error detection options then:
nounset
detects using unset variables (whether that is due to a coding mistake or a script misuse).pipefail
detects failures of piped commands (even thoughecho
is unlikely to fail here).
set -o errexit | |
set -o errexit -o nounset -o pipefail |
@@ -20,7 +20,7 @@ sudo -E -H -u musicbrainz cp docker/musicbrainz-tests/DBDefs.pm lib/ | |||
|
|||
sv_start_if_down postgresql redis | |||
|
|||
sudo -E -H -u musicbrainz carton exec -- ./script/create_test_db.sh | |||
REPLICATION_TYPE=1 sudo -E -H -u musicbrainz carton exec -- ./script/create_test_db.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this change isn’t obvious from the message for commit 37a8cf3
@@ -117,6 +117,7 @@ test all => sub { | |||
'-U', $system_db->username, | |||
$test_db->database; | |||
|
|||
$ENV{REPLICATION_TYPE} = 1; # master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
This is based on top of #3194
Problem
This resolves two problems:
I'd like to fix these issues in order to improve the test suites that make use of replication packets (and thus require separate master/mirror test databases).
Solution
With this PR, you can set the
REPLICATION_TYPE
environment variable before running./script/create_test_db.sh
:See associated commits for details.
Testing
Just manual invocations of the create_test_db.sh and InitDb.pl commands, plus automated tests.