mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
This commit is contained in:
parent
7f1cc633ee
commit
337403d532
@ -128,11 +128,14 @@ func (h *newHasuraIntefaceQuery) UnmarshalJSON(b []byte) error {
|
||||
case dropComputedField:
|
||||
q.Args = &dropComputedFieldInput{}
|
||||
default:
|
||||
return fmt.Errorf("cannot squash type %s", h.Type)
|
||||
return fmt.Errorf("cannot squash type %s", q.Type)
|
||||
}
|
||||
if err := json.Unmarshal(argBody, &q.Args); err != nil {
|
||||
return err
|
||||
}
|
||||
if q.Args == nil {
|
||||
return fmt.Errorf("args is missing in metadata action %s", q.Type)
|
||||
}
|
||||
*h = newHasuraIntefaceQuery(q)
|
||||
return nil
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ func (m *Migrate) Squash(v uint64) (vs []int64, um []interface{}, us []byte, dm
|
||||
go m.squashMigrations(retUp, retDown, dataUp, dataDown, retVersions)
|
||||
|
||||
// make a chan for errors
|
||||
errChn := make(chan error)
|
||||
errChn := make(chan error, 2)
|
||||
|
||||
// create a waitgroup to wait for all goroutines to finish execution
|
||||
var wg sync.WaitGroup
|
||||
@ -403,7 +403,8 @@ func (m *Migrate) Squash(v uint64) (vs []int64, um []interface{}, us []byte, dm
|
||||
case error:
|
||||
// it's an error, set error and return
|
||||
// note: this return is returning the goroutine, not the current function
|
||||
err = r.(error)
|
||||
m.isGracefulStop = true
|
||||
errChn <- r.(error)
|
||||
return
|
||||
case []byte:
|
||||
// it's SQL, concat all of them
|
||||
@ -429,7 +430,8 @@ func (m *Migrate) Squash(v uint64) (vs []int64, um []interface{}, us []byte, dm
|
||||
case error:
|
||||
// it's an error, set error and return
|
||||
// note: this return is returning the goroutine, not the current function
|
||||
err = r.(error)
|
||||
m.isGracefulStop = true
|
||||
errChn <- r.(error)
|
||||
return
|
||||
case []byte:
|
||||
// it's SQL, concat all of them
|
||||
@ -459,15 +461,16 @@ func (m *Migrate) Squash(v uint64) (vs []int64, um []interface{}, us []byte, dm
|
||||
// wait until all tasks (3) in the workgroup are completed
|
||||
wg.Wait()
|
||||
|
||||
// close the errChn
|
||||
close(errChn)
|
||||
|
||||
// check for errors in the error channel
|
||||
select {
|
||||
// we got an error, set err and return
|
||||
case err = <-errChn:
|
||||
return
|
||||
default:
|
||||
// set nothing and return, all is well
|
||||
for e := range errChn {
|
||||
err = e
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Migrate looks at the currently active migration version,
|
||||
@ -686,6 +689,10 @@ func (m *Migrate) squashDown(version uint64, ret chan<- interface{}) {
|
||||
return
|
||||
}
|
||||
|
||||
if from < version {
|
||||
return
|
||||
}
|
||||
|
||||
err = m.versionDownExists(from)
|
||||
if err != nil {
|
||||
ret <- err
|
||||
@ -711,10 +718,6 @@ func (m *Migrate) squashDown(version uint64, ret chan<- interface{}) {
|
||||
go migr.Buffer()
|
||||
}
|
||||
|
||||
if from == version {
|
||||
return
|
||||
}
|
||||
|
||||
migr, err := m.metanewMigration(from, int64(prev))
|
||||
if err != nil {
|
||||
ret <- err
|
||||
@ -1115,11 +1118,17 @@ func (m *Migrate) squashMigrations(retUp <-chan interface{}, retDown <-chan inte
|
||||
defer close(dataUp)
|
||||
defer close(versions)
|
||||
|
||||
var err error
|
||||
|
||||
squashList := database.CustomList{
|
||||
list.New(),
|
||||
}
|
||||
|
||||
defer m.databaseDrv.Squash(&squashList, dataUp)
|
||||
defer func() {
|
||||
if err == nil {
|
||||
m.databaseDrv.Squash(&squashList, dataUp)
|
||||
}
|
||||
}()
|
||||
|
||||
for r := range retUp {
|
||||
if m.stop() {
|
||||
@ -1131,8 +1140,9 @@ func (m *Migrate) squashMigrations(retUp <-chan interface{}, retDown <-chan inte
|
||||
case *Migration:
|
||||
migr := r.(*Migration)
|
||||
if migr.Body != nil {
|
||||
if err := m.databaseDrv.PushToList(migr.BufferedBody, migr.FileType, &squashList); err != nil {
|
||||
if err = m.databaseDrv.PushToList(migr.BufferedBody, migr.FileType, &squashList); err != nil {
|
||||
dataUp <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -1147,12 +1157,17 @@ func (m *Migrate) squashMigrations(retUp <-chan interface{}, retDown <-chan inte
|
||||
|
||||
go func() {
|
||||
defer close(dataDown)
|
||||
var err error
|
||||
|
||||
squashList := database.CustomList{
|
||||
list.New(),
|
||||
}
|
||||
|
||||
defer m.databaseDrv.Squash(&squashList, dataDown)
|
||||
defer func() {
|
||||
if err == nil {
|
||||
m.databaseDrv.Squash(&squashList, dataDown)
|
||||
}
|
||||
}()
|
||||
|
||||
for r := range retDown {
|
||||
if m.stop() {
|
||||
@ -1164,8 +1179,9 @@ func (m *Migrate) squashMigrations(retUp <-chan interface{}, retDown <-chan inte
|
||||
case *Migration:
|
||||
migr := r.(*Migration)
|
||||
if migr.Body != nil {
|
||||
if err := m.databaseDrv.PushToList(migr.BufferedBody, migr.FileType, &squashList); err != nil {
|
||||
if err = m.databaseDrv.PushToList(migr.BufferedBody, migr.FileType, &squashList); err != nil {
|
||||
dataDown <- err
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user