英文:
How to use old schema(with no new columns) with a kind/table having new columns added, after a rollback
问题
我在Google Cloud Datastore的一种数据中添加了一些新的列,并且Golang的新模式正在读取这些列。现在,如果由于某些问题需要回滚到旧的模式,其中这些新列不存在,那么最理想的策略是什么?我有两个选项:
1)编写一个脚本,在需要回滚时从GDS中删除新列。
2)添加一个类似标志的功能来禁用新列,以便该数据类型可以与旧的模式一起使用。我不确定是否存在这个解决方案。
哪个是最理想的选择,如何实现它们?
英文:
I have added some new columns in a kind in Google Cloud Datastore and new schema in Golang is reading that. Now if I want to rollback binaries to older schema because of some issue where these new columns do not exist, what is the ideal strategy for that? I have two options:
- Write a script to delete new column from GDS when I want to rollback
- Add a flag kind of feature to disable new columns so that the kind works with the older schema. I am not sure about this solution if is present.
Which is the ideal one and how to achieve them?
答案1
得分: 0
我能够找到一个名为omitempty
的变量,可以在这些情况下帮助。我在这个博客上找到了一个很好的解释:https://www.sohamkamani.com/golang/omitempty/。
如果我在数据库中存储一个带有它的默认零值的列,那么在读取JSON时,omitempty将不会读取它。通过这种方式,我将能够在多个数据库模式中使用相同的Golang模式。
type User struct {
ID string `json:"Id" datastore:"Id"`
}
英文:
I was able to figure a variable omitempty
which can help in these situations. I found a good blog on it's explanation - https://www.sohamkamani.com/golang/omitempty/ .
If I store in DB a column with it's default zero value, then omitempty will not read it while reading json. In this way I will be able to use same golang schema with multiple DB schemas.
type User struct {
ID string `json:"Id" datastore:"Id"`
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论