(ctx context.Context, sourceClient *managedplugin.Client, managedDestinationsClients managedplugin.Clients, sourceSpec specs.Source, destinationSpecs []specs.Destination, destinationsVersions [][]int)
| 14 | ) |
| 15 | |
| 16 | func migrateConnectionV2(ctx context.Context, sourceClient *managedplugin.Client, managedDestinationsClients managedplugin.Clients, sourceSpec specs.Source, destinationSpecs []specs.Destination, destinationsVersions [][]int) error { |
| 17 | destinationStrings := make([]string, len(destinationSpecs)) |
| 18 | for i := range destinationSpecs { |
| 19 | destinationStrings[i] = destinationSpecs[i].VersionString() |
| 20 | } |
| 21 | migrateStart := time.Now().UTC() |
| 22 | log.Info().Str("source", sourceSpec.Name).Strs("destinations", destinationStrings).Time("migrate_time", migrateStart).Msg("Start migration") |
| 23 | defer log.Info().Str("source", sourceSpec.Name).Strs("destinations", destinationStrings).Time("migrate_time", migrateStart).Msg("End migration") |
| 24 | |
| 25 | sourcePbClient := pbSource.NewSourceClient(sourceClient.Conn) |
| 26 | destinationsTransformers := getSourceV2DestV3DestinationsTransformers(destinationSpecs, destinationsVersions) |
| 27 | destinationsPbClients := make([]pbdestination.DestinationClient, len(managedDestinationsClients)) |
| 28 | for i := range managedDestinationsClients { |
| 29 | destinationsPbClients[i] = pbdestination.NewDestinationClient(managedDestinationsClients[i].Conn) |
| 30 | } |
| 31 | |
| 32 | specBytes, err := json.Marshal(CLISourceSpecToPbSpec(sourceSpec)) |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | if _, err := sourcePbClient.Init(ctx, &pbSource.Init_Request{ |
| 37 | Spec: specBytes, |
| 38 | }); err != nil { |
| 39 | return fmt.Errorf("failed to Init source: %w", err) |
| 40 | } |
| 41 | tablesRes, err := sourcePbClient.GetDynamicTables(ctx, &pbSource.GetDynamicTables_Request{}) |
| 42 | if err != nil { |
| 43 | return fmt.Errorf("failed to GetDynamicTables: %w", err) |
| 44 | } |
| 45 | |
| 46 | transformedSchemasBytes := make([][][]byte, 0, len(managedDestinationsClients)) |
| 47 | for i := range managedDestinationsClients { |
| 48 | destinationSchemasBytes, err := transformSourceV2DestV3Schemas(tablesRes.Tables, destinationsTransformers[i]) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | transformedSchemasBytes = append(transformedSchemasBytes, destinationSchemasBytes) |
| 53 | } |
| 54 | |
| 55 | fmt.Printf("Starting migration with for: %s -> %s\n", sourceSpec.VersionString(), destinationStrings) |
| 56 | for i := range managedDestinationsClients { |
| 57 | destSpecBytes, err := json.Marshal(CLIDestinationSpecToPbSpec(destinationSpecs[i])) |
| 58 | if err != nil { |
| 59 | return err |
| 60 | } |
| 61 | if _, err := destinationsPbClients[i].Configure(ctx, &pbdestination.Configure_Request{ |
| 62 | Config: destSpecBytes, |
| 63 | }); err != nil { |
| 64 | return fmt.Errorf("failed to call Migrate: %w", err) |
| 65 | } |
| 66 | if _, err := destinationsPbClients[i].Migrate(ctx, &pbdestination.Migrate_Request{ |
| 67 | Tables: transformedSchemasBytes[i], |
| 68 | }); err != nil { |
| 69 | return fmt.Errorf("failed to call Migrate: %w", err) |
| 70 | } |
| 71 | } |
| 72 | migrateTimeTook := time.Since(migrateStart) |
| 73 | fmt.Println("Migration completed successfully.") |
no test coverage detected