applyIfNotAlready method
Applies the provided migration only if it has not yet been applied.
migration
: The migration to apply.
Returns A future that resolves to a boolean
that indicates if the migration was applied.
Implementation
@override
Future<bool> applyIfNotAlready(StmtMigration migration) async {
final rows = await adapter.query(
Statement(
'''
SELECT 1 FROM $migrationsTable
WHERE version = ${queryBuilder.makePositionalParam(1)}''',
[migration.version],
),
);
final shouldApply = rows.isEmpty;
if (shouldApply) {
// This is a new migration because its version number
// is not in our migrations table.
await apply(migration);
}
return shouldApply;
}