-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfunc_sync.go
More file actions
41 lines (32 loc) · 1.55 KB
/
Copy pathfunc_sync.go
File metadata and controls
41 lines (32 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package deployment
import (
"context"
"fmt"
"github.com/pipe-cd/community-plugins/plugins/sqldef/config"
"github.com/pipe-cd/community-plugins/plugins/sqldef/provider"
toolRegistryPkg "github.com/pipe-cd/community-plugins/plugins/sqldef/toolregistry"
sdk "github.com/pipe-cd/piped-plugin-sdk-go"
)
func (p *Plugin) executeSqldefSyncStage(ctx context.Context, dts []*sdk.DeployTarget[config.SqldefDeployTargetConfig], input *sdk.ExecuteStageInput[config.SqldefApplicationSpec]) sdk.StageStatus {
lp := input.Client.LogPersister()
lp.Info("Start syncing the deployment")
// Currently, we create them every time the stage is executed beucause we can't pass input.Client.toolRegistry to the plugin when starting the plugin.
toolRegistry := toolRegistryPkg.NewRegistry(input.Client.ToolRegistry())
for _, dt := range dts {
// TODO: check db_type from dt.config to choose which sqldef binary to download
// Now we temporarily hard-coded as mysql
sqlDefPath, err := toolRegistry.Mysqldef(ctx, "")
lp.Info(fmt.Sprintf("Sqldef binary downloaded: %s", sqlDefPath))
if err != nil {
lp.Errorf("Failed while getting Sqldef tool (%v)", err)
return sdk.StageStatusFailure
}
lp.Info(fmt.Sprintf("dt: %+v\n", dt))
sqldef := provider.NewSqldef(lp, dt.Config.Username, dt.Config.Password, dt.Config.Host, dt.Config.Port, dt.Config.DBName, dt.Config.SchemaFilePath, sqlDefPath)
err = sqldef.Execute(ctx, dt.Config.DryRun, dt.Config.EnableDrop)
if err != nil {
lp.Errorf("Failed while syncing the deployment (%v)", err)
}
}
return sdk.StageStatusSuccess
}