You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/hooks.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,10 +81,48 @@ The following variables are available on all hooks:
81
81
82
82
The following variable are available on particular hooks:
83
83
84
+
-`GH_OST_INSTANT_DDL` is only available in `gh-ost-on-success`. The value is `true` if instant DDL was successful, and `false` if it was not.
84
85
-`GH_OST_COMMAND` is only available in `gh-ost-on-interactive-command`
85
86
-`GH_OST_STATUS` is only available in `gh-ost-on-status`
86
87
-`GH_OST_LAST_BATCH_COPY_ERROR` is only available in `gh-ost-on-batch-copy-retry`
87
88
88
89
### Examples
89
90
90
91
See [sample hooks](https://github.com/github/gh-ost/tree/master/resources/hooks-sample), as `bash` implementation samples.
92
+
93
+
### Embedded usage: registering Go callbacks
94
+
95
+
When `gh-ost` is consumed as a library (importing `github.com/github/gh-ost/go/logic`), callers can register Go functions for any hook event instead of, or in addition to, the on-disk script contract. Implement the `base.Hooks` interface and assign it to `MigrationContext.Hooks` before calling `logic.NewMigrator`:
To run shell hooks from `--hooks-path` and Go callbacks together, wrap both in `logic.CompositeHooks`. Each member is invoked in order; the first non-nil error short-circuits, matching the script executor's behavior:
120
+
121
+
```go
122
+
ctx.Hooks = logic.CompositeHooks{
123
+
logic.NewHooksExecutor(ctx), // existing scripts under HooksPath
124
+
&myHooks{}, // additional Go callbacks
125
+
}
126
+
```
127
+
128
+
`MigrationContext.Hooks` is opt-in. When it is nil, `NewMigrator` wires the default script executor and behavior is identical to the CLI. Hooks are read once at `NewMigrator` time, so reassigning the field afterwards has no effect on the running migration.
0 commit comments