MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / migrateConnectionV1

Function migrateConnectionV1

cli/cmd/migrate_v1.go:17–65  ·  view source on GitHub ↗
(ctx context.Context, sourceClient *managedplugin.Client, managedDestinationsClients managedplugin.Clients, sourceSpec specs.Source, destinationSpecs []specs.Destination)

Source from the content-addressed store, hash-verified

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

Callers 1

migrateFunction · 0.85

Calls 6

CLISourceSpecToPbSpecFunction · 0.85
ErrorfMethod · 0.80
PrintfMethod · 0.80
VersionStringMethod · 0.80
PrintlnMethod · 0.80

Tested by

no test coverage detected