verify static method
Future<MssqlSchemaReport>
verify(
- MssqlConnection connection, {
- required List<
MssqlTableBinding< bindings,Object?> >
Reports how bindings differ from what connection actually has.
Returns a report rather than throwing. What to do about drift is the application's decision — fail startup in development, log in production, stop only on breaking changes — and a library making that choice for everyone would be wrong for most of them.
Implementation
static Future<MssqlSchemaReport> verify(
MssqlConnection connection, {
required List<MssqlTableBinding<Object?>> bindings,
}) async {
if (bindings.isEmpty) return MssqlSchemaReport(const []);
final reader = MssqlSchemaReader(connection);
final schemas = <String>{for (final b in bindings) b.schema};
final live = <String, MssqlTableSchema>{
for (final table in await reader.readTables(schemas: schemas))
table.qualifiedName.toLowerCase(): table,
};
final differences = <MssqlSchemaDifference>[];
for (final binding in bindings) {
final table = live[binding.qualifiedName.toLowerCase()];
if (table == null) {
differences.add(
MssqlSchemaDifference(
table: binding.qualifiedName,
kind: MssqlDifferenceKind.tableMissing,
severity: MssqlDifferenceSeverity.breaking,
expected: 'a table',
actual: 'nothing',
remedy: 'The table was dropped or renamed; regenerate.',
),
);
continue;
}
differences.addAll(_compare(binding, table));
}
return MssqlSchemaReport(differences);
}