Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions app/lib/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:gcloud/service_scope.dart' as ss;
import 'package:meta/meta.dart';
import 'package:postgres/postgres.dart';
import 'package:pub_dev/service/secret/backend.dart';
import 'package:pub_dev/shared/configuration.dart';
import 'package:pub_dev/shared/env_config.dart';

final _random = Random.secure();
Expand All @@ -33,11 +34,15 @@ class PrimaryDatabase {
/// the secret backend, connects to it and registers the primary database
/// service in the current scope.
static Future<void> tryRegisterInScope() async {
if (activeConfiguration.isProduction) {
// Production is not configured for postgresql yet.
return;
}
var connectionString =
envConfig.pubPostgresUrl ??
(await secretBackend.lookup(SecretKey.postgresConnectionString));
if (connectionString == null && envConfig.isRunningInAppengine) {
// ignore for now, must throw once we have the environment setup ready
if (connectionString == null && activeConfiguration.isStaging) {
// Staging may not have the connection string set yet.
return;
}
// The scope-specific custom database. We are creating a custom database for
Expand Down
2 changes: 2 additions & 0 deletions app/lib/frontend/handlers/pubapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:_pub_shared/data/package_api.dart';
import 'package:_pub_shared/data/publisher_api.dart';
import 'package:_pub_shared/data/task_api.dart';
import 'package:api_builder/api_builder.dart';
import 'package:pub_dev/database/database.dart';
import 'package:pub_dev/frontend/handlers/atom_feed.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf_router/shelf_router.dart';
Expand Down Expand Up @@ -457,6 +458,7 @@ class PubApi {
Future<Response> debug(Request request) async => debugResponse({
'package': packageDebugStats(),
'search': searchDebugStats(),
'database': primaryDatabase != null,
});

@EndPoint.get('/packages.json')
Expand Down
11 changes: 10 additions & 1 deletion app/lib/service/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,16 @@ Future<R> _withPubServices<R>(FutureOr<R> Function() fn) async {
await storageService.verifyBucketExistenceAndAccess(bucketName);
}

await PrimaryDatabase.tryRegisterInScope();
try {
await PrimaryDatabase.tryRegisterInScope();
} catch (e, st) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please catch the specific error.

if (envConfig.isRunningInAppengine) {
// ignore setup issues for now
_logger.warning('Could not connect to Postgresql database.', e, st);
} else {
rethrow;
}
}
registerAccountBackend(AccountBackend(dbService));
registerAdminBackend(AdminBackend(dbService));
registerAnnouncementBackend(AnnouncementBackend());
Expand Down