Skip to content

Commit 4ad9b13

Browse files
authored
Update configurations to recognize dbname instead of database (#1390)
* Stop using 'database' and start using 'dbname' to describe the database name to connect to in Postgres For Synapse, these pass through and match expected configuration expectations from the manual. For Dendrite, the generated database config is parsed and turned into a DSN that is used to generate its main config yaml. All that was needed is to update where the value comes from. This brings the named parameters into line with libpq. * Stop removing and re-adding the `name` attribute from the database config This only seemed to be needed for Synapse as Dendrite used another method and was not relevant
1 parent c678954 commit 4ad9b13

File tree

5 files changed

+17
-29
lines changed

5 files changed

+17
-29
lines changed

lib/SyTest/Homeserver.pm

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,11 @@ sub _get_dbconfigs
374374
foreach my $db ( keys %db_configs ) {
375375
my $db_config = $db_configs{$db};
376376

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

410413
my $db_type = $db_config{type};
411414
if( $db_type eq 'pg' ) {
412-
foreach (qw( database )) {
415+
foreach (qw( dbname )) {
413416
if( !$db_config{args}->{$_} ) {
414417
die "Missing required database argument $_";
415418
}
@@ -445,7 +448,7 @@ sub _clear_db_pg
445448
my %args = @_;
446449

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

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

460-
$dbh->do( "CREATE DATABASE $args{database} WITH TEMPLATE sytest_template" ) or
463+
$dbh->do( "CREATE DATABASE $args{dbname} WITH TEMPLATE sytest_template" ) or
461464
die $dbh->errstr;
462465
}
463466
else {
464-
$dbh = DBI->connect( "dbi:Pg:dbname=$args{database};host=$host", $args{user}, $args{password} )
467+
$dbh = DBI->connect( "dbi:Pg:dbname=$args{dbname};host=$host", $args{user}, $args{password} )
465468
or die DBI->errstr;
466469

467470
foreach my $row ( @{ $dbh->selectall_arrayref( "SELECT tablename FROM pg_tables WHERE schemaname = 'public'" ) } ) {

lib/SyTest/Homeserver/Dendrite.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ sub _get_config
9191
$db_config{args}->{user},
9292
$db_config{args}->{password},
9393
"", # $db_config{args}->{host},
94-
$db_config{args}->{database},
94+
$db_config{args}->{dbname},
9595
$db_config{args}->{sslmode},
9696
);
9797

lib/SyTest/Homeserver/Synapse.pm

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,6 @@ sub start
125125
},
126126
);
127127

128-
# convert sytest db args onto synapse db args
129-
for my $db ( keys %db_configs ) {
130-
my %db_config = %{ $db_configs{$db} };
131-
132-
my $db_type = $db_config{type};
133-
134-
if( $db_type eq "pg" ) {
135-
$db_configs{$db}{name} = 'psycopg2';
136-
}
137-
else {
138-
# must be sqlite
139-
$db_configs{$db}{name} = 'sqlite3';
140-
}
141-
}
142-
143128
# Clean up the media_store directory each time, or else it fills up with
144129
# thousands of automatically-generated avatar images
145130
if( -d "$hs_dir/media_store" ) {

scripts/prep_sytest_for_postgres.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mkdir -p "server-1"
2828
cat > "server-0/database.yaml" << EOF
2929
name: psycopg2
3030
args:
31-
database: $POSTGRES_DB_1
31+
dbname: $POSTGRES_DB_1
3232
user: $PGUSER
3333
password: $PGPASSWORD
3434
host: localhost
@@ -38,7 +38,7 @@ EOF
3838
cat > "server-1/database.yaml" << EOF
3939
name: psycopg2
4040
args:
41-
database: $POSTGRES_DB_2
41+
dbname: $POSTGRES_DB_2
4242
user: $PGUSER
4343
password: $PGPASSWORD
4444
host: localhost

scripts/synapse_sytest.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ main:
5656
data_stores:
5757
- main
5858
args:
59-
database: pg1_main
59+
dbname: pg1_main
6060
user: postgres
6161
password: $PGPASSWORD
6262
host: localhost
@@ -66,7 +66,7 @@ state_db:
6666
data_stores:
6767
- state
6868
args:
69-
database: pg1_state
69+
dbname: pg1_state
7070
user: postgres
7171
password: $PGPASSWORD
7272
host: localhost
@@ -79,7 +79,7 @@ main:
7979
data_stores:
8080
- main
8181
args:
82-
database: pg2_main
82+
dbname: pg2_main
8383
user: postgres
8484
password: $PGPASSWORD
8585
host: localhost
@@ -89,7 +89,7 @@ state_db:
8989
data_stores:
9090
- state
9191
args:
92-
database: pg2_state
92+
dbname: pg2_state
9393
user: postgres
9494
password: $PGPASSWORD
9595
host: localhost

0 commit comments

Comments
 (0)