8000 Timestamp field in Migrations generated as NULL with ent 0.14 and MariaDB 11.7 · Issue #3532 · ariga/atlas · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 8000
Timestamp field in Migrations generated as NULL with ent 0.14 and MariaDB 11.7 #3532
Open
@MansenC

Description

@MansenC

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0