@@ -54,11 +54,17 @@ abstract class SchemaVerifier<DB extends CommonDatabase> {
5454 /// the database into the expected schema. If the comparison fails, a
5555 /// [SchemaMismatch] exception will be thrown.
5656 ///
57- /// If [validateDropped] is enabled (defaults to `false` ), the method also
58- /// validates that no further tables, triggers or views apart from those
59- /// expected exist.
60- Future <void > migrateAndValidate (GeneratedDatabase db, int expectedVersion,
61- {bool validateDropped = false });
57+ /// The [ValidationOptions] can be used to make the schema validation more
58+ /// strict (e.g. by enabling [ValidationOptions.validateDropped] to ensure
59+ /// that no old tables continue to exist if they're not referenced in the new
60+ /// schema) or more lenient (e.g. by disabling
61+ /// [ValidationOptions.validateColumnConstraints] ).
62+ Future <void > migrateAndValidate (
63+ GeneratedDatabase db,
64+ int expectedVersion, {
65+ ValidationOptions options = const ValidationOptions (),
66+ @Deprecated ('Use field in ValidationOptions instead' ) bool ? validateDropped,
67+ });
6268
6369 /// Utility function used by generated tests to verify that migrations
6470 /// modify the database schema as expected.
@@ -156,3 +162,36 @@ class InitializedSchema<DB extends CommonDatabase> {
156162 /// forgetting to call [close] does not have terrible side-effects.
157163 void close () => rawDatabase.dispose ();
158164}
165+
166+ /// Options that control how schemas are compared to find mismatches.
167+ final class ValidationOptions {
168+ /// When enabled (defaults to `false` ), validate that no furhter tables,
169+ /// triggers or views apart from those expected exist.
170+ final bool validateDropped;
171+
172+ /// When enabled (defualts to `true` ), validate column constraints.
173+ ///
174+ /// When disabled, schema verification passes even without
175+ final bool validateColumnConstraints;
176+
177+ const ValidationOptions ({
178+ this .validateDropped = false ,
179+ this .validateColumnConstraints = true ,
180+ });
181+
182+ /// Returns new [ValidationOptions] with the [ValidationOptions.validateDropped]
183+ /// field replaced if [validateDropped] is not null.validateDropped
184+ ///
185+ /// This is used for backwards-compatibility when [validateDropped] was the
186+ /// only option and no [ValidationOptions] class existed.
187+ ValidationOptions applyDeprecatedValidateDroppedParam (bool ? validateDropped) {
188+ if (validateDropped case final changed? ) {
189+ return ValidationOptions (
190+ validateColumnConstraints: validateColumnConstraints,
191+ validateDropped: changed,
192+ );
193+ } else {
194+ return this ;
195+ }
196+ }
197+ }
0 commit comments