File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import 'package:gcloud/service_scope.dart' as ss;
1111import 'package:meta/meta.dart' ;
1212import 'package:postgres/postgres.dart' ;
1313import 'package:pub_dev/service/secret/backend.dart' ;
14+ import 'package:pub_dev/shared/configuration.dart' ;
1415import 'package:pub_dev/shared/env_config.dart' ;
1516
1617final _random = Random .secure ();
@@ -33,11 +34,15 @@ class PrimaryDatabase {
3334 /// the secret backend, connects to it and registers the primary database
3435 /// service in the current scope.
3536 static Future <void > tryRegisterInScope () async {
37+ if (activeConfiguration.isProduction) {
38+ // Production is not configured for postgresql yet.
39+ return ;
40+ }
3641 var connectionString =
3742 envConfig.pubPostgresUrl ??
3843 (await secretBackend.lookup (SecretKey .postgresConnectionString));
39- if (connectionString == null && envConfig.isRunningInAppengine ) {
40- // ignore for now, must throw once we have the environment setup ready
44+ if (connectionString == null && activeConfiguration.isStaging ) {
45+ // Staging may not have the connection string set yet.
4146 return ;
4247 }
4348 // The scope-specific custom database. We are creating a custom database for
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import 'package:_pub_shared/data/package_api.dart';
99import 'package:_pub_shared/data/publisher_api.dart' ;
1010import 'package:_pub_shared/data/task_api.dart' ;
1111import 'package:api_builder/api_builder.dart' ;
12+ import 'package:pub_dev/database/database.dart' ;
1213import 'package:pub_dev/frontend/handlers/atom_feed.dart' ;
1314import 'package:shelf/shelf.dart' ;
1415import 'package:shelf_router/shelf_router.dart' ;
@@ -457,6 +458,7 @@ class PubApi {
457458 Future <Response > debug (Request request) async => debugResponse ({
458459 'package' : packageDebugStats (),
459460 'search' : searchDebugStats (),
461+ 'database' : primaryDatabase != null ,
460462 });
461463
462464 @EndPoint .get ('/packages.json' )
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import 'package:gcloud/service_scope.dart';
1414import 'package:gcloud/storage.dart' ;
1515import 'package:googleapis_auth/auth_io.dart' as auth;
1616import 'package:logging/logging.dart' ;
17+ import 'package:postgres/postgres.dart' ;
1718import 'package:pub_dev/database/database.dart' ;
1819import 'package:pub_dev/package/api_export/api_exporter.dart' ;
1920import 'package:pub_dev/search/handlers.dart' ;
@@ -251,7 +252,16 @@ Future<R> _withPubServices<R>(FutureOr<R> Function() fn) async {
251252 await storageService.verifyBucketExistenceAndAccess (bucketName);
252253 }
253254
254- await PrimaryDatabase .tryRegisterInScope ();
255+ try {
256+ await PrimaryDatabase .tryRegisterInScope ();
257+ } on PgException catch (e, st) {
258+ if (envConfig.isRunningInAppengine) {
259+ // ignore setup issues for now
260+ _logger.warning ('Could not connect to Postgresql database.' , e, st);
261+ } else {
262+ rethrow ;
263+ }
264+ }
255265 registerAccountBackend (AccountBackend (dbService));
256266 registerAdminBackend (AdminBackend (dbService));
257267 registerAnnouncementBackend (AnnouncementBackend ());
You can’t perform that action at this time.
0 commit comments