-
Notifications
You must be signed in to change notification settings - Fork 105
Pass all column attributes to new temporary column when adding a new one to the table #788
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
Conversation
17f7082
to
7c4faa3
Compare
would it be possible to add a test that fails without this change? |
No. At the moment we do not have a standard way to duplicate duplicated columns. First we need to decide how we want to deal with those column, then it can be tested. But I do not see the value of adding a test for this change. Adding more info to a struct is not going to break anything for adding columns. |
Do I understand correctly that you say it is not fixing anything either? |
It is fixing the syntax error. If we fix the syntax error, then we get to the underlying issue which is that we cannot duplicate the column. |
pkg/migrations/op_add_column.go
Outdated
table.AddColumn(o.Column.Name, &schema.Column{ | ||
Name: TemporaryName(o.Column.Name), | ||
}) | ||
tmpColumn := &schema.Column{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid mistakes if a new field is added to schema.Column
we probably want to clone o.Column
then change the name maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are two different Column
types, I cannot really clone them. I added a function we could call to translate from migrations.Column
to schema.Column
.
4785d72
to
699b86d
Compare
The following migration was failing due to several reasons:
This PR fixes the first problem with the migration. The first problem is when
pgroll
adds the new column with the temporary name to the table schema it lacks all column attributes. Thus, if a later operation tries to duplicate this duplicated column it fails because we do not know the type of the column, the default value, etc. The SQL statement generated has a syntax error because of the lack of information: