Skip to content

Commit db9999f

Browse files
authored
Merge branch 'master' into dependabot/go_modules/go_modules-dd7da38a6b
2 parents fc98679 + e62debe commit db9999f

47 files changed

Lines changed: 2939 additions & 2302 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
with:
1919
go-version-file: go.mod
2020
- name: golangci-lint
21-
uses: golangci/golangci-lint-action@v6
21+
uses: golangci/golangci-lint-action@v9
2222
with:
23-
version: v1.61.0
23+
version: v2.11

.golangci.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
run:
2-
timeout: 5m
1+
version: "2"
32
linters:
4-
disable:
5-
- errcheck
63
enable:
74
- bodyclose
85
- containedctx
@@ -11,18 +8,38 @@ linters:
118
- durationcheck
129
- errname
1310
- errorlint
14-
- gofmt
1511
- misspell
1612
- nilerr
1713
- nilnil
18-
- noctx
1914
- nolintlint
2015
- nosprintfhostport
21-
- prealloc
2216
- rowserrcheck
2317
- sqlclosecheck
2418
- unconvert
2519
- unparam
26-
- unused
2720
- wastedassign
2821
- whitespace
22+
disable:
23+
- errcheck
24+
- noctx
25+
- prealloc
26+
exclusions:
27+
generated: lax
28+
presets:
29+
- comments
30+
- common-false-positives
31+
- legacy
32+
- std-error-handling
33+
paths:
34+
- third_party$
35+
- builtin$
36+
- examples$
37+
formatters:
38+
enable:
39+
- gofmt
40+
exclusions:
41+
generated: lax
42+
paths:
43+
- third_party$
44+
- builtin$
45+
- examples$

Dockerfile.packaging

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23-bullseye
1+
FROM golang:1.25.9-bookworm
22

33
RUN apt-get update
44
RUN apt-get install -y ruby ruby-dev rubygems build-essential

Dockerfile.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23-bullseye
1+
FROM golang:1.25.9-bookworm
22
LABEL maintainer="github@github.com"
33

44
RUN apt-get update
@@ -8,4 +8,4 @@ RUN rm -rf /var/lib/apt/lists/*
88
COPY . /go/src/github.com/github/gh-ost
99
WORKDIR /go/src/github.com/github/gh-ost
1010

11-
CMD ["script/test"]
11+
CMD ["script/test", "-short=1"]

doc/hooks.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,48 @@ The following variables are available on all hooks:
8181

8282
The following variable are available on particular hooks:
8383

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.
8485
- `GH_OST_COMMAND` is only available in `gh-ost-on-interactive-command`
8586
- `GH_OST_STATUS` is only available in `gh-ost-on-status`
8687
- `GH_OST_LAST_BATCH_COPY_ERROR` is only available in `gh-ost-on-batch-copy-retry`
8788

8889
### Examples
8990

9091
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`:
96+
97+
```go
98+
import (
99+
"github.com/github/gh-ost/go/base"
100+
"github.com/github/gh-ost/go/logic"
101+
)
102+
103+
const version = "1.1.8"
104+
105+
type myHooks struct{}
106+
107+
func (myHooks) OnSuccess(instantDDL bool) error { return nil }
108+
func (myHooks) OnFailure() error { return nil }
109+
// ... implement the remaining base.Hooks methods.
110+
111+
ctx := base.NewMigrationContext()
112+
// ... configure ctx (DatabaseName, OriginalTableName, AlterStatement, etc.)
113+
114+
ctx.Hooks = &myHooks{}
115+
m := logic.NewMigrator(ctx, version)
116+
err := m.Migrate()
117+
```
118+
119+
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.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/github/gh-ost
22

3-
go 1.24.0
3+
go 1.25.9
44

55
require (
66
github.com/go-ini/ini v1.67.0

0 commit comments

Comments
 (0)