Skip to content
Merged
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
111 changes: 111 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: golang
on:
push:
branches:
- master
pull_request:
jobs:
test:
strategy:
fail-fast: true
matrix:
go-version: [ '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20']
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup-go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: true
cache-dependency-path: go.sum
- name: go build
run: go build -o ./bin/sql-migrate ./sql-migrate && ./bin/sql-migrate --help
- name: go test
run: go test ./...
lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup-go
uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: true
cache-dependency-path: go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
- name: go mod tidy
run: go mod tidy
- name: check for any changes
run: |
[[ $(git status --porcelain) == "" ]] || (echo "changes detected" && exit 1)
integration:
needs:
- test
- lint
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
go-version: [ '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20']
services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: '1'
MYSQL_ROOT_PASSWORD: ''
MYSQL_DATABASE: 'test'
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: 'password'
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
MYSQL_HOST: '127.0.0.1'
PGHOST: '127.0.0.1'
PGUSER: 'postgres'
PGPASSWORD: 'password'
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup-go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: true
cache-dependency-path: go.sum
- name: setup databases
run: |
mysql --user=root -e 'CREATE DATABASE IF NOT EXISTS test;'
mysql --user=root -e 'CREATE DATABASE IF NOT EXISTS test_env;'
psql -U postgres -c 'CREATE DATABASE test;'
- name: install sql-migrate
run: go install ./...
- name: postgres
run: bash ./test-integration/postgres.sh
- name: mysql
run: bash ./test-integration/mysql.sh
- name: mysql-flag
run: bash ./test-integration/mysql-flag.sh
- name: mysql-env
run: bash ./test-integration/mysql-env.sh
- name: sqlite
run: bash ./test-integration/sqlite.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@

/sql-migrate/test.db
/test.db
.vscode/
bin/
98 changes: 98 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
linters-settings:
gocritic:
disabled-checks:
- ifElseChain
goimports:
local-prefixes: github.com/rubenv/sql-migrate
govet:
enable-all: true
disable:
- fieldalignment
depguard:
list-type: blacklist
include-go-root: true
include-go-std-lib: true
exhaustive:
default-signifies-exhaustive: true
nolintlint:
allow-unused: false
allow-leading-space: false
allow-no-explanation:
- depguard
require-explanation: true
require-specific: true
revive:
enable-all-rules: false
rules:
- name: atomic
- name: blank-imports
- name: bool-literal-in-expr
- name: call-to-gc
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: duplicated-imports
- name: empty-block
- name: empty-lines
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: identical-branches
- name: imports-blacklist
- name: increment-decrement
- name: indent-error-flow
- name: modifies-parameter
- name: modifies-value-receiver
- name: package-comments
- name: range
- name: range-val-address
- name: range-val-in-closure
- name: receiver-naming
- name: string-format
- name: string-of-int
- name: struct-tag
- name: time-naming
- name: unconditional-recursion
- name: unexported-naming
- name: unexported-return
- name: superfluous-else
- name: unreachable-code
- name: var-declaration
- name: waitgroup-by-value
- name: unused-receiver
- name: unnecessary-stmt
- name: unused-parameter
run:
tests: true
timeout: 1m
linters:
disable-all: true
enable:
- asciicheck
- depguard
- errcheck
- exhaustive
- gocritic
- gofmt
- gofumpt
- goimports
- govet
- ineffassign
- nolintlint
- revive
- staticcheck
- typecheck
- unused
- whitespace
- errorlint
- gosimple
- unparam
issues:
exclude:
- 'declaration of "err" shadows declaration at' # Allow shadowing of `err` because it's so common
- 'error-strings: error strings should not be capitalized or end with punctuation or a newline'
max-same-issues: 10000
max-issues-per-linter: 10000
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.PHONY: test lint build

test:
go test ./...

lint:
golangci-lint run --fix --config .golangci.yaml

build:
mkdir -p bin
go build -o ./bin/sql-migrate ./sql-migrate
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Up/down migrations to allow rollback
* Supports multiple database types in one project
* Works great with other libraries such as [sqlx](https://jmoiron.github.io/sqlx/)
* Supported on go1.13+

## Installation

Expand Down
26 changes: 14 additions & 12 deletions bindata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func bindata_read(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err)
return nil, fmt.Errorf("Read %q: %w", name, err)
}

var buf bytes.Buffer
Expand All @@ -21,7 +21,7 @@ func bindata_read(data []byte, name string) ([]byte, error) {
}

if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err)
return nil, fmt.Errorf("Read %q: %w", name, err)
}

return buf.Bytes(), nil
Expand Down Expand Up @@ -68,7 +68,7 @@ func test_migrations_2_record_sql() ([]byte, error) {
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
canonicalName := strings.Replace(name, "\\", "/", -1)
canonicalName := strings.ReplaceAll(name, "\\", "/")
if f, ok := _bindata[canonicalName]; ok {
return f()
}
Expand All @@ -94,19 +94,21 @@ var _bindata = map[string]func() ([]byte, error){
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
//
// data/
// foo.txt
// img/
// a.png
// b.png
//
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
canonicalName := strings.Replace(name, "\\", "/", -1)
canonicalName := strings.ReplaceAll(name, "\\", "/")
pathList := strings.Split(canonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
Expand All @@ -131,8 +133,8 @@ type _bintree_t struct {
}

var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
"test-migrations": &_bintree_t{nil, map[string]*_bintree_t{
"1_initial.sql": &_bintree_t{test_migrations_1_initial_sql, map[string]*_bintree_t{}},
"2_record.sql": &_bintree_t{test_migrations_2_record_sql, map[string]*_bintree_t{}},
"test-migrations": {nil, map[string]*_bintree_t{
"1_initial.sql": {test_migrations_1_initial_sql, map[string]*_bintree_t{}},
"2_record.sql": {test_migrations_2_record_sql, map[string]*_bintree_t{}},
}},
}}
Loading