-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invalid schema steps code without migrations
`stepByStep` and `migrationSteps` take a callback for each schema upgrade as named callbacks. When no arguments are necessary because no schema versions are there, an invalid empty named argument list would be generated (`steps({})`). This fixes the generation to not generate any arguments in that case. Closes #3064
- Loading branch information
Showing
4 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:test_descriptor/test_descriptor.dart' as d; | ||
|
||
import '../../utils.dart'; | ||
import '../utils.dart'; | ||
|
||
void main() { | ||
test('generates valid code when no schemas have been saved', () async { | ||
final project = await TestDriftProject.create([d.dir('drift_schemas/')]); | ||
final path = project.root.path; | ||
await project.runDriftCli([ | ||
'schema', | ||
'steps', | ||
'$path/drift_schemas/', | ||
'$path/schema_versions.dart', | ||
]); | ||
|
||
await d | ||
.file('app/schema_versions.dart', IsValidDartFile(anything)) | ||
.validate(); | ||
}); | ||
|
||
test('generates valid code when only one schema version is saved', () async { | ||
final project = await TestDriftProject.create([ | ||
d.dir( | ||
'drift_schemas/', | ||
[ | ||
d.file('v1.json', ''' | ||
{ | ||
"meta": { | ||
"version": "1.0.0" | ||
}, | ||
"options": { | ||
"store_date_time_values_as_text": false | ||
}, | ||
"entities": [ | ||
{ | ||
"id": 0, | ||
"references": [], | ||
"type": "table", | ||
"data": { | ||
"name": "groups", | ||
"was_declared_in_moor": true, | ||
"columns": [ | ||
{ | ||
"name": "id", | ||
"getter_name": "id", | ||
"moor_type": "int", | ||
"nullable": false, | ||
"customConstraints": "NOT NULL PRIMARY KEY AUTOINCREMENT", | ||
"default_dart": null, | ||
"default_client_dart": null, | ||
"dsl_features": [ | ||
"auto-increment" | ||
] | ||
}, | ||
{ | ||
"name": "name", | ||
"getter_name": "name", | ||
"moor_type": "string", | ||
"nullable": false, | ||
"customConstraints": "NOT NULL", | ||
"default_dart": null, | ||
"default_client_dart": null, | ||
"dsl_features": [] | ||
} | ||
], | ||
"is_virtual": false, | ||
"without_rowid": false | ||
} | ||
}, | ||
], | ||
} | ||
'''), | ||
], | ||
), | ||
]); | ||
final path = project.root.path; | ||
await project.runDriftCli([ | ||
'schema', | ||
'steps', | ||
'$path/drift_schemas/', | ||
'$path/schema_versions.dart', | ||
]); | ||
|
||
await d | ||
.file('app/schema_versions.dart', IsValidDartFile(anything)) | ||
.validate(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ class TestDriftProject { | |
name: app | ||
environment: | ||
sdk: ^2.12.0 | ||
sdk: ^3.0.0 | ||
dependencies: | ||
drift: | ||
|