Skip to content

Commit a647484

Browse files
author
Ivan Dlugos
committed
add generator v0.5 -> v0.6 upgrade helper, checking the existence of an old objectbox-model.json
1 parent b5192e4 commit a647484

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

generator/lib/src/code_builder.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ class CodeBuilder extends Builder {
5555
}
5656

5757
Future<ModelInfo> updateModel(List<ModelEntity> entities, BuildStep buildStep) async {
58+
{
59+
// TODO temporary v0.5 -> v0.6 update - check if the model file exists in the old location
60+
final oldJson = AssetId(buildStep.inputId.package, "objectbox-model.json");
61+
if (File(oldJson.path).existsSync()) {
62+
throw StateError(""
63+
"Found objectbox-model.json in the package root. This is the old behaviour before ObjectBox v0.6\n"
64+
"Please move objectbox-model.json to lib/objectbox-model.json and run the build_runner again.\n");
65+
}
66+
}
67+
5868
// load an existing model or initialize a new one
5969
ModelInfo model;
6070
final jsonId = AssetId(buildStep.inputId.package, dir(buildStep) + "/" + jsonFile);
@@ -81,8 +91,8 @@ class CodeBuilder extends Builder {
8191
void updateCode(ModelInfo model, List<String> infoFiles, BuildStep buildStep) async {
8292
// transform "/lib/path/entity.objectbox.info" to "path/entity.dart"
8393
final imports = infoFiles
84-
.map((file) => file.replaceFirst(EntityResolver.suffix, ".dart").replaceFirst(dir(buildStep) + "/", ""))
85-
.toList();
94+
.map((file) => file.replaceFirst(EntityResolver.suffix, ".dart").replaceFirst(dir(buildStep) + "/", ""))
95+
.toList();
8696

8797
var code = CodeChunks.objectboxDart(model, imports);
8898
code = DartFormatter().format(code);
@@ -141,7 +151,7 @@ class CodeBuilder extends Builder {
141151
// then remove all properties not present anymore in readEntity
142152
entityInModel.properties.where((p) => entity.findSameProperty(p) == null).forEach((p) {
143153
log.warning(
144-
"Property ${entity.name}.${p.name}(${p.id.toString()}) not found in the code, removing from the model");
154+
"Property ${entity.name}.${p.name}(${p.id.toString()}) not found in the code, removing from the model");
145155
entityInModel.removeProperty(p);
146156
});
147157

0 commit comments

Comments
 (0)