From 6468522b5a8eb6c93cf42bf94270039971d6598a Mon Sep 17 00:00:00 2001 From: Tobe O Date: Mon, 20 Nov 2017 13:09:23 -0500 Subject: [PATCH] Fixed errant build, pushed +5 --- .idea/orm.iml | 1 - .../lib/src/builder/orm/build_context.dart | 2 +- .../lib/src/builder/orm/migration.dart | 13 +++++++++---- angel_orm_generator/test/models/author.up.g.sql | 2 +- angel_orm_generator/test/models/book.up.g.sql | 2 +- angel_orm_generator/test/models/car.up.g.sql | 2 +- angel_orm_generator/test/models/foot.up.g.sql | 2 +- angel_orm_generator/test/models/fruit.up.g.sql | 2 +- angel_orm_generator/test/models/leg.up.g.sql | 2 +- angel_orm_generator/test/models/role.up.g.sql | 2 +- .../test/models/tree.migration.g.dart | 3 ++- angel_orm_generator/test/models/tree.up.g.sql | 4 ++-- angel_orm_generator/test/models/user.up.g.sql | 2 +- 13 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.idea/orm.iml b/.idea/orm.iml index 5ef6ddeb..0afafb50 100644 --- a/.idea/orm.iml +++ b/.idea/orm.iml @@ -16,6 +16,5 @@ - \ No newline at end of file diff --git a/angel_orm_generator/lib/src/builder/orm/build_context.dart b/angel_orm_generator/lib/src/builder/orm/build_context.dart index d2b70516..2bf880dd 100644 --- a/angel_orm_generator/lib/src/builder/orm/build_context.dart +++ b/angel_orm_generator/lib/src/builder/orm/build_context.dart @@ -142,7 +142,7 @@ Future buildContext( ); } - if (column != null) { + if (column != null && column.type == null) { column = new Column( nullable: column.nullable, length: column.length, diff --git a/angel_orm_generator/lib/src/builder/orm/migration.dart b/angel_orm_generator/lib/src/builder/orm/migration.dart index 0c7f105a..b92f0692 100644 --- a/angel_orm_generator/lib/src/builder/orm/migration.dart +++ b/angel_orm_generator/lib/src/builder/orm/migration.dart @@ -48,18 +48,19 @@ class MigrationGenerator extends GeneratorForAnnotation { var clazz = new ClassBuilder('${ctx.modelClassName}Migration', asExtends: new TypeBuilder('Migration')); - clazz..addMethod(buildUpMigration(ctx))..addMethod(buildDownMigration(ctx)); + clazz..addMethod(buildUpMigration(ctx, lib))..addMethod(buildDownMigration(ctx)); return lib..addMember(clazz); } - MethodBuilder buildUpMigration(PostgresBuildContext ctx) { + MethodBuilder buildUpMigration(PostgresBuildContext ctx, LibraryBuilder lib) { var meth = new MethodBuilder('up')..addPositional(_schemaParam); var closure = new MethodBuilder.closure() ..addPositional(parameter('table')); var table = reference('table'); List dup = []; + bool hasOrmImport = false; ctx.columnInfo.forEach((name, col) { var key = ctx.resolveFieldName(name); @@ -81,8 +82,7 @@ class MigrationGenerator extends GeneratorForAnnotation { List positional = [literal(key)]; Map named = {}; - if (autoIdAndDateFields != false && name == 'id') - methodName = 'serial'; + if (autoIdAndDateFields != false && name == 'id') methodName = 'serial'; if (methodName == null) { switch (col.type) { @@ -115,6 +115,11 @@ class MigrationGenerator extends GeneratorForAnnotation { methodName = 'timeStamp'; break; default: + if (!hasOrmImport) { + hasOrmImport = true; + lib.addDirective(new ImportBuilder('package:angel_orm/angel_orm.dart')); + } + ExpressionBuilder provColumn; var colType = new TypeBuilder('Column'); var columnTypeType = new TypeBuilder('ColumnType'); diff --git a/angel_orm_generator/test/models/author.up.g.sql b/angel_orm_generator/test/models/author.up.g.sql index 3ea50c88..4be12feb 100644 --- a/angel_orm_generator/test/models/author.up.g.sql +++ b/angel_orm_generator/test/models/author.up.g.sql @@ -1,5 +1,5 @@ CREATE TEMPORARY TABLE "authors" ( - "id" varchar, + "id" serial, "name" varchar UNIQUE, "created_at" timestamp, "updated_at" timestamp, diff --git a/angel_orm_generator/test/models/book.up.g.sql b/angel_orm_generator/test/models/book.up.g.sql index 125ff38d..465e1f07 100644 --- a/angel_orm_generator/test/models/book.up.g.sql +++ b/angel_orm_generator/test/models/book.up.g.sql @@ -1,5 +1,5 @@ CREATE TEMPORARY TABLE "books" ( - "id" varchar, + "id" serial, "name" varchar, "created_at" timestamp, "updated_at" timestamp, diff --git a/angel_orm_generator/test/models/car.up.g.sql b/angel_orm_generator/test/models/car.up.g.sql index ce6adb74..4cfacf16 100644 --- a/angel_orm_generator/test/models/car.up.g.sql +++ b/angel_orm_generator/test/models/car.up.g.sql @@ -1,5 +1,5 @@ CREATE TEMPORARY TABLE "cars" ( - "id" varchar, + "id" serial, "make" varchar, "description" varchar, "family_friendly" boolean, diff --git a/angel_orm_generator/test/models/foot.up.g.sql b/angel_orm_generator/test/models/foot.up.g.sql index 2635e5f3..8b9583a0 100644 --- a/angel_orm_generator/test/models/foot.up.g.sql +++ b/angel_orm_generator/test/models/foot.up.g.sql @@ -1,5 +1,5 @@ CREATE TEMPORARY TABLE "foots" ( - "id" varchar, + "id" serial, "leg_id" int, "n_toes" int, "created_at" timestamp, diff --git a/angel_orm_generator/test/models/fruit.up.g.sql b/angel_orm_generator/test/models/fruit.up.g.sql index f5b5fefe..558745c8 100644 --- a/angel_orm_generator/test/models/fruit.up.g.sql +++ b/angel_orm_generator/test/models/fruit.up.g.sql @@ -1,5 +1,5 @@ CREATE TEMPORARY TABLE "fruits" ( - "id" varchar, + "id" serial, "tree_id" int, "common_name" varchar, "created_at" timestamp, diff --git a/angel_orm_generator/test/models/leg.up.g.sql b/angel_orm_generator/test/models/leg.up.g.sql index 145ee9bd..6748f79c 100644 --- a/angel_orm_generator/test/models/leg.up.g.sql +++ b/angel_orm_generator/test/models/leg.up.g.sql @@ -1,5 +1,5 @@ CREATE TEMPORARY TABLE "legs" ( - "id" varchar, + "id" serial, "name" varchar, "created_at" timestamp, "updated_at" timestamp, diff --git a/angel_orm_generator/test/models/role.up.g.sql b/angel_orm_generator/test/models/role.up.g.sql index 649ea5dc..0cfadc10 100644 --- a/angel_orm_generator/test/models/role.up.g.sql +++ b/angel_orm_generator/test/models/role.up.g.sql @@ -1,5 +1,5 @@ CREATE TEMPORARY TABLE "roles" ( - "id" varchar, + "id" serial, "name" varchar, "created_at" timestamp, "updated_at" timestamp, diff --git a/angel_orm_generator/test/models/tree.migration.g.dart b/angel_orm_generator/test/models/tree.migration.g.dart index 11ed9d2f..c0feec10 100644 --- a/angel_orm_generator/test/models/tree.migration.g.dart +++ b/angel_orm_generator/test/models/tree.migration.g.dart @@ -5,13 +5,14 @@ // ************************************************************************** import 'package:angel_migration/angel_migration.dart'; +import 'package:angel_orm/angel_orm.dart'; class TreeMigration extends Migration { @override up(Schema schema) { schema.create('trees', (table) { table.serial('id')..primaryKey(); - table.integer('rings')..unique(); + table.declare('rings', new ColumnType('smallint'))..unique(); table.timeStamp('created_at'); table.timeStamp('updated_at'); }); diff --git a/angel_orm_generator/test/models/tree.up.g.sql b/angel_orm_generator/test/models/tree.up.g.sql index a1bde855..0acebf9e 100644 --- a/angel_orm_generator/test/models/tree.up.g.sql +++ b/angel_orm_generator/test/models/tree.up.g.sql @@ -1,6 +1,6 @@ CREATE TEMPORARY TABLE "trees" ( - "id" varchar, - "rings" int UNIQUE, + "id" serial, + "rings" smallint UNIQUE, "created_at" timestamp, "updated_at" timestamp, UNIQUE(rings), diff --git a/angel_orm_generator/test/models/user.up.g.sql b/angel_orm_generator/test/models/user.up.g.sql index 2ac08fb4..b536a5a5 100644 --- a/angel_orm_generator/test/models/user.up.g.sql +++ b/angel_orm_generator/test/models/user.up.g.sql @@ -1,5 +1,5 @@ CREATE TEMPORARY TABLE "users" ( - "id" varchar, + "id" serial, "username" varchar, "password" varchar, "email" varchar,