Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f916ad6
Modify logging to support logrus
kumaya Sep 12, 2018
2513950
Modify logging to support logrus
kumaya Sep 18, 2018
f6ccfd4
Merge branch 'master' of https://github.com/golang-migrate/migrate
kumaya Sep 18, 2018
24a850c
Merge branch 'master' of https://github.com/golang-migrate/migrate
kumaya Sep 18, 2018
4499bdf
Enable configuration
kumaya Sep 14, 2018
2ed505f
Merge pull request #3 from kumaya/config
kumaya Oct 3, 2018
adeea01
Configuration support for database string
kumaya Oct 3, 2018
49df9a4
Merge pull request #4 from kumaya/dsn
kumaya Oct 3, 2018
1875527
Update README.md
kumaya Oct 9, 2018
aa78373
Merge branch 'master' of https://github.com/golang-migrate/migrate
kumaya Oct 15, 2018
8a93a8f
Merge pull request #5 from kumaya/master
kumaya Oct 15, 2018
b200546
Update go and alpine versions (#6)
Calebjh Apr 13, 2021
5564ef4
Add Jenkinsfile (#7)
Calebjh Apr 14, 2021
079cf15
Fix test issues
Calebjh Apr 15, 2021
577e929
Skip tests, just build
Calebjh Apr 15, 2021
8e2cb3a
Docker credentials around build, too
Calebjh Apr 15, 2021
2299517
Only push to harbor
Calebjh Apr 15, 2021
c2c9739
URL escape password and username on connection strings (#10)
Calebjh Sep 24, 2021
b912ce7
Merge branch 'master' of github.com:golang-migrate/migrate into ib
kumaya Nov 24, 2021
418501b
merge upstream
daniel-garcia Jul 12, 2022
8445c30
add hotload support
daniel-garcia Jul 14, 2022
f1ec28e
add hotload support (#15)
daniel-garcia Jul 14, 2022
b23a55e
build in ib-branch
daniel-garcia Jul 14, 2022
2786533
Merge branch 'hotload' into ib
daniel-garcia Jul 14, 2022
2d48d39
import fsync
daniel-garcia Jul 15, 2022
f746be2
Upgrade alpine 3.13 -> 3.18 (#21)
ychen-bloxer Oct 13, 2023
31fc03e
adding pgx as the supported hotload base driver (#26)
Gowdasupriya Nov 30, 2023
f83486d
removing the pgx register in migrate (#27)
Gowdasupriya Dec 1, 2023
c441785
Hotload support (#31)
daniel-garcia Dec 8, 2023
d6166ab
resolved upstream conflicts in go.*
daniel-garcia Dec 8, 2023
b82c168
patch vulns
daniel-garcia Dec 8, 2023
af3698e
merge upstream master
daniel-garcia Dec 21, 2023
8447691
Merge pull request #33 from infobloxopen/vulns
daniel-garcia Dec 21, 2023
d47e437
fixed merged conflict
daniel-garcia Jul 13, 2024
6caa1d9
upgrade go->1.22, alpine->latest (#34)
ychen-bloxer Aug 15, 2024
13318b2
Goto command support to handle dirty Database state (#36)
venkat-iblox Oct 4, 2024
5d974f1
Minor code updates from missed open comments from #36 to the migrated…
venkat-iblox Oct 9, 2024
9070a97
Update go version and dependencies (#42)
Calebjh Apr 10, 2025
0ccdb3b
Build docker image using scratch as final base layer (#44)
Calebjh Jun 12, 2025
144e706
Update jenkins go version to 1.24 (#45)
Calebjh Jun 12, 2025
3ed052a
Try to unset go flags to make mod work maybe (#46)
Calebjh Jun 13, 2025
7efd19e
Try using go mod download instead of vendor (#47)
Calebjh Jun 13, 2025
eab00b9
feat: add install-to subcommand for binary self-installation
daniel-garcia Sep 11, 2025
028c114
gofmt and remove lint
daniel-garcia Sep 11, 2025
7e04814
limit tests and test on 1.24
daniel-garcia Sep 11, 2025
6f0ba2b
do not test sqlserver
daniel-garcia Sep 11, 2025
c84938c
Merge pull request #49 from infobloxopen/installTo
daniel-garcia Sep 11, 2025
7351dcb
Merge branch 'master' into ib
daniel-garcia Sep 12, 2025
67ef559
disable linting for infobloxopen
daniel-garcia Sep 12, 2025
0f032ae
store db migrates in the database if it supports it
daniel-garcia Sep 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
lint:
if: false # disable linting for infobloxopen/migrate
name: lint
runs-on: ubuntu-latest
steps:
Expand All @@ -31,7 +32,7 @@ jobs:
go-version: ${{ matrix.go }}

- name: Run test
run: make test COVERAGE_DIR=/tmp/coverage
run: make test COVERAGE_DIR=/tmp/coverage DATABASE="postgres mysql clickhouse mongodb pgx pgx5 rqlite sqlite sqlite3"

- name: Send goveralls coverage
uses: shogo82148/actions-goveralls@v1
Expand All @@ -51,11 +52,11 @@ jobs:

goreleaser:
name: Release a new version
needs: [lint, test]
needs: [test]
runs-on: ubuntu-latest
environment: GoReleaser
# This job only runs when
# 1. When the previous `lint` and `test` jobs has completed successfully
# 1. When the previous `test` job has completed successfully
# 2. When the repository is not a fork, i.e. it will only run on the official golang-migrate/migrate
# 3. When the workflow is triggered by a tag with `v` prefix
if: ${{ success() && github.repository == 'golang-migrate/migrate' && startsWith(github.ref, 'refs/tags/v') }}
Expand Down
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG VERSION

RUN apk add --no-cache git gcc musl-dev make

WORKDIR /go/src/github.com/golang-migrate/migrate
WORKDIR /go/src/github.com/infobloxopen/migrate

ENV GO111MODULE=on

Expand All @@ -15,12 +15,11 @@ COPY . ./

RUN make build-docker

FROM alpine:3.21
FROM gcr.io/distroless/static:nonroot

RUN apk add --no-cache ca-certificates

COPY --from=builder /go/src/github.com/golang-migrate/migrate/build/migrate.linux-386 /usr/local/bin/migrate
RUN ln -s /usr/local/bin/migrate /migrate
COPY --from=builder /go/src/github.com/infobloxopen/migrate/cmd/migrate/config /cli/config/
COPY --from=builder /go/src/github.com/infobloxopen/migrate/build/migrate.linux-386 /migrate
COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs/

ENTRYPOINT ["migrate"]
CMD ["--help"]
2 changes: 1 addition & 1 deletion Dockerfile.github-actions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.19
FROM alpine:latest

RUN apk add --no-cache ca-certificates

Expand Down
63 changes: 63 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

// This library defines the isPrBuild, prepareBuild and finalizeBuild methods
@Library('jenkins.shared.library') _

pipeline {
agent {
label 'ubuntu_docker_label'
}
tools {
go "Go 1.24.2"
}
options {
checkoutToSubdirectory('src/github.com/infobloxopen/migrate')
}
environment {
GOPATH = "$WORKSPACE"
DIRECTORY = "src/github.com/infobloxopen/migrate"
}

stages {
stage("Setup") {
steps {
// prepareBuild is one of the Secure CICD helper methods
prepareBuild()
}
}
stage("Unit Tests") {
steps {
dir("$DIRECTORY") {
// sh "make test"
}
}
}
stage("Build Image") {
steps {
withDockerRegistry([credentialsId: "${env.JENKINS_DOCKER_CRED_ID}", url: ""]) {
dir("$DIRECTORY") {
sh "make build"
}
}
}
}
}
post {
success {
// finalizeBuild is one of the Secure CICD helper methods
dir("$DIRECTORY") {
finalizeBuild(
sh(
script: 'make list-of-images',
returnStdout: true
)
)
}
}
cleanup {
dir("$DIRECTORY") {
sh "make clean || true"
}
cleanWs()
}
}
}
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
SOURCE ?= file go_bindata github github_ee bitbucket aws_s3 google_cloud_storage godoc_vfs gitlab
DATABASE ?= postgres mysql redshift cassandra spanner cockroachdb yugabytedb clickhouse mongodb sqlserver firebird neo4j pgx pgx5 rqlite
DATABASE_TEST ?= $(DATABASE) sqlite sqlite3 sqlcipher
VERSION ?= $(shell git describe --tags 2>/dev/null | cut -c 2-)
BUILD_NUMBER ?= 0
VERSION ?= $(shell git describe --tags --long --dirty=-unsupported 2>/dev/null | cut -c 2-)-j$(BUILD_NUMBER)
TEST_FLAGS ?=
REPO_OWNER ?= $(shell cd .. && basename "$$(pwd)")
COVERAGE_DIR ?= .coverage

build:
CGO_ENABLED=0 go build -ldflags='-X main.Version=$(VERSION)' -tags '$(DATABASE) $(SOURCE)' ./cmd/migrate

build-docker:
CGO_ENABLED=0 go build -a -o build/migrate.linux-386 -ldflags="-s -w -X main.Version=${VERSION}" -tags "$(DATABASE) $(SOURCE)" ./cmd/migrate

Expand All @@ -24,6 +22,17 @@ build-cli: clean
cd ./cli/build && shasum -a 256 * > sha256sum.txt
cat ./cli/build/sha256sum.txt

build:
docker build --pull --build-arg VERSION=$(VERSION) . -t infoblox/migrate -t infoblox/migrate:$(VERSION)

docker-push:
docker push infoblox/migrate:$(VERSION)

show-image-version:
echo $(VERSION)

list-of-images:
@echo "infoblox/migrate:$(VERSION)"

clean:
-rm -r ./cli/build
Expand Down Expand Up @@ -117,4 +126,3 @@ endef

SHELL = /bin/sh
RAND = $(shell echo $$RANDOM)

4 changes: 3 additions & 1 deletion cli/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import "github.com/golang-migrate/migrate/v4/internal/cli"
import (
"github.com/golang-migrate/migrate/v4/internal/cli"
)

// Deprecated, please use cmd/migrate
func main() {
Expand Down
1 change: 1 addition & 0 deletions cmd/migrate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
migrate
42 changes: 42 additions & 0 deletions cmd/migrate/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import "github.com/spf13/pflag"

const (
// configuration defaults support local development (i.e. "go run ...")
defaultDatabaseDSN = ""
defaultDatabaseDriver = "postgres"
defaultDatabaseAddress = "0.0.0.0:5432"
defaultDatabaseName = ""
defaultDatabaseUser = "postgres"
defaultDatabasePassword = "postgres"
defaultDatabaseSSL = "disable"
defaultConfigDirectory = "/cli/config"
)

var (
// define flag overrides
flagHelp = pflag.Bool("help", false, "Print usage")
flagVersion = pflag.String("version", Version, "Print version")
flagLoggingVerbose = pflag.Bool("verbose", true, "Print verbose logging")
flagPrefetch = pflag.Uint("prefetch", 10, "Number of migrations to load in advance before executing")
flaglockTimeout = pflag.Uint("lock-timeout", 15, "Allow N seconds to acquire database lock")

flagDatabaseDSN = pflag.String("database.dsn", defaultDatabaseDSN, "database connection string")
flagDatabaseDriver = pflag.String("database.driver", defaultDatabaseDriver, "database driver")
flagDatabaseAddress = pflag.String("database.address", defaultDatabaseAddress, "address of the database")
flagDatabaseName = pflag.String("database.name", defaultDatabaseName, "name of the database")
flagDatabaseUser = pflag.String("database.user", defaultDatabaseUser, "database username")
flagDatabasePassword = pflag.String("database.password", defaultDatabasePassword, "database password")
flagDatabaseSSL = pflag.String("database.ssl", defaultDatabaseSSL, "database ssl mode")

flagSource = pflag.String("source", "", "Location of the migrations (driver://url)")
flagPath = pflag.String("path", "", "Shorthand for -source=file://path")

flagConfigDirectory = pflag.String("config.source", defaultConfigDirectory, "directory of the configuration file")
flagConfigFile = pflag.String("config.file", "", "configuration file name without extension")

// goto command flags
flagDirty = pflag.Bool("force-dirty-handling", false, "force the handling of dirty database state")
flagMountPath = pflag.String("cache-dir", "", "path to the cache-dir which is used to copy the migration files")
)
14 changes: 14 additions & 0 deletions cmd/migrate/config/defaults.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
help: false
version: false
verbose: true
prefetch: 10
lockTimeout: 15
path: "/atlas-migrations/migrations"
#source: "file:///atlas-migrations/migrations"
database:
driver: postgres
address: postgres:5432
name: app_db
user: postgres
password: postgres
ssl: disable
35 changes: 34 additions & 1 deletion cmd/migrate/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
package main

import "github.com/golang-migrate/migrate/v4/internal/cli"
import (
"log"
"strings"

"github.com/golang-migrate/migrate/v4/internal/cli"
"github.com/infobloxopen/hotload"
_ "github.com/infobloxopen/hotload/fsnotify"
"github.com/jackc/pgx/v4/stdlib"
"github.com/lib/pq"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

func init() {
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
viper.AutomaticEnv()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AddConfigPath(viper.GetString("config.source"))
if viper.GetString("config.file") != "" {
viper.SetConfigName(viper.GetString("config.file"))
if err := viper.ReadInConfig(); err != nil {
log.Fatalf("cannot load configuration: %v", err)
}
}
// logrus formatter
customFormatter := new(logrus.JSONFormatter)
logrus.SetFormatter(customFormatter)

hotload.RegisterSQLDriver("pgx", stdlib.GetDefaultDriver())
hotload.RegisterSQLDriver("postgres", pq.Driver{})
hotload.RegisterSQLDriver("postgresql", pq.Driver{})
}

func main() {
cli.Main(Version)
Expand Down
Loading