Skip to content

Commit

Permalink
fix issue with only first table sync succeeding
Browse files Browse the repository at this point in the history
  • Loading branch information
Phani Raj committed Aug 3, 2022
1 parent 29eeaa3 commit b91d5d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions cmd/internal/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ func Sync(ctx context.Context, mysqlDatabase PlanetScaleEdgeMysqlAccess, edgeDat

func generateEmptyState(source PlanetScaleSource, catalog Catalog, shards []string) *State {
var s State
initialState, err := source.GetInitialState(source.Database, shards)
if err != nil {
return nil
}

s = State{
Streams: map[string]ShardStates{},
}

for _, stream := range catalog.Streams {
initialState, err := source.GetInitialState(source.Database, shards)
if err != nil {
return nil
}
s.Streams[stream.Name] = initialState
}

Expand Down
20 changes: 18 additions & 2 deletions cmd/internal/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func TestSync_CanStartFromEmptyState(t *testing.T) {
var cursor *psdbconnect.TableCursor
ped := &testPlanetScaleEdgeDatabase{
ReadFn: func(ctx context.Context, ps PlanetScaleSource, s Stream, tc *psdbconnect.TableCursor) (*SerializedCursor, error) {
assert.Empty(t, tc.Position, "start position should be empty")
cursor = tc
cursor.Position = "I-HAVE-MOVED"
return TableCursorToSerializedCursor(tc)
},
}
Expand All @@ -72,8 +74,22 @@ func TestSync_CanStartFromEmptyState(t *testing.T) {
Metadata: MetadataCollection{
{
Metadata: NodeMetadata{
Selected: true,
BreadCrumb: []string{},
ReplicationMethod: "INCREMENTAL",
Selected: true,
BreadCrumb: []string{},
},
},
},
},
{
Name: "customers",
TableName: "customers",
Metadata: MetadataCollection{
{
Metadata: NodeMetadata{
ReplicationMethod: "INCREMENTAL",
Selected: true,
BreadCrumb: []string{},
},
},
},
Expand Down

0 comments on commit b91d5d4

Please sign in to comment.