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

fix comments lost in generated DDL. #3052

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

chaosue
Copy link

@chaosue chaosue commented Oct 29, 2022

no comments generated on DDL in database, this problem should be fixed, or there's no way to get descriptions for the tables and their columns unless checking the schema golang code, which may lead to impossibility of reverse engineerings and incomprehension for DBA.

Copy link
Member

@a8m a8m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this, @chaosue. It's appreciated! 🙏

I think this change should be added to EntSQL annotation, because I prefer not to trigger migration changes to all users that use the Comment option today. Also, some users, like myself, care only about the code comments and do not need database comments.

@a8m
Copy link
Member

a8m commented Nov 18, 2022

Hey @chaosue! Any update on this PR?

@a8m
Copy link
Member

a8m commented Dec 10, 2022

After a discussion with Cheng on Discord, we think the configuration can be simplified by providing a single annotation in the entsql package to indicate that columns' comments should also be stored on the database schema. For example:

func (T) Annotations() []schema.Annotation {
    return []schema.Annotation{
        // WithComments indicates that all entity comments
        // should be stored in the database schema as well.
        entsql.WithComments(true),
    }
}

Table comments can be implemented once #3164 is merged, and an entsql.Comment(string) annotation can be added in case there are requests for mixed comments (one for code generation, and one for the database).

@huiwanggo
Copy link

table comment ? entsql.WithComments(true), schema.Comment(string) SQL DDL not work。Will this feature be supported? @a8m

@suncle1993
Copy link

table comment ? entsql.WithComments(true), schema.Comment(string) SQL DDL not work。Will this feature be supported? @a8m

if you want to generate table comment and column comment, you can upgrade your entgo to master version. And then use like this:

type T struct {
	ent.Schema
}

func (T) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{Table: "t"},
		entsql.WithComments(true),
		schema.Comment("t is like business unit table"),
	}
}

func (T) Fields() []ent.Field {
	return []ent.Field{
		field.String("name").Comment("unique name"),
		field.String("description").Default("").Comment("xxx"),
	}
}

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

Successfully merging this pull request may close these issues.

None yet

4 participants