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

Generated column should not be altered during automigration #5534

Open
khalilsarwari opened this issue Jul 21, 2022 · 6 comments
Open

Generated column should not be altered during automigration #5534

khalilsarwari opened this issue Jul 21, 2022 · 6 comments
Assignees

Comments

@khalilsarwari
Copy link

GORM Playground Link

go-gorm/playground#496

Description

Once a generated column is created in postgres, it cannot be altered so it should be skipped during automigration.

This is also discussed here

Currently the automigrator tries to alter the column, resulting in an error like:

migrator.go:291 ERROR: syntax error at or near "GENERATED" (SQLSTATE 42601)

@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Jul 21, 2022
@jhartman86
Copy link

seeing the same issue @khalilsarwari

@a631807682
Copy link
Member

#4946 the analysis is good, we need to solve it, it has a little relationship with #6083, we need to correctly handle the size comparison in the custom type.

@black-06
Copy link
Contributor

black-06 commented Mar 8, 2023

We can support a struct tag migration. it is similar to <-

optional value description
"create" Only allow migrator to create column if it doesn't existed
"update" Only allow migrator to alter column
"false"/"-" no migrate permission
"" create and update permission

For non-breaking API changes, it will not work if -:migration is set.

How about this idea?

@a631807682
Copy link
Member

a631807682 commented Apr 13, 2023

This seems to be a size matching error. (As far as I know, if size is included), the type size will be composed of numbers or letters with parentheses at the end, not after a space. I'm not sure I know all the cases, is it possible we can fix it by modifying the regex?

gorm:"->;type:bool GENERATED ALWAYS AS (some_expression) STORED;default:(-);"

gorm:"->;type:bool(should appear here) GENERATED ALWAYS AS (some_expression) STORED;default:(-);"

@black-06
Copy link
Contributor

This seems to be a size matching error. (As far as I know, if size is included), the type size will be composed of numbers or letters with parentheses at the end, not after a space. I'm not sure I know all the cases, is it possible we can fix it by modifying the regex?

gorm:"->;type:bool GENERATED ALWAYS AS (some_expression) STORED;default:(-);"

gorm:"->;type:bool(should appear here) GENERATED ALWAYS AS (some_expression) STORED;default:(-);"

It's possible. But I think it's cool to add perm for migration

@a631807682
Copy link
Member

This seems to be a size matching error. (As far as I know, if size is included), the type size will be composed of numbers or letters with parentheses at the end, not after a space. I'm not sure I know all the cases, is it possible we can fix it by modifying the regex?

gorm:"->;type:bool GENERATED ALWAYS AS (some_expression) STORED;default:(-);"

gorm:"->;type:bool(should appear here) GENERATED ALWAYS AS (some_expression) STORED;default:(-);"

It's possible. But I think it's cool to add perm for migration

Usually, the addition of feat needs to have a real scene, and feat cannot be added to avoid bugs.
This feat seems unnecessary when AutoMigrator has no bugs, but unfortunately it does have many bugs, and it is impossible to solve them in a short time, so i am not sure whether this temporary feat is needed to avoid them.

bfabio added a commit to bfabio/developers-italia-api that referenced this issue Aug 23, 2023
bfabio added a commit to bfabio/developers-italia-api that referenced this issue Aug 23, 2023
bfabio added a commit to bfabio/developers-italia-api that referenced this issue Aug 23, 2023
bfabio added a commit to bfabio/developers-italia-api that referenced this issue Aug 23, 2023
bfabio added a commit to italia/developers-italia-api that referenced this issue Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants