Skip to content

Commit

Permalink
continue - v4-alpha.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Apr 16, 2023
1 parent 0d1296b commit 1e3c9e4
Show file tree
Hide file tree
Showing 143 changed files with 5,137 additions and 3,350 deletions.
2 changes: 1 addition & 1 deletion .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", "1.19", "1.20"]
go-version: ["1.19", "1.20"]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
Expand Down
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
}
Loading

0 comments on commit 1e3c9e4

Please sign in to comment.