Remove build.yaml targets in gen

This commit is contained in:
Tobe O 2019-04-25 18:47:26 -04:00
parent 7c5eef9dc2
commit 6e61ec355a
5 changed files with 19 additions and 9 deletions

View file

@ -177,15 +177,21 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
refer('RawSql').constInstance([literalString(value)]); refer('RawSql').constInstance([literalString(value)]);
} else if (type is InterfaceType && type.element.isEnum) { } else if (type is InterfaceType && type.element.isEnum) {
// Default to enum index. // Default to enum index.
try {
var index = var index =
ConstantReader(defaultValue).read('index').intValue; ConstantReader(defaultValue).read('index')?.intValue;
defaultExpr = literalNum(index); if (index != null) defaultExpr = literalNum(index);
} catch (_) {
// Extremely weird error occurs here: `Not an instance of int`.
// Definitely an analyzer issue.
}
} else { } else {
defaultExpr = new CodeExpression( defaultExpr = new CodeExpression(
new Code(dartObjectToString(defaultValue)), new Code(dartObjectToString(defaultValue)),
); );
} }
if (defaultExpr != null)
cascade.add(refer('defaultsTo').call([defaultExpr])); cascade.add(refer('defaultsTo').call([defaultExpr]));
} }

View file

@ -41,6 +41,7 @@ FieldElement findPrimaryFieldInList(
var column = reviveColumn(new ConstantReader(columnAnnotation)); var column = reviveColumn(new ConstantReader(columnAnnotation));
// print( // print(
// ' * Found column on ${field.name} with indexType = ${column.indexType}'); // ' * Found column on ${field.name} with indexType = ${column.indexType}');
// print(element.metadata);
if (column.indexType == IndexType.primaryKey) return field; if (column.indexType == IndexType.primaryKey) return field;
} }
} }
@ -301,6 +302,11 @@ Column reviveColumn(ConstantReader cr) {
cr.peek('indexType')?.objectValue?.getField('index')?.toIntValue() ?? cr.peek('indexType')?.objectValue?.getField('index')?.toIntValue() ??
IndexType.none.index]; IndexType.none.index];
if (const TypeChecker.fromRuntime(PrimaryKey)
.isAssignableFromType(cr.objectValue.type)) {
indexType = IndexType.primaryKey;
}
if (columnObj != null) { if (columnObj != null) {
columnType = new _ColumnType(columnObj); columnType = new _ColumnType(columnObj);
} }

View file

@ -30,9 +30,7 @@ class AuthorMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('authors', (table) { schema.create('authors', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.varChar('name', length: 255) table.varChar('name', length: 255)..defaultsTo('Tobe Osakwe');
..defaultsTo('Tobe Osakwe')
..unique();
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
}); });

View file

@ -11,7 +11,7 @@ class HasCarMigration extends Migration {
up(Schema schema) { up(Schema schema) {
schema.create('has_cars', (table) { schema.create('has_cars', (table) {
table.serial('id')..primaryKey(); table.serial('id')..primaryKey();
table.integer('type')..defaultsTo(0); table.integer('type');
table.timeStamp('created_at'); table.timeStamp('created_at');
table.timeStamp('updated_at'); table.timeStamp('updated_at');
}); });

View file

@ -10,7 +10,7 @@ class UnorthodoxMigration extends Migration {
@override @override
up(Schema schema) { up(Schema schema) {
schema.create('unorthodoxes', (table) { schema.create('unorthodoxes', (table) {
table.varChar('name')..primaryKey(); table.varChar('name');
}); });
} }