MCPcopy
hub / github.com/hasura/graphql-engine / squashUp

Method squashUp

cli/migrate/migrate.go:799–888  ·  view source on GitHub ↗
(from uint64, to int64, ret chan<- interface{})

Source from the content-addressed store, hash-verified

797}
798
799func (m *Migrate) squashUp(from uint64, to int64, ret chan<- interface{}) {
800 defer close(ret)
801 currentVersion := from
802 count := int64(0)
803 limit := int64(-1)
804 if m.stop() {
805 return
806 }
807
808 for limit == -1 {
809 if int64(from) == to {
810 return
811 }
812 if currentVersion == from {
813 // during the first iteration of the loop
814 // check if a next version exists for "--from" version
815 if err := m.versionUpExists(from); err != nil {
816 ret <- err
817 return
818 }
819
820 // If next version exists this function will return an instance of
821 // migration.go.Migrate struct
822 // this reads the SQL up migration
823 // even if a migration file does'nt exist in the source
824 // a empty migration will be returned
825 migr, err := m.newMigration(from, int64(from))
826 if err != nil {
827 ret <- err
828 return
829 }
830 ret <- migr
831 // write the body of the migration to reader
832 // the migr instance sent via the channel will then start reading
833 // from it
834 go func(migr *Migration, m *Migrate) {
835 if err := migr.Buffer(); err != nil {
836 m.Logger.Error(err)
837 }
838 }(migr, m)
839
840 count++
841 }
842
843 // get the next version using source driver
844 // earlier in the first iteration we knew what version to operate on
845 // but here we have to find the next version
846 next, err := m.sourceDrv.Next(currentVersion)
847 if errors.Is(err, fs.ErrNotExist) {
848 // no limit, but no migrations applied?
849 if count == 0 {
850 ret <- ErrNoChange
851 return
852 }
853 // when there is no more migrations return
854 if limit == -1 {
855 return
856 }

Callers 1

SquashMethod · 0.95

Calls 7

stopMethod · 0.95
versionUpExistsMethod · 0.95
newMigrationMethod · 0.95
closeFunction · 0.85
BufferMethod · 0.80
NextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected