Skip to content
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

Update configurations to recognize dbname instead of database #1390

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/SyTest/Homeserver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,11 @@ sub _get_dbconfigs
foreach my $db ( keys %db_configs ) {
my $db_config = $db_configs{$db};

# backwards-compatibility hacks
my $db_name = delete $db_config->{name};
# Extract the name of the module that is used to access the database. This
# does add a new item to the database config block, 'type'. It appears to
# be harmless and is used later on to determine which method to use to
# clear the database
my $db_name = $db_config->{name};
if( defined $db_name ) {
if( $db_name eq 'psycopg2' ) {
$db_config->{type} = 'pg';
Expand Down Expand Up @@ -409,7 +412,7 @@ sub _check_db_config

my $db_type = $db_config{type};
if( $db_type eq 'pg' ) {
foreach (qw( database )) {
foreach (qw( dbname )) {
if( !$db_config{args}->{$_} ) {
die "Missing required database argument $_";
}
Expand Down Expand Up @@ -445,7 +448,7 @@ sub _clear_db_pg
my %args = @_;

my $host = $args{host} // '';
$self->{output}->diag( "Clearing Pg database $args{database} on '$host'" );
$self->{output}->diag( "Clearing Pg database $args{dbname} on '$host'" );

require DBI;
require DBD::Pg;
Expand All @@ -455,13 +458,13 @@ sub _clear_db_pg
# a fair few seconds)
my $dbh = DBI->connect( "dbi:Pg:dbname=sytest_template;host=$host", $args{user}, $args{password} );
if ( $dbh ) {
$dbh->do( "DROP DATABASE $args{database}" ); # we don't mind if this dies
$dbh->do( "DROP DATABASE $args{dbname}" ); # we don't mind if this dies

$dbh->do( "CREATE DATABASE $args{database} WITH TEMPLATE sytest_template" ) or
$dbh->do( "CREATE DATABASE $args{dbname} WITH TEMPLATE sytest_template" ) or
die $dbh->errstr;
}
else {
$dbh = DBI->connect( "dbi:Pg:dbname=$args{database};host=$host", $args{user}, $args{password} )
$dbh = DBI->connect( "dbi:Pg:dbname=$args{dbname};host=$host", $args{user}, $args{password} )
or die DBI->errstr;

foreach my $row ( @{ $dbh->selectall_arrayref( "SELECT tablename FROM pg_tables WHERE schemaname = 'public'" ) } ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/SyTest/Homeserver/Dendrite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sub _get_config
$db_config{args}->{user},
$db_config{args}->{password},
"", # $db_config{args}->{host},
$db_config{args}->{database},
$db_config{args}->{dbname},
$db_config{args}->{sslmode},
);

Expand Down
15 changes: 0 additions & 15 deletions lib/SyTest/Homeserver/Synapse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,6 @@ sub start
},
);

# convert sytest db args onto synapse db args
for my $db ( keys %db_configs ) {
my %db_config = %{ $db_configs{$db} };

my $db_type = $db_config{type};

if( $db_type eq "pg" ) {
$db_configs{$db}{name} = 'psycopg2';
}
else {
# must be sqlite
$db_configs{$db}{name} = 'sqlite3';
}
}

# Clean up the media_store directory each time, or else it fills up with
# thousands of automatically-generated avatar images
if( -d "$hs_dir/media_store" ) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/prep_sytest_for_postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mkdir -p "server-1"
cat > "server-0/database.yaml" << EOF
name: psycopg2
args:
database: $POSTGRES_DB_1
dbname: $POSTGRES_DB_1
user: $PGUSER
password: $PGPASSWORD
host: localhost
Expand All @@ -38,7 +38,7 @@ EOF
cat > "server-1/database.yaml" << EOF
name: psycopg2
args:
database: $POSTGRES_DB_2
dbname: $POSTGRES_DB_2
user: $PGUSER
password: $PGPASSWORD
host: localhost
Expand Down
8 changes: 4 additions & 4 deletions scripts/synapse_sytest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ main:
data_stores:
- main
args:
database: pg1_main
dbname: pg1_main
user: postgres
password: $PGPASSWORD
host: localhost
Expand All @@ -66,7 +66,7 @@ state_db:
data_stores:
- state
args:
database: pg1_state
dbname: pg1_state
user: postgres
password: $PGPASSWORD
host: localhost
Expand All @@ -79,7 +79,7 @@ main:
data_stores:
- main
args:
database: pg2_main
dbname: pg2_main
user: postgres
password: $PGPASSWORD
host: localhost
Expand All @@ -89,7 +89,7 @@ state_db:
data_stores:
- state
args:
database: pg2_state
dbname: pg2_state
user: postgres
password: $PGPASSWORD
host: localhost
Expand Down
Loading