From 6e61ec355abb8fc272ef712753ac1da52ff3fe17 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Thu, 25 Apr 2019 18:47:26 -0400 Subject: [PATCH] Remove build.yaml targets in gen --- .../lib/src/migration_generator.dart | 14 ++++++++++---- angel_orm_generator/lib/src/orm_build_context.dart | 6 ++++++ angel_orm_test/lib/src/models/book.g.dart | 4 +--- angel_orm_test/lib/src/models/has_car.g.dart | 2 +- angel_orm_test/lib/src/models/unorthodox.g.dart | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/angel_orm_generator/lib/src/migration_generator.dart b/angel_orm_generator/lib/src/migration_generator.dart index 4355353a..a66fa3b8 100644 --- a/angel_orm_generator/lib/src/migration_generator.dart +++ b/angel_orm_generator/lib/src/migration_generator.dart @@ -177,16 +177,22 @@ class MigrationGenerator extends GeneratorForAnnotation { refer('RawSql').constInstance([literalString(value)]); } else if (type is InterfaceType && type.element.isEnum) { // Default to enum index. - var index = - ConstantReader(defaultValue).read('index').intValue; - defaultExpr = literalNum(index); + try { + var index = + ConstantReader(defaultValue).read('index')?.intValue; + if (index != null) defaultExpr = literalNum(index); + } catch (_) { + // Extremely weird error occurs here: `Not an instance of int`. + // Definitely an analyzer issue. + } } else { defaultExpr = new CodeExpression( new Code(dartObjectToString(defaultValue)), ); } - cascade.add(refer('defaultsTo').call([defaultExpr])); + if (defaultExpr != null) + cascade.add(refer('defaultsTo').call([defaultExpr])); } if (col.indexType == IndexType.primaryKey || diff --git a/angel_orm_generator/lib/src/orm_build_context.dart b/angel_orm_generator/lib/src/orm_build_context.dart index f350d600..ad29dc94 100644 --- a/angel_orm_generator/lib/src/orm_build_context.dart +++ b/angel_orm_generator/lib/src/orm_build_context.dart @@ -41,6 +41,7 @@ FieldElement findPrimaryFieldInList( var column = reviveColumn(new ConstantReader(columnAnnotation)); // print( // ' * Found column on ${field.name} with indexType = ${column.indexType}'); + // print(element.metadata); if (column.indexType == IndexType.primaryKey) return field; } } @@ -301,6 +302,11 @@ Column reviveColumn(ConstantReader cr) { cr.peek('indexType')?.objectValue?.getField('index')?.toIntValue() ?? IndexType.none.index]; + if (const TypeChecker.fromRuntime(PrimaryKey) + .isAssignableFromType(cr.objectValue.type)) { + indexType = IndexType.primaryKey; + } + if (columnObj != null) { columnType = new _ColumnType(columnObj); } diff --git a/angel_orm_test/lib/src/models/book.g.dart b/angel_orm_test/lib/src/models/book.g.dart index 95b71133..014c0e77 100644 --- a/angel_orm_test/lib/src/models/book.g.dart +++ b/angel_orm_test/lib/src/models/book.g.dart @@ -30,9 +30,7 @@ class AuthorMigration extends Migration { up(Schema schema) { schema.create('authors', (table) { table.serial('id')..primaryKey(); - table.varChar('name', length: 255) - ..defaultsTo('Tobe Osakwe') - ..unique(); + table.varChar('name', length: 255)..defaultsTo('Tobe Osakwe'); table.timeStamp('created_at'); table.timeStamp('updated_at'); }); diff --git a/angel_orm_test/lib/src/models/has_car.g.dart b/angel_orm_test/lib/src/models/has_car.g.dart index 24465baa..0357ab1d 100644 --- a/angel_orm_test/lib/src/models/has_car.g.dart +++ b/angel_orm_test/lib/src/models/has_car.g.dart @@ -11,7 +11,7 @@ class HasCarMigration extends Migration { up(Schema schema) { schema.create('has_cars', (table) { table.serial('id')..primaryKey(); - table.integer('type')..defaultsTo(0); + table.integer('type'); table.timeStamp('created_at'); table.timeStamp('updated_at'); }); diff --git a/angel_orm_test/lib/src/models/unorthodox.g.dart b/angel_orm_test/lib/src/models/unorthodox.g.dart index 98a24a17..676f8ac5 100644 --- a/angel_orm_test/lib/src/models/unorthodox.g.dart +++ b/angel_orm_test/lib/src/models/unorthodox.g.dart @@ -10,7 +10,7 @@ class UnorthodoxMigration extends Migration { @override up(Schema schema) { schema.create('unorthodoxes', (table) { - table.varChar('name')..primaryKey(); + table.varChar('name'); }); }