Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the method Comment in schema not migrate db column comment like MySQL #1546

Closed
luckylsx opened this issue May 8, 2021 · 6 comments
Closed

Comments

@luckylsx
Copy link

luckylsx commented May 8, 2021

Hi, first of all, thanks the ent!

When I migrate the schema, I found the content in Comment defined was not migrate the DB。
the schema define like following:

func (Order) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("id"),
		field.Int64("order_id").
			Positive().
			Default(0).
			Unique().
			Comment("订单号"),
		field.Int64("product_id").Positive().Default(0).Comment("商品id"),
    }
}

But after the table migrate, the DDL like this:

CREATE TABLE `orders` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) NOT NULL DEFAULT '0',
  `product_id` bigint(20) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

Expect is:

CREATE TABLE `orders` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `order_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'order id',
  `product_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'product id',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

I want to know How can I migrate with comment or this part is not support?
Thanks!

@a8m
Copy link
Member

a8m commented May 16, 2021

Hey @luckylsx, the Comment value is added to generated code, but not to the schema migration.

We're working on the new migration framework for ent and plan to add support for this.

@waltcow
Copy link

waltcow commented Nov 18, 2022

in most case, sql field comment is needed,
maybe ent can provide a config flag in migrateOption like FieldComment

@a8m
Copy link
Member

a8m commented Nov 18, 2022

Hey @waltcow! Atlas already supports this, and the change is not that big. I suggest changing this PR to be annotation-based. I'll give them another ping to ensure it's active; if not, one of the Ent's team can take it.

@waltcow
Copy link

waltcow commented Nov 18, 2022

Hey @waltcow! Atlas already supports this, and the change is not that big. I suggest changing this PR to be annotation-based. I'll give them another ping to ensure it's active; if not, one of the Ent's team can take it.

I'm agree with you, this Comment annotation nested in entsql annotation is more appropriate

@waltcow
Copy link

waltcow commented Dec 2, 2022

Ent's team can take it now, wait for this fix @a8m

@a8m
Copy link
Member

a8m commented Dec 26, 2022

The issue was resolved with: https://entgo.io/docs/schema-annotations#database-comments.

Update your Ent version to master, and check out this tweet to see an example: https://twitter.com/entgo_io/status/1607394587009589248

@a8m a8m closed this as completed Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants