Skip to content

Commit be45256

Browse files
authored
Use the migrations/*.sql script in primary database initialization. (dart-lang#9303)
1 parent 537e607 commit be45256

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

app/lib/database/database.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:math';
99
import 'package:clock/clock.dart';
1010
import 'package:gcloud/service_scope.dart' as ss;
1111
import 'package:meta/meta.dart';
12+
import 'package:path/path.dart' as p;
1213
import 'package:postgres/postgres.dart';
1314
import 'package:pub_dev/database/migration.dart';
1415
import 'package:pub_dev/database/schema.dart';
@@ -127,14 +128,22 @@ class PrimaryDatabase {
127128
).replaceFirst('CREATE TABLE "', 'CREATE TABLE IF NOT EXISTS "');
128129
await _pg.execute(createSql);
129130

130-
// TODO: replace with real migration SQL files
131+
// Read SQL migration files
132+
final files = Directory('migrations')
133+
.listSync()
134+
.whereType<File>()
135+
.where((f) => f.path.endsWith('.sql'))
136+
.toList();
137+
files.sort((a, b) => a.path.compareTo(b.path));
138+
final scripts = files
139+
.map((f) => (name: p.basename(f.path), content: f.readAsStringSync()))
140+
.toList();
141+
131142
await migrateScripts(
132143
target: _adapter,
133144
table: migrationDb.schema_migrations,
134145
migrationsName: 'pub-dev',
135-
scripts: [
136-
(name: 'primary.sql', content: createPrimarySchemaTables(_dialect)),
137-
],
146+
scripts: scripts,
138147
);
139148
}
140149

0 commit comments

Comments
 (0)