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

Down SQL in 'alter column' operation that renames a column should use the new column name #350

Closed
andrew-farries opened this issue May 3, 2024 · 0 comments · Fixed by #354
Labels
bug Something isn't working

Comments

@andrew-farries
Copy link
Collaborator

When a column is renamed and modified in some other way that requires an up and down SQL (eg changing its type), migration authors should be able to refer to the column in the down SQL by the new name of the column, as in this example:

{
  "name": "02_alter_column",
  "operations": [
    {
      "alter_column": {
        "table": "products",
        "column": "age",
        "name": "product_age",
        "type": "integer",
        "up": "CAST(age AS integer)",
        "down": "CAST(product_age AS text)"
      }
    }
  ]
}

Currently, the above migration will fail because the down SQL in the above example needs to be written as though the column were still called age, ie the column name before the rename.

For alter column operations involving a rename, the generated down trigger should change in such a way that the name of column in the user supplied down SQL can use the renamed column name.

@andrew-farries andrew-farries added the bug Something isn't working label May 3, 2024
andrew-farries added a commit that referenced this issue May 16, 2024
…olumn (#354)

Ensure that 'alter column' operations that rename a column and also
specify `down` SQL (such as those that alter some other column attribute
at the time of the rename) must use the new name of the column in the
`down` SQL.

Without this change, the `down` SQL would require the use of the old
column name.

Fixes #350
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant