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,16 +177,22 @@ class MigrationGenerator extends GeneratorForAnnotation<Orm> {
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 ||

View file

@ -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);
}

View file

@ -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');
});

View file

@ -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');
});

View file

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