mirror of
https://github.com/immich-app/drift.git
synced 2026-09-30 13:22:57 +08:00
Allow running make-migrations without tests
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
- Fix invalid schema code for views.
|
||||
- Add the `known_tables` option. It allows defining external tables assumed to be available
|
||||
without including them in the drift-managed schema.
|
||||
- Make-migrations: Add `--no-test` option to disable generating tests.
|
||||
|
||||
## 2.28.3
|
||||
|
||||
|
||||
@@ -17,6 +17,11 @@ import 'package:recase/recase.dart';
|
||||
class MakeMigrationCommand extends DriftCommand {
|
||||
MakeMigrationCommand(super.cli) {
|
||||
argParser.registerExportSchemaStartupCodeOption();
|
||||
argParser.addFlag(
|
||||
'test',
|
||||
help: 'Whether to generate a test file template for migrations',
|
||||
defaultsTo: true,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -96,6 +101,7 @@ targets:
|
||||
cli.exit('`test_dir` must be a relative path. Remove the leading slash');
|
||||
}
|
||||
|
||||
final generateTests = argResults?.flag('test') ?? true;
|
||||
final dumpGeneratedSchemaCode = argResults?.exportSchemaStartupCode;
|
||||
|
||||
/// The root directory where test files for all databases are stored
|
||||
@@ -142,8 +148,11 @@ targets:
|
||||
await writer.writeStepsFile();
|
||||
// Write the generated test databases
|
||||
await writer.writeTestDatabases();
|
||||
// Write the generated test
|
||||
await writer.writeTest();
|
||||
// Write the generated test (unless that option has been disabled).
|
||||
if (generateTests) {
|
||||
await writer.writeTest();
|
||||
}
|
||||
|
||||
await writer.flush();
|
||||
writer.suggestDataMigrationTest();
|
||||
}
|
||||
|
||||
@@ -76,6 +76,53 @@ targets:
|
||||
.file('app/lib/db.steps.dart', IsValidDartFile(anything))
|
||||
.validate();
|
||||
});
|
||||
|
||||
test('without tests', () async {
|
||||
project = await TestDriftProject.create([
|
||||
d.dir('lib', [d.file('db.dart', _dbContent)]),
|
||||
d.file('build.yaml', """
|
||||
targets:
|
||||
\$default:
|
||||
builders:
|
||||
drift_dev:
|
||||
options:
|
||||
databases:
|
||||
my_database: lib/db.dart""")
|
||||
]);
|
||||
await project.runDriftCli(['make-migrations']);
|
||||
expect(
|
||||
d
|
||||
.file('app/drift_schemas/my_database/drift_schema_v1.json')
|
||||
.io
|
||||
.existsSync(),
|
||||
true);
|
||||
// No other files should be created for 1st version
|
||||
expect(d.file('app/test').io.existsSync(), false);
|
||||
|
||||
// Change the db schema and bump the version
|
||||
File(p.join(project.root.path, 'lib/db.dart'))
|
||||
.writeAsStringSync(_dbWithNewColumnBump);
|
||||
await project.runDriftCli(['make-migrations', '--no-test']);
|
||||
expect(
|
||||
d
|
||||
.file('app/drift_schemas/my_database/drift_schema_v2.json')
|
||||
.io
|
||||
.existsSync(),
|
||||
true);
|
||||
// Test files should be created
|
||||
await d.dir('app/test/drift/my_database', [
|
||||
// No test file, option was disabled
|
||||
d.nothing('migration_test.dart'),
|
||||
d.file('generated/schema.dart', IsValidDartFile(anything)),
|
||||
d.file('generated/schema_v1.dart', IsValidDartFile(anything)),
|
||||
d.file('generated/schema_v2.dart', IsValidDartFile(anything)),
|
||||
]).validate();
|
||||
// Steps file should be created
|
||||
await d
|
||||
.file('app/lib/db.steps.dart', IsValidDartFile(anything))
|
||||
.validate();
|
||||
});
|
||||
|
||||
test('schema_dir is respected', () async {
|
||||
project = await TestDriftProject.create([
|
||||
d.dir('lib', [d.file('db.dart', _dbContent)]),
|
||||
|
||||
Reference in New Issue
Block a user