Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: add opts to ExecFuncType (#17126)

p0ny971abcf5f024
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index f65ef4f173..1f0685107c 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -35,7 +35,7 @@ type Executor interface {
RunOnce(ctx context.Context, driverCtx context.Context, task *store.TaskMessage, taskRunUID int) (terminated bool, result *storepb.TaskRunResult, err error)
}
-type execFuncType func(context.Context, string) error
+type execFuncType func(context.Context, string, db.ExecuteOptions) error
// RunExecutorOnce wraps a TaskExecutor.RunOnce call with panic recovery.
func RunExecutorOnce(ctx context.Context, driverCtx context.Context, exec Executor, task *store.TaskMessage, taskRunUID int) (terminated bool, result *storepb.TaskRunResult, err error) {
@@ -308,7 +308,7 @@ func doMigrationWithFunc(
opts.CreateTaskRunLog = getCreateTaskRunLog(ctx, mc.taskRunUID, stores, profile)
if execFunc == nil {
- execFunc = func(ctx context.Context, execStatement string) error {
+ execFunc = func(ctx context.Context, execStatement string, opts db.ExecuteOptions) error {
if _, err := driver.Execute(ctx, execStatement, opts); err != nil {
return err
}
@@ -353,7 +353,21 @@ func postMigration(ctx context.Context, stores *store.Store, mc *migrateContext,
}, nil
}
-func runMigrationWithFunc(ctx context.Context, driverCtx context.Context, store *store.Store, dbFactory *dbfactory.DBFactory, stateCfg *state.State, syncer *schemasync.Syncer, profile *config.Profile, task *store.TaskMessage, taskRunUID int, statement string, schemaVersion string, sheetID *int, execFunc execFuncType) (terminated bool, result *storepb.TaskRunResult, err error) {
+func runMigrationWithFunc(
+ ctx context.Context,
+ driverCtx context.Context,
+ store *store.Store,
+ dbFactory *dbfactory.DBFactory,
+ stateCfg *state.State,
+ syncer *schemasync.Syncer,
+ profile *config.Profile,
+ task *store.TaskMessage,
+ taskRunUID int,
+ statement string,
+ schemaVersion string,
+ sheetID *int,
+ execFunc execFuncType,
+) (terminated bool, result *storepb.TaskRunResult, err error) {
mc, err := getMigrationInfo(ctx, store, profile, syncer, task, schemaVersion, sheetID, taskRunUID, dbFactory)
if err != nil {
return true, nil, err
@@ -371,7 +385,15 @@ func runMigration(ctx context.Context, driverCtx context.Context, store *store.S
}
// executeMigrationWithFunc executes the migration with custom migration function.
-func executeMigrationWithFunc(ctx context.Context, driverCtx context.Context, s *store.Store, mc *migrateContext, statement string, execFunc func(ctx context.Context, execStatement string) error, opts db.ExecuteOptions) (skipped bool, resErr error) {
+func executeMigrationWithFunc(
+ ctx context.Context,
+ driverCtx context.Context,
+ s *store.Store,
+ mc *migrateContext,
+ statement string,
+ execFunc execFuncType,
+ opts db.ExecuteOptions,
+) (skipped bool, resErr error) {
// Phase 1 - Dump before migration.
// Check if versioned is already applied.
skipExecution, err := beginMigration(ctx, s, mc, opts)
@@ -393,7 +415,7 @@ func executeMigrationWithFunc(ctx context.Context, driverCtx context.Context, s
}()
// Phase 2 - Executing migration.
- if err := execFunc(driverCtx, statement); err != nil {
+ if err := execFunc(driverCtx, statement, opts); err != nil {
return false, err
}
diff --git a/backend/runner/taskrun/schema_update_ghost_executor.go b/backend/runner/taskrun/schema_update_ghost_executor.go
index a96c837c5e..77935a781a 100644
--- a/backend/runner/taskrun/schema_update_ghost_executor.go
+++ b/backend/runner/taskrun/schema_update_ghost_executor.go
@@ -70,7 +70,7 @@ func (exec *SchemaUpdateGhostExecutor) RunOnce(ctx context.Context, driverCtx co
return true, nil, errors.Errorf("database not found")
}
- execFunc := func(execCtx context.Context, execStatement string) error {
+ execFunc := func(execCtx context.Context, execStatement string, _ db.ExecuteOptions) error {
// set buffer size to 1 to unblock the sender because there is no listener if the task is canceled.
migrationError := make(chan error, 1)
diff --git a/backend/runner/taskrun/schema_update_sdl_executor.go b/backend/runner/taskrun/schema_update_sdl_executor.go
index 02e63934b0..0144effe57 100644
--- a/backend/runner/taskrun/schema_update_sdl_executor.go
+++ b/backend/runner/taskrun/schema_update_sdl_executor.go
@@ -62,6 +62,7 @@ func (exec *SchemaDeclareExecutor) RunOnce(ctx context.Context, driverCtx contex
// sync database schema
// TODO(p0ny): see if we can reduce the number of syncs.
+ // TODO(p0ny): move the diff calculation into the Exec func, which is after the beginMigration. so that we can avoid the sync.
exec.store.CreateTaskRunLogS(ctx, taskRunUID, time.Now(), exec.profile.DeployID, &storepb.TaskRunLog{
Type: storepb.TaskRunLog_DATABASE_SYNC_START,
DatabaseSyncStart: &storepb.TaskRunLog_DatabaseSyncStart{},
@@ -128,5 +129,5 @@ func (exec *SchemaDeclareExecutor) RunOnce(ctx context.Context, driverCtx contex
return true, nil, connect.NewError(connect.CodeInternal, errors.Errorf("failed to generate migration SQL, error: %v", err))
}
- return runMigration(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, migrationSQL, task.Payload.GetSchemaVersion(), &sheetID)
+ return runMigrationWithFunc(ctx, driverCtx, exec.store, exec.dbFactory, exec.stateCfg, exec.schemaSyncer, exec.profile, task, taskRunUID, migrationSQL, task.Payload.GetSchemaVersion(), &sheetID, nil)
}