Skip to content

feat: adding column comments for postgres#4461

Closed
nionoku wants to merge 2 commits intotypeorm:masterfrom
nionoku:master
Closed

feat: adding column comments for postgres#4461
nionoku wants to merge 2 commits intotypeorm:masterfrom
nionoku:master

Conversation

@nionoku
Copy link

@nionoku nionoku commented Jul 18, 2019

Adding a comment to a column when creating a column for postgres.

Related #4359

@nionoku nionoku changed the title add column comment support for for postgres feat: add column comment support for for postgres Jul 18, 2019
@nionoku
Copy link
Author

nionoku commented Jul 23, 2019

Fix test, comments are now added when creating a table in PostgreSQL.

@rmainwork
Copy link

Just to clarify the title of the PR...

Postgres column comments are already supported. They just don't work. But it's cool that you have a PR to fix this, thank you!

@nionoku nionoku changed the title feat: add column comment support for for postgres feat: adding column comments for postgres Aug 14, 2019
@nionoku
Copy link
Author

nionoku commented Aug 14, 2019

Just to clarify the title of the PR...

Postgres column comments are already supported. They just don't work. But it's cool that you have a PR to fix this, thank you!

Indeed, but the moment I was thinking about the name, there was a slightly different thought in my head. Thanks for comment.

@rmainwork
Copy link

Yeah, not trying to be pedantic - I just thought it was worth pointing out :) <3

@rmainwork
Copy link

Also, just to add - I've noticed that column comments actually already work (sort of) with postgres.....if you create a column it doesn't add the column comment in the migration. But if you somehow change something about that column (the length, the type etc.) the changes written into a migration also include the column comment.

@nionoku
Copy link
Author

nionoku commented Aug 22, 2019

Also, just to add - I've noticed that column comments actually already work (sort of) with postgres.....if you create a column it doesn't add the column comment in the migration. But if you somehow change something about that column (the length, the type etc.) the changes written into a migration also include the column comment.

Yes, a comment for the column was added when changing the model fields.
My PR adds a comment to the column when creating the table :)

@nionoku
Copy link
Author

nionoku commented Aug 29, 2019

@rmainseas hello! Thank you for your attention to the question, regarding the attached issue #3357, I created a small repository, as typeorm I used my fork accordingly, and tested: created an entity, synchronized it with the database, conducted a test: the first module was executed, the second failed (as expected), then I changed the length of the field in the entity and repeated synchronization with the database, and repeated testing - all tests have been passed. That is, the comment is saved (by the way, this functionality is not included in my PR).
https://github.com/nionoku/typeorm-field-options-test

@jjosef
Copy link

jjosef commented Feb 4, 2020

This is really basic and simple, any reason it is not being merged?

@nionoku nionoku requested a review from AlexMesser February 10, 2020 14:43
// create column's comment
if (column.comment) {
upQueries.push(new Query(`COMMENT ON COLUMN ${this.escapePath(table)}.${column.name} IS '${column.comment}'`));
downQueries.push(new Query(`COMMENT ON COLUMN ${this.escapePath(table)}.${column.name} IS '${column.comment}'`));
Copy link
Collaborator

Choose a reason for hiding this comment

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

column.name should be escaped here


table.columns
.filter(it => it.comment)
.forEach(it => sql += ` COMMENT ON COLUMN ${this.escapePath(table)}.${it.name} IS '${it.comment}';`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

it.name should be escaped here

@AlexMesser
Copy link
Collaborator

@nionoku we also need to obtain information about column comments from database and put it into ColumnMetadata for subsequent schema synchronization, like we did it with column charset and collation for example. e.g. in your current PR comment won't be applied on existing column. It also won't be removed once you remove comment from the decorator (or change existing comment)

@imnotjames imnotjames self-requested a review October 8, 2020 06:00
@imnotjames
Copy link
Contributor

Any luck on addressing these issues? Without pulling it into column metadata, synchronize will stop working.

Can you rebase this & fix conflicts, as well?

@imnotjames
Copy link
Contributor

Related issue #3360

Copy link
Contributor

@imnotjames imnotjames left a comment

Choose a reason for hiding this comment

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

This needs to update the change detection code to handle checking for comment changes.

Also comments need to be escaped somehow

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.

5 participants