cloudwan / gohan

Gohan is an API Gateway Server written by Go that makes it easy for developers to create and maintain REST-style API
http://www.slideshare.net/natiueno/gohan-61170476
Other
109 stars 44 forks source link

CW-2355: persist pending post migration events in database. #781

Closed cierpuchaw closed 4 years ago

cierpuchaw commented 4 years ago

We allow migrations to mark schema IDs as modified to later trigger the "post-migration" event for them. We used to store that set in memory only. This potentially led to lost post-migration events when e.g. etcd was unavailable at the time of applying migrations or one of the event handlers failed. Another run of "migrate up" did not mark the same schemas again, because db migrations were already applied and thus not executed. It was also easy to miss the fact that post-migration events were not triggered.

This commit introduces an additional db store for the modified schema set. This way, if gohan can't handle all post-migration events, remaining ones will be loaded from the database on next try. Pending post-migration events also block running gohan server in no_init mode, this mirrors the behavior of pending migrations. It makes it also impossible to unintentionally ignore.

Newly introduced behavior is compatible with forced post-migration events. If a forced schema happens to have a pending post-migration event, it will be treated as completed, provided the event handler succeded. If one forces 2 out of 3 pending schemas, the remaining one will still block execution of gohan server.