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

Support the ability to alter table...rename a column #420

Open
sfc-gh-dsandler opened this issue Jan 21, 2021 · 17 comments
Open

Support the ability to alter table...rename a column #420

sfc-gh-dsandler opened this issue Jan 21, 2021 · 17 comments
Labels
category:resource feature-request Used to mark issues with provider's missing functionalities resource:table Issue connected to the snowflake_table resource

Comments

@sfc-gh-dsandler
Copy link

As a data modeler, I need to rename a column. I would like to use the snowflake_table resource to support this action

From pure-DDL perspective, it would like this:

alter table mydb.myschema.mytbl rename column col1 to column1;

to be supported with a ne property called OLD_NAME in the nested schema for column (as such):

resource "snowflake_table" "my_tbl" {
  name     = "MYTBL"
  database = "MYDB"
  schema   = "MYSCHEMA"
  column   {
            name = "COLUMN1"
            old_name = "COL1"
            type = "STRING" 
  } 
  comment  = "test table"

  depends_on = [snowflake_schema.schema]
}
@sfc-gh-dsandler sfc-gh-dsandler added the feature-request Used to mark issues with provider's missing functionalities label Jan 21, 2021
@kumarjoshi
Copy link

This would be a great feature. Plus, the ability to change data type would be great too.

@juan-yunis
Copy link

I would like to see this feature released any time soon!

@mddataminr
Copy link

mddataminr commented Feb 8, 2022

I would love this functionality too. I imagine the issue is maintaining the column id across each iteration. ie, if you change the name, right now TF is going to treat it like a drop and add. However, if the column had on id field, you could change attributes of it without losing the relationship.

The problem with this is that you'd now have a TF field to create with each column that is only valuable occassionally.

resource "snowflake_table" "my_tbl" {
  name     = "MYTBL"
  database = "MYDB"
  schema   = "MYSCHEMA"
  column   {
            id = "column_1_id"
            name = "COLUMN1"
            type = "STRING" 
  } 
  comment  = "test table"

  depends_on = [snowflake_schema.schema]
}

Or maybe we pass in a column resource instead of the current structure? Something like:

resource "snowflake_table" "my_tbl" {
  name     = "MYTBL"
  database = "MYDB"
  schema   = "MYSCHEMA"
  resource "snowflake_column" "column1"   {
            name = "COLUMN1"
            type = "STRING" 
  } 
  comment  = "test table"

  depends_on = [snowflake_schema.schema]
}

I'm not sure if the option above is syntactically possible in TF, but something along either line would be very helpful.

@sagar-raythatha
Copy link

I would love to have this feature. I am new to Go language but I would be happy to collaborate with anyone to implement this feature.

@fermezz
Copy link

fermezz commented Apr 7, 2022

I'd love to see this one go through. Can we make it happen?

@elikschultz
Copy link

I am also experiencing issues with this. To add a little more color, the problem extends beyond not being able to alter a column in place, as trying to rename a column can also cause unintended changes to other columns that are not being modified.

For instance, let a resource be created as follows:

resource snowflake_table test_test {
  database            = "MY_DATABASE"
  schema              = "MY_SCHEMA"
  name                = "TEST_1"
  column {
      name = "ABC"
      type = "VARCHAR(16777216)"
  }
  column {
      name = "EFG"
      type = "VARCHAR(16777216)"
  }
}

Now let column ABC be renamed to HIJ:

resource snowflake_table test_test {
  database            = "MY_DATABASE"
  schema              = "MY_SCHEMA"
  name                = "TEST_1"
  column {
      name = "HIJ"
      type = "VARCHAR(16777216)"
  }
  column {
      name = "EFG"
      type = "VARCHAR(16777216)"
  }
}

Terraform will drop ABC and add a column named HIJ, but the next time a terraform plan/terraform apply are run, Terraform will think EFG needs to be renamed to HIJ and that HIJ needs to be renamed to EFG, so ultimately column EFG will end up getting deleted and recreated as well.

I like @mddataminr's suggestions, particularly the first one. Similar to @sagar-raythatha I don't have Go experience but would be contribute in any way I can.

@greenantim
Copy link

I would like to see this feature added. If you have a table with a single column and then try to rename the column, terraform apply will fail with an error because it attempts to drop the column which is not allowed when it is the only column in the table.

@franziskakuehn
Copy link

franziskakuehn commented Jan 13, 2023

schema evolution strategy would be highly appreciated

  • rename columns
  • control table schema order
  • add columns
  • version control

@jandanecki
Copy link

I noticed similar behaviour like @elikschultz describe.

I have table definition with sth like

  column {
    name     = "aaa"
    type     = "VARCHAR"
    nullable = false
  }
  column {
    name     = "bbb"
    type     = "VARCHAR"
    nullable = false
  }
  column {
    name     = "ccc"
    type     = "VARCHAR"
    nullable = false
  }

and after each plan I see

      ~ column {
          ~ name     = "aaa" -> "ccc"

        }
      ~ column {
            name     = "bbb"

        }
      ~ column {
          ~ name     = "ccc" -> "aaa"
        }

@samoor64
Copy link

samoor64 commented Nov 2, 2023

Please add this feature, would be extremely helpful!

@realanda
Copy link

realanda commented Jan 9, 2024

+1; please add this feature -- it would be really helpful!
It's critical for a production table with realistic usecases.
We've run into similar problems described in this thread.

@Sophiakorginska
Copy link

+1, having the same issue as @jandanecki. Btw, @jandanecki how are you handling this issue in your terraform code, I have a lot of tables and this behavior overwhelms the output of my terraform plan/apply. Would be glad for any suggestions, thanks!

@sfc-gh-jcieslak sfc-gh-jcieslak added category:resource resource:table Issue connected to the snowflake_table resource labels May 20, 2024
@reachoutbud
Copy link

Bringing this thread back to attention—can this be resolved quickly? We're facing numerous issues due to the lack of this capability.

@sfc-gh-asawicki
Copy link
Collaborator

@reachoutbud
Copy link

@sfc-gh-asawicki
Could you let me know when it will be available on any specific date?

@sfc-gh-asawicki
Copy link
Collaborator

@reachoutbud we do not have any specific date that we can share at the moment.

@sfc-gh-jcieslak
Copy link
Collaborator

sfc-gh-jcieslak commented Oct 23, 2024

Hi all 👋
Recently, we've done more in-depth research on a few topics; one of them was ignoring the list item's order after creation and handling individual list item updates. When applied to the table columns, it should solve most (if not all) of the issues. A more detailed summary of the research should be posted (and announced in the discussions) soon, so stay tuned. The fix for table columns should be adjusted with the overall table refactor for v1 (that is marked as an essential object).

sfc-gh-jcieslak added a commit that referenced this issue Nov 5, 2024
Test cases for changes in lists and sets. From the given time, I only
went through essential cases that consisted of:
- Ignoring the order of list items after creation.
- Having the ability to update an item while ignoring the order.
For the testing, I created a test resource because currently, we don't
have anything to test more complex examples of certain resource
behaviors (temporary providers we create for custom diff testing are not
sufficient in this case). The resource is only added to the resource
list whenever a special env is set (we could remove it entirely and
leave some documentation in the resource file (and acc test file) on how
to prepare for the tests). The imitation of external storage was done by
creating a struct and its global instance (some of the things needed to
be exported since external changes tested in acceptance tests needed to
access those). Certain resource fields were researched to test different
approaches, each is described in the implementation file.

Also added an assert on lists/sets that is able to assert items in order
independent manner (it was needed for the tests of the proposals).

> Note: Only lists were tested, because there was no major issue with
them in current resources. For the lists the following issues were
addressed: #420, #753

## Next pr
- Apply (parameterized tests in object renaming test cases)
#3130 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:resource feature-request Used to mark issues with provider's missing functionalities resource:table Issue connected to the snowflake_table resource
Projects
None yet
Development

No branches or pull requests