verifySnapshot static method

Future<MssqlSchemaReport> verifySnapshot(
  1. MssqlConnection connection,
  2. MssqlSchemaSnapshot snapshot, {
  3. bool includeViews = true,
})

Reports how the live database differs from snapshot.

This is what a standalone check_schema runs. Comparing the whole snapshot rather than a header hash is what lets it name the column, its old and new type, and why the change matters — a hash can only say that something moved.

Implementation

static Future<MssqlSchemaReport> verifySnapshot(
  MssqlConnection connection,
  MssqlSchemaSnapshot snapshot, {
  bool includeViews = true,
}) async {
  final ambiguous = snapshot.ambiguousNames;
  if (ambiguous.isNotEmpty) {
    throw StateError(
      'The snapshot holds names that differ only in case '
      '(${ambiguous.join('; ')}). Comparing them would mean folding them '
      'together, which is wrong for a case-sensitive collation.',
    );
  }
  final schemas = <String>{for (final t in snapshot.tables) t.schema};
  if (schemas.isEmpty) return MssqlSchemaReport(const []);
  final live = await MssqlSchemaReader(
    connection,
  ).readTables(schemas: schemas, includeViews: includeViews);
  return MssqlSchemaReport(
    diffSchemas(expected: snapshot.tables, actual: live),
  );
}