我有一个只有哈希键的表,我想使用 terraform 添加新的范围键和 GSI,而不影响表中的数据或破坏它。
我知道它有 prevent_destroy = true。我想在不删除或破坏旧数据的情况下更新表。
老一:
resource "aws_dynamodb_table" "table" {
name = "table_example"
hash_key = "hash"
attribute {
name = "hash"
type = "S"
}
lifecycle {
prevent_destroy = true
}
}
更新后:
resource "aws_dynamodb_table" "table" {
name = "table_example"
hash_key = "hash"
range_key = "range"
attribute {
name = "hash"
type = "S"
}
attribute {
name = "range"
type = "S"
}
global_secondary_index {
name = "gsi-example"
hash_key = "range"
projection_type = "ALL"
}
lifecycle {
prevent_destroy = true
}
}
你不能这样做。KeySchema 的 任何更改都需要替换。
您必须备份数据,更新时创建新表,然后重新上传。或者,使用您的排序键创建 GSI。通过这种方式,您可以保持主表不变,并在需要使用排序键时对 GSI 进行操作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句