feat: Take @SerializableField properties into account when generating Migration
(#98)
This commit is contained in:
parent
95f425021a
commit
966622ed2f
2 changed files with 15 additions and 3 deletions
|
@ -125,12 +125,18 @@ Future<OrmBuildContext?> buildOrmContext(
|
|||
buildCtx.resolveSerializedFieldType(field.name),
|
||||
),
|
||||
);
|
||||
|
||||
var isEnumField =
|
||||
(field.type is InterfaceType && field.type.element is EnumElement);
|
||||
var hasColumnAnnotation =
|
||||
(columnAnnotation?.getField('type')?.hasKnownValue ?? false);
|
||||
column = Column(
|
||||
isNullable: column.isNullable,
|
||||
length: column.length,
|
||||
indexType: column.indexType,
|
||||
type: inferColumnType(field.type),
|
||||
// Only infer type when not set by the @Column annotation, for enums
|
||||
type: (isEnumField && hasColumnAnnotation)
|
||||
? column.type
|
||||
: inferColumnType(field.type),
|
||||
defaultValue: column.defaultValue,
|
||||
);
|
||||
|
||||
|
|
|
@ -15,7 +15,13 @@ class HasCarMigration extends Migration {
|
|||
table.serial('id').primaryKey();
|
||||
table.timeStamp('created_at');
|
||||
table.timeStamp('updated_at');
|
||||
table.varChar('color');
|
||||
table.declareColumn(
|
||||
'color',
|
||||
Column(
|
||||
type: ColumnType('varchar'),
|
||||
length: 1,
|
||||
),
|
||||
);
|
||||
table.integer('type').defaultsTo(0);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue