@@ -10,9 +10,11 @@ import 'package:clock/clock.dart';
1010import 'package:gcloud/service_scope.dart' as ss;
1111import 'package:meta/meta.dart' ;
1212import 'package:postgres/postgres.dart' ;
13+ import 'package:pub_dev/database/schema.dart' ;
1314import 'package:pub_dev/service/secret/backend.dart' ;
1415import 'package:pub_dev/shared/configuration.dart' ;
1516import 'package:pub_dev/shared/env_config.dart' ;
17+ import 'package:typed_sql/typed_sql.dart' ;
1618
1719final _random = Random .secure ();
1820
@@ -27,8 +29,10 @@ PrimaryDatabase? get primaryDatabase =>
2729/// Access to the primary database connection and object mapping.
2830class PrimaryDatabase {
2931 final Pool _pg;
32+ final DatabaseAdapter _adapter;
33+ final Database <PrimarySchema > db;
3034
31- PrimaryDatabase ._(this ._pg);
35+ PrimaryDatabase ._(this ._pg, this ._adapter, this .db );
3236
3337 /// Gets the connection string either from the environment variable or from
3438 /// the secret backend, connects to it and registers the primary database
@@ -77,10 +81,14 @@ class PrimaryDatabase {
7781
7882 static Future <PrimaryDatabase > _fromConnectionString (String value) async {
7983 final pg = Pool .withUrl (value);
80- return PrimaryDatabase ._(pg);
84+ final adapter = DatabaseAdapter .postgres (pg);
85+ final db = Database <PrimarySchema >(adapter, SqlDialect .postgres ());
86+ await db.createTables ();
87+ return PrimaryDatabase ._(pg, adapter, db);
8188 }
8289
8390 Future <void > close () async {
91+ await _adapter.close ();
8492 await _pg.close ();
8593 }
8694
0 commit comments