Open
Description
I am running into an issue where ent generatest he schema correctly but the atlas-generated migrations reproduce an issue explained in ent here.
My setup looks like this:
type SomeEntity struct {
ent.Schema
}
func (SomeEntity) Fields() []ent.Field {
return []ent.Field{
field.Time("created_at").Immutable().Annotations(entsql.DefaultExpr("current_timestamp()")),
}
}
I expect this to create the implicit ID column and a timestamp column that's not null and always produces the current timestamp as its value when inserting. Inspecting the schema.go
file generated by ent, the table looks like this:
SomeEntityColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "created_at", Type: field.TypeTime, Default: schema.Expr("current_timestamp()")},
}
Meaning it generated correctly here, omitting the Nullable property. When then generating a migration using atlas that runs against mariadb, the generated .sql f 557D ile for my migration creates the table like this:
CREATE TABLE `some_entity` (`id` bigint NOT NULL AUTO_INCREMENT, `created_at` timestamp NULL DEFAULT (current_timestamp());
This is obiously unintended as there's no mention of null in my declaration of the entity here.
Metadata
Metadata
Assignees
Labels
No labels