GORM Playground Link
https://github.com/go-gorm/playground/pull/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)
Comment From: jhartman86
seeing the same issue @khalilsarwari
Comment From: a631807682
https://github.com/go-gorm/gorm/issues/4946 the analysis is good, we need to solve it, it has a little relationship with https://github.com/go-gorm/gorm/pull/6083, we need to correctly handle the size comparison in the custom type.
Comment From: black-06
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?
Comment From: a631807682
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:(-);"
Comment From: black-06
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?
```diff 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
Comment From: a631807682
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? ```diff 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.