suiteDatabaseName function

String suiteDatabaseName({
  1. required String project,
  2. required DateTime now,
  3. required String token,
})

A database name for one suite.

The project makes a stray database traceable to the package that left it, and the minute stamp is how an abandoned one is recognised later: neither Postgres nor MySQL records when a database was created, so the name has to. Without it there would be no way to tell a database a crashed suite left behind from one another suite created a moment ago.

Implementation

String suiteDatabaseName({
  required String project,
  required DateTime now,
  required String token,
}) {
  final slug = _slugOf(project);
  final stamp = minuteStampOf(now);
  // Postgres caps identifiers at 63 characters and MySQL at 64, so one
  // number serves both. The stamp and the token have to survive whatever the
  // project is called, so the slug is what gives way.
  final room = 63 - 'test__${stamp}_$token'.length;
  final trimmed = slug.length > room ? slug.substring(0, room) : slug;
  return 'test_${trimmed}_${stamp}_$token';
}