Skip to content
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
16 changes: 13 additions & 3 deletions app/lib/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,21 @@ Future<(String, String?)> _startOrUseLocalPostgresInDocker() async {
throw StateError('Missing connection URL in Appengine environment.');
}

final socketFile = File('/tmp/pub_dev_postgres/run/.s.PGSQL.5432');

// the default connection URL for local server
final url = Uri(
scheme: 'postgresql',
host: 'localhost',
port: 55432,
path: 'postgres',
userInfo: 'postgres:postgres',
queryParameters: {'sslmode': 'disable'},
queryParameters: {
// If the socket file is present, let's try to use it, otherwise connect through the port.
// Both has benefits:
// - (during startup) calling the port is a blocking call and waits until the service is started,
// - (while the service is running) the socket file seems to provide a bit faster connection.
'host': await socketFile.exists() ? socketFile.path : 'localhost:55432',
'sslmode': 'disable',
},
).toString();

try {
Expand All @@ -122,6 +129,9 @@ Future<(String, String?)> _startOrUseLocalPostgresInDocker() async {
'Unexpect exit code from tool/start-local-postgres.sh\n${pr.stderr}',
);
}
// The socket file may be present sooner than the server is accepting connections.
// This arbitrary wait is probably enough to have a working server at this point.
await Future.delayed(Duration(seconds: 2));
}
return (url, null);
}
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies:
pana: '0.23.0'
# 3rd-party packages with pinned versions
mailer: '6.5.0'
postgres: '3.5.8'
postgres: '3.5.9'
ulid: '2.0.1'
tar: '2.0.0'
api_builder:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,10 @@ packages:
dependency: transitive
description:
name: postgres
sha256: "96d7f40e079b96cdbfed13d71c64668cfd79c35bc17223c6b3ac0ca63bff72f0"
sha256: fefbbfe749c6130e5096588b9c4459173684c695952cd7636ab19be76f255469
url: "https://pub.dev"
source: hosted
version: "3.5.8"
version: "3.5.9"
protobuf:
dependency: transitive
description:
Expand Down