Skip to content

Commit c5112c5

Browse files
committed
Upgrade package:postgres and use a local socket file to communicate with the dev server.
1 parent f5613f7 commit c5112c5

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

app/lib/database/database.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,21 @@ Future<(String, String?)> _startOrUseLocalPostgresInDocker() async {
100100
throw StateError('Missing connection URL in Appengine environment.');
101101
}
102102

103+
final socketFile = File('/tmp/pub_dev_postgres/run/.s.PGSQL.5432');
104+
103105
// the default connection URL for local server
104106
final url = Uri(
105107
scheme: 'postgresql',
106-
host: 'localhost',
107-
port: 55432,
108108
path: 'postgres',
109109
userInfo: 'postgres:postgres',
110-
queryParameters: {'sslmode': 'disable'},
110+
queryParameters: {
111+
// If the socket file is present, let's try to use it, otherwise connect through the port.
112+
// Both has benefits:
113+
// - (during startup) calling the port is a blocking call and waits until the service is started,
114+
// - (while the service is running) the socket file seems to provide a bit faster connection.
115+
'host': await socketFile.exists() ? socketFile.path : 'localhost:55432',
116+
'sslmode': 'disable',
117+
},
111118
).toString();
112119

113120
try {
@@ -122,6 +129,9 @@ Future<(String, String?)> _startOrUseLocalPostgresInDocker() async {
122129
'Unexpect exit code from tool/start-local-postgres.sh\n${pr.stderr}',
123130
);
124131
}
132+
// The socket file may be present sooner than the server is accepting connections.
133+
// This arbitrary wait is probably enough to have a working server at this point.
134+
await Future.delayed(Duration(seconds: 2));
125135
}
126136
return (url, null);
127137
}

app/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ dependencies:
4949
pana: '0.23.0'
5050
# 3rd-party packages with pinned versions
5151
mailer: '6.5.0'
52-
postgres: '3.5.8'
52+
postgres: '3.5.9'
5353
ulid: '2.0.1'
5454
tar: '2.0.0'
5555
api_builder:

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,10 @@ packages:
661661
dependency: transitive
662662
description:
663663
name: postgres
664-
sha256: "96d7f40e079b96cdbfed13d71c64668cfd79c35bc17223c6b3ac0ca63bff72f0"
664+
sha256: fefbbfe749c6130e5096588b9c4459173684c695952cd7636ab19be76f255469
665665
url: "https://pub.dev"
666666
source: hosted
667-
version: "3.5.8"
667+
version: "3.5.9"
668668
protobuf:
669669
dependency: transitive
670670
description:

0 commit comments

Comments
 (0)