validateApplied method
Future<List<StmtMigration> >
validateApplied(
- List<
StmtMigration> migrations, - List<
MigrationRecord> existing
inherited
Implementation
Future<List<StmtMigration>> validateApplied(
List<StmtMigration> migrations,
List<MigrationRecord> existing,
) async {
// `existing` migrations may contain migrations
// received at runtime that are not bundled in the app
// i.e. those are not present in `migrations`
// Thus, `existing` may be longer than `migrations`.
// So we should only compare a prefix of `existing`
// that has the same length as `migrations`
// take a slice of `existing` migrations
// that will be checked against `migrations`
final existingPrefix = existing.slice(0, migrations.length);
// First we validate that the existing records are the first migrations.
for (var i = 0; i < existingPrefix.length; i++) {
final migrationRecord = existingPrefix[i];
final version = migrationRecord.version;
final migration = migrations[i];
if (migration.version != version) {
throw SatelliteException(
SatelliteErrorCode.unknownSchemaVersion,
kSchemaVersionErrorMsg,
);
}
}
// Then we can confidently slice and return the non-existing.
return migrations.slice(existingPrefix.length);
}