Skip to content

Commit

Permalink
Support changing cluster_by on a new column (#1605)
Browse files Browse the repository at this point in the history
Move the cluster_by logic when updating a table to take place *after* columns are added.
  • Loading branch information
michael-robbins authored Mar 30, 2023
1 parent caa461f commit edc7fd6
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/resources/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,21 +639,6 @@ func UpdateTable(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error updating table comment on %v", d.Id())
}
}
if d.HasChange("cluster_by") {
cb := expandStringList(d.Get("cluster_by").([]interface{}))

var q string
if len(cb) != 0 {
builder.WithClustering(cb)
q = builder.ChangeClusterBy(builder.GetClusterKeyString())
} else {
q = builder.DropClustering()
}

if err := snowflake.Exec(db, q); err != nil {
return fmt.Errorf("error updating table clustering on %v", d.Id())
}
}
if d.HasChange("column") {
t, new := d.GetChange("column")
removed, added, changed := getColumns(t).diffs(getColumns(new))
Expand Down Expand Up @@ -715,6 +700,21 @@ func UpdateTable(d *schema.ResourceData, meta interface{}) error {
}
}
}
if d.HasChange("cluster_by") {
cb := expandStringList(d.Get("cluster_by").([]interface{}))

var q string
if len(cb) != 0 {
builder.WithClustering(cb)
q = builder.ChangeClusterBy(builder.GetClusterKeyString())
} else {
q = builder.DropClustering()
}

if err := snowflake.Exec(db, q); err != nil {
return fmt.Errorf("error updating table clustering on %v", d.Id())
}
}
if d.HasChange("primary_key") {
opk, npk := d.GetChange("primary_key")

Expand Down

0 comments on commit edc7fd6

Please sign in to comment.