Home > database >  How to use old schema(with no new columns) with a kind/table having new columns added, after a rollb
How to use old schema(with no new columns) with a kind/table having new columns added, after a rollb

Time:01-01

I have added some new columns in a kind in Google Data store 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 -

  1. Write a script to delete new column from GDS when I want to rollback
  2. Add a flag kind of feature to disable new cloumns 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?

CodePudding user response:

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"`
}
  • Related