cli: fix bug with squashing event triggers (close #4883) (#4949)

This commit is contained in:
Aravind 2020-06-03 12:13:05 +05:30 committed by GitHub
parent edbd9c4f48
commit daf098886b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 10 deletions

View File

@ -82,6 +82,7 @@ Read more about the session argument for computed fields in the [docs](https://h
- console: fix visiting view modify page overwriting raw sql content (fix #4798) (#4810)
- console: add help button and move about page to settings (#4848)
- cli: list all available commands in root command help (fix #4623) (#4628)
- cli: fix bug with squashing event triggers (close #4883)
- cli: add support for skipping execution while generating migrations through the migrate REST API
- docs: add section on actions vs. remote schemas to actions documentation (#4284)
- docs: fix wrong info about excluding scheme in CORS config (#4685)

View File

@ -29,6 +29,7 @@ func (q CustomQuery) MergeEventTriggers(squashList *database.CustomList) error {
next := q.Iterate()
for item, ok := next(); ok; item, ok = next() {
var wasCreated bool
g := item.(linq.Group)
if g.Key == "" {
continue
@ -42,14 +43,19 @@ func (q CustomQuery) MergeEventTriggers(squashList *database.CustomList) error {
element := val.(*list.Element)
switch obj := element.Value.(type) {
case *createEventTriggerInput:
if obj.Replace {
for _, e := range prevElems {
squashList.Remove(e)
}
err := eventTriggerTransition.Trigger("delete_event_trigger", &evCfg, nil)
if err != nil {
return err
if obj.Replace != nil {
if *obj.Replace {
for _, e := range prevElems {
squashList.Remove(e)
}
err := eventTriggerTransition.Trigger("delete_event_trigger", &evCfg, nil)
if err != nil {
return err
}
obj.Replace = nil
}
} else {
wasCreated = true
}
err := eventTriggerTransition.Trigger("create_event_trigger", &evCfg, nil)
if err != nil {
@ -57,11 +63,18 @@ func (q CustomQuery) MergeEventTriggers(squashList *database.CustomList) error {
}
prevElems = append(prevElems, element)
case *deleteEventTriggerInput:
if wasCreated {
// if this is true it means that a trigger was created
// which means their is no point in keeping the delete event trigger around
//
// otherwise it means that it was only updated so we have to keep
// the delete trigger migration
prevElems = append(prevElems, element)
}
err := eventTriggerTransition.Trigger("delete_event_trigger", &evCfg, nil)
if err != nil {
return err
}
prevElems = append(prevElems, element)
// drop previous elements
for _, e := range prevElems {
squashList.Remove(e)

View File

@ -482,8 +482,9 @@ type createEventTriggerInput struct {
WebhookFromEnv string `json:"webhook_from_env,omitempty" yaml:"webhook_from_env,omitempty"`
Definition *createEventTriggerOperationInput `json:"definition,omitempty" yaml:"definition,omitempty"`
Headers interface{} `json:"headers" yaml:"headers"`
Replace bool `json:"replace" yaml:"replace"`
Replace *bool `json:"replace,omitempty" yaml:"replace,omitempty"`
RetryConf *createEventTriggerRetryConfInput `json:"retry_conf" yaml:"retry_conf"`
EnableManual *bool `json:"enable_manual,omitempty" yaml:"enable_manual,omitempty"`
createEventTriggerOperationInput
}
@ -513,11 +514,12 @@ func (c *createEventTriggerInput) MarshalJSON() ([]byte, error) {
Webhook string `json:"webhook,omitempty" yaml:"webhook,omitempty"`
WebhookFromEnv string `json:"webhook_from_env,omitempty" yaml:"webhook_from_env,omitempty"`
Headers interface{} `json:"headers" yaml:"headers"`
Replace bool `json:"replace" yaml:"replace"`
Replace *bool `json:"replace,omitempty" yaml:"replace,omitempty"`
RetryConf *createEventTriggerRetryConfInput `json:"retry_conf" yaml:"retry_conf"`
Insert interface{} `json:"insert,omitempty" yaml:"insert,omitempty"`
Update interface{} `json:"update,omitempty" yaml:"update,omitempty"`
Delete interface{} `json:"delete,omitempty" yaml:"delete,omitempty"`
EnableManual *bool `json:"enable_manual,omitempty" yaml:"enable_manual,omitempty"`
}{
Name: c.Name,
Table: c.Table,
@ -529,6 +531,7 @@ func (c *createEventTriggerInput) MarshalJSON() ([]byte, error) {
Insert: c.Insert,
Update: c.Update,
Delete: c.Delete,
EnableManual: c.EnableManual,
})
}