import 'package:drift_dev/api/migrations_native.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tane/db/database.dart';

import 'schema/schema.dart';

void main() {
  late SchemaVerifier verifier;

  setUpAll(() {
    verifier = SchemaVerifier(GeneratedHelper());
  });

  test('freshly created database matches the exported schema v9', () async {
    final schema = await verifier.schemaAt(9);
    final db = AppDatabase(schema.newConnection());
    await verifier.migrateAndValidate(db, 9);
    await db.close();
  });

  // Every historical version upgrades cleanly to the current schema (v9).
  for (var from = 1; from <= 8; from++) {
    test('upgrades v$from → v9 and matches the fresh schema', () async {
      final connection = await verifier.startAt(from);
      final db = AppDatabase(connection);
      await verifier.migrateAndValidate(db, 9);
      await db.close();
    });
  }
}
