-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow schema rename #450
Allow schema rename #450
Conversation
@@ -13,7 +13,7 @@ import ( | |||
) | |||
|
|||
var schemaSchema = map[string]*schema.Schema{ | |||
"name": ObjectNameSchema("schema", true, true), | |||
"name": ObjectNameSchema("schema", true, false), |
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.
The problem here is that if we change the schema name to not be ForceNew, then if someone actually wants to change the name of the schema they will not be able to do that. So there needs to be a mechanism where schema renames are allowed but also they don't break all of the objects that reference that schema.
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.
Yeah. How does this work in other database providers, like PostgreSQL and Snowflake?
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.
Snowflake does force recreate the dependant objects, eg:
They also have some other bugs that affect the way they handle schemas:
The Postgres providers that I've checked do not seem to support this at all, eg. they don't have resources that depend on schema names.
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.
One option would be to leave the ForceNew as true and then instruct users that they can add an ignore block to the child objects, eg:
resource "materialize_database" "db" {
name = "db"
}
resource "materialize_schema" "schema" {
name = "test_schema3"
database_name = materialize_database.db.name
}
resource "materialize_table" "test_table" {
name = "test_table"
schema_name = materialize_schema.schema.name
# Ignore schema name rename
lifecycle {
ignore_changes = [schema_name]
}
database_name = materialize_database.db.name
column {
name = "id"
type = "int"
}
column {
name = "name"
type = "text"
}
}
That way the schema rename will work as expected, and the child resources will not be recreated and after the rename, the ignore block can be removed as the schema name will be updated correctly in the state file thanks to the read func.
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.
I'm way out of my depth here, but it seems like the easy answer is to not do anything special, which means users have to add the lifecycle ignore blocks like you suggested. If we do decide to set ForceNew to false, what other mechanism would we provide for schema renames?
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.
Might be question we could ask the cloud team, maybe they have suggestions since they have a lot of collective IaC experience?
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.
After the discussion, I would say that we can take the following plan of action:
- For the short term: Merge this PR as it is as it will still allow people to rename schemas without having to drop all of their dependent objects some manual work by using the
lifecycle { ignore_changes = [schema_name] }
syntax - For the long term: Implement
schema_id
which can be used along sideschema_name
, I've opened a tracking issue for this as it will be a pretty significant change as 80% of all resources actually depend on theschema_name
at the moment: [Epic] Introduceschema_id
for all object that useschema_name
#472
Open to suggestions! Tagging @jubrad as schema_id
was his idea 👏
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.
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.
Oh yes, sorry, absolutely okay with this! It's great to have an MVP!
b469950
to
3ebe420
Compare
31656df
to
c677578
Compare
Implementing the schema rename by itself is straight forward, the challenging part is all of the handling of all of the dependant resources, eg all resources that use the
SchemaNameSchema
.Closes #334