Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding goose provider and misc features #484

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
go-version: ["1.18.x", "1.19.x", "1.20.x"]
go-version: ["1.19", "1.20"]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
Expand All @@ -22,11 +22,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
check-latest: true
cache: true
- name: Check Go code formatting
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: "1.20.x"
check-latest: true
cache: true
go-version: "stable"
- name: Run e2e ${{ matrix.dialect }} tests
run: |
make test-e2e-${{ matrix.dialect }}
10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: "1.20.x"
check-latest: true
cache: true
go-version: "stable"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
github-token: ${{ secrets.GITHUB_TOKEN }}
args: --timeout=2m --verbose

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand All @@ -37,7 +37,7 @@ jobs:
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
skip-pkg-cache: true
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
# Local testing
.envrc
*.FAIL
/scripts
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ changelog:
exclude:
- "^docs:"
- "^test:"
# TODO(mf): add docker support?
8 changes: 0 additions & 8 deletions Dockerfile.local

This file was deleted.

26 changes: 18 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ dist:
GOOS=windows GOARCH=amd64 go build -o ./bin/goose-windows64.exe ./cmd/goose
GOOS=windows GOARCH=386 go build -o ./bin/goose-windows386.exe ./cmd/goose

.PHONY: build
build:
go build -o $$GOBIN/goose ./cmd/goose

.PHONY: clean
clean:
@find . -type f -name '*.FAIL' -delete
Expand All @@ -28,25 +32,31 @@ test-packages:
test-e2e: test-e2e-postgres test-e2e-mysql test-e2e-clickhouse test-e2e-vertica

test-e2e-postgres:
go test $(GO_TEST_FLAGS) ./tests/e2e -dialect=postgres
go test $(GO_TEST_FLAGS) ./tests/e2e/postgres

test-e2e-mysql:
go test $(GO_TEST_FLAGS) ./tests/e2e -dialect=mysql
go test $(GO_TEST_FLAGS) ./tests/e2e/mysql

test-e2e-clickhouse:
go test $(GO_TEST_FLAGS) ./tests/clickhouse -test.short
go test $(GO_TEST_FLAGS) ./tests/e2e/clickhouse -test.short

test-e2e-vertica:
go test $(GO_TEST_FLAGS) ./tests/vertica
go test $(GO_TEST_FLAGS) ./tests/e2e/vertica

docker-cleanup:
docker stop -t=0 $$(docker ps --filter="label=goose_test" -aq)

docker-start-postgres:
docker run --rm -d \
-e POSTGRES_USER=${GOOSE_POSTGRES_DB_USER} \
-e POSTGRES_PASSWORD=${GOOSE_POSTGRES_PASSWORD} \
-e POSTGRES_DB=${GOOSE_POSTGRES_DBNAME} \
-p ${GOOSE_POSTGRES_PORT}:5432 \
-e POSTGRES_USER=${POSTGRES_DB_USER} \
-e POSTGRES_PASSWORD=${POSTGRES_PASSWORD} \
-e POSTGRES_DB=${POSTGRES_DBNAME} \
-p ${POSTGRES_PORT}:5432 \
-l goose_test \
postgres:14-alpine -c log_statement=all

todo:
rg --type go --ignore-case '//.*(todo|feat)\('

gh-links:
rg --type go --ignore-case '//.*github.com/.*/(issues|pull)/[0-9]+'
61 changes: 61 additions & 0 deletions apply_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package goose

import (
"context"
"database/sql"
"errors"
"fmt"

"github.com/pressly/goose/v4/internal/sqlparser"
"go.uber.org/multierr"
)

// ApplyVersion applies exactly one migration at the specified version. If a migration cannot be
// found for the specified version, this method returns ErrNoCurrentVersion. If the migration has
// been applied already, this method returns ErrAlreadyApplied.
//
// If the direction is true, the migration will be applied. If the direction is false, the migration
// will be rolled back.
func (p *Provider) ApplyVersion(ctx context.Context, version int64, direction bool) (_ *MigrationResult, retErr error) {
if version < 1 {
return nil, fmt.Errorf("invalid version: %d", version)
}

m, err := p.getMigration(version)
if err != nil {
return nil, err
}

conn, cleanup, err := p.initialize(ctx)
if err != nil {
return nil, err
}
defer func() {
retErr = multierr.Append(retErr, cleanup())
}()
// Ensure version table exists.
if err := p.ensureVersionTable(ctx, conn); err != nil {
return nil, err
}

result, err := p.store.GetMigration(ctx, conn, version)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return nil, err
}
if result != nil {
return nil, ErrAlreadyApplied
}

d := sqlparser.DirectionDown
if direction {
d = sqlparser.DirectionUp
}
results, err := p.runMigrations(ctx, conn, []*migration{m}, d, true)
if err != nil {
return nil, err
}
if len(results) == 0 {
return nil, ErrAlreadyApplied
}
return results[0], nil
}
2 changes: 1 addition & 1 deletion cmd/goose/driver_mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
package main

import (
_ "github.com/denisenkom/go-mssqldb"
_ "github.com/microsoft/go-mssqldb"
)
Loading