Skip to content

Commit

Permalink
Allow schema rename (#450)
Browse files Browse the repository at this point in the history
* [WIP] Allow schema rename

* Revert forcenew to true
  • Loading branch information
bobbyiliev authored Feb 21, 2024
1 parent 1d64549 commit fd37171
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/materialize/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func (b *SchemaBuilder) Create() error {
return b.ddl.exec(q)
}

func (b *SchemaBuilder) Rename(newName string) error {
old := b.QualifiedName()
new := QualifiedName(newName)
return b.ddl.rename(old, new)
}

func (b *SchemaBuilder) Drop() error {
qn := b.QualifiedName()
return b.ddl.drop(qn)
Expand Down
11 changes: 10 additions & 1 deletion pkg/resources/resource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

var schemaSchema = map[string]*schema.Schema{
"name": ObjectNameSchema("schema", true, true),
"name": ObjectNameSchema("schema", true, false),
"database_name": DatabaseNameSchema("schema", false),
"qualified_sql_name": QualifiedNameSchema("schema"),
"comment": CommentSchema(false),
Expand Down Expand Up @@ -153,6 +153,15 @@ func schemaUpdate(ctx context.Context, d *schema.ResourceData, meta interface{})
}
}

if d.HasChange("name") {
oldName, newName := d.GetChange("name")
o := materialize.MaterializeObject{ObjectType: "SCHEMA", Name: oldName.(string), DatabaseName: databaseName}
b := materialize.NewSchemaBuilder(metaDb, o)
if err := b.Rename(newName.(string)); err != nil {
return diag.FromErr(err)
}
}

return schemaRead(ctx, d, meta)
}

Expand Down

0 comments on commit fd37171

Please sign in to comment.