Skip to content

Commit 7393377

Browse files
authored
Merge branch 'master' into patch-1
2 parents 074b27e + 61ee1bf commit 7393377

24 files changed

+439
-244
lines changed

.github/workflows/golang.yml

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: golang
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
jobs:
8+
test:
9+
strategy:
10+
fail-fast: true
11+
matrix:
12+
go-version: [ '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20']
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: checkout
16+
uses: actions/checkout@v3
17+
- name: setup-go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
cache: true
22+
cache-dependency-path: go.sum
23+
- name: go build
24+
run: go build -o ./bin/sql-migrate ./sql-migrate && ./bin/sql-migrate --help
25+
- name: go test
26+
run: go test ./...
27+
lint:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: checkout
31+
uses: actions/checkout@v3
32+
- name: setup-go
33+
uses: actions/setup-go@v4
34+
with:
35+
go-version: '1.20'
36+
cache: true
37+
cache-dependency-path: go.sum
38+
- name: golangci-lint
39+
uses: golangci/golangci-lint-action@v3
40+
with:
41+
version: v1.52.2
42+
- name: go mod tidy
43+
run: go mod tidy
44+
- name: check for any changes
45+
run: |
46+
[[ $(git status --porcelain) == "" ]] || (echo "changes detected" && exit 1)
47+
integration:
48+
needs:
49+
- test
50+
- lint
51+
runs-on: ubuntu-latest
52+
strategy:
53+
fail-fast: true
54+
matrix:
55+
go-version: [ '1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20']
56+
services:
57+
mysql:
58+
image: mysql:8.0
59+
env:
60+
MYSQL_ALLOW_EMPTY_PASSWORD: '1'
61+
MYSQL_ROOT_PASSWORD: ''
62+
MYSQL_DATABASE: 'test'
63+
ports:
64+
- 3306:3306
65+
options: >-
66+
--health-cmd="mysqladmin ping"
67+
--health-interval=10s
68+
--health-timeout=5s
69+
--health-retries=3
70+
postgres:
71+
image: postgres:15
72+
env:
73+
POSTGRES_PASSWORD: 'password'
74+
ports:
75+
- 5432:5432
76+
options: >-
77+
--health-cmd pg_isready
78+
--health-interval 10s
79+
--health-timeout 5s
80+
--health-retries 5
81+
env:
82+
MYSQL_HOST: '127.0.0.1'
83+
PGHOST: '127.0.0.1'
84+
PGUSER: 'postgres'
85+
PGPASSWORD: 'password'
86+
steps:
87+
- name: checkout
88+
uses: actions/checkout@v3
89+
- name: setup-go
90+
uses: actions/setup-go@v4
91+
with:
92+
go-version: ${{ matrix.go-version }}
93+
cache: true
94+
cache-dependency-path: go.sum
95+
- name: setup databases
96+
run: |
97+
mysql --user=root -e 'CREATE DATABASE IF NOT EXISTS test;'
98+
mysql --user=root -e 'CREATE DATABASE IF NOT EXISTS test_env;'
99+
psql -U postgres -c 'CREATE DATABASE test;'
100+
- name: install sql-migrate
101+
run: go install ./...
102+
- name: postgres
103+
run: bash ./test-integration/postgres.sh
104+
- name: mysql
105+
run: bash ./test-integration/mysql.sh
106+
- name: mysql-flag
107+
run: bash ./test-integration/mysql-flag.sh
108+
- name: mysql-env
109+
run: bash ./test-integration/mysql-env.sh
110+
- name: sqlite
111+
run: bash ./test-integration/sqlite.sh

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55

66
/sql-migrate/test.db
77
/test.db
8+
.vscode/
9+
bin/

.golangci.yaml

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
linters-settings:
2+
gocritic:
3+
disabled-checks:
4+
- ifElseChain
5+
goimports:
6+
local-prefixes: github.com/rubenv/sql-migrate
7+
govet:
8+
enable-all: true
9+
disable:
10+
- fieldalignment
11+
depguard:
12+
list-type: blacklist
13+
include-go-root: true
14+
include-go-std-lib: true
15+
exhaustive:
16+
default-signifies-exhaustive: true
17+
nolintlint:
18+
allow-unused: false
19+
allow-leading-space: false
20+
allow-no-explanation:
21+
- depguard
22+
require-explanation: true
23+
require-specific: true
24+
revive:
25+
enable-all-rules: false
26+
rules:
27+
- name: atomic
28+
- name: blank-imports
29+
- name: bool-literal-in-expr
30+
- name: call-to-gc
31+
- name: constant-logical-expr
32+
- name: context-as-argument
33+
- name: context-keys-type
34+
- name: dot-imports
35+
- name: duplicated-imports
36+
- name: empty-block
37+
- name: empty-lines
38+
- name: error-naming
39+
- name: error-return
40+
- name: error-strings
41+
- name: errorf
42+
- name: exported
43+
- name: identical-branches
44+
- name: imports-blacklist
45+
- name: increment-decrement
46+
- name: indent-error-flow
47+
- name: modifies-parameter
48+
- name: modifies-value-receiver
49+
- name: package-comments
50+
- name: range
51+
- name: range-val-address
52+
- name: range-val-in-closure
53+
- name: receiver-naming
54+
- name: string-format
55+
- name: string-of-int
56+
- name: struct-tag
57+
- name: time-naming
58+
- name: unconditional-recursion
59+
- name: unexported-naming
60+
- name: unexported-return
61+
- name: superfluous-else
62+
- name: unreachable-code
63+
- name: var-declaration
64+
- name: waitgroup-by-value
65+
- name: unused-receiver
66+
- name: unnecessary-stmt
67+
- name: unused-parameter
68+
run:
69+
tests: true
70+
timeout: 1m
71+
linters:
72+
disable-all: true
73+
enable:
74+
- asciicheck
75+
- depguard
76+
- errcheck
77+
- exhaustive
78+
- gocritic
79+
- gofmt
80+
- gofumpt
81+
- goimports
82+
- govet
83+
- ineffassign
84+
- nolintlint
85+
- revive
86+
- staticcheck
87+
- typecheck
88+
- unused
89+
- whitespace
90+
- errorlint
91+
- gosimple
92+
- unparam
93+
issues:
94+
exclude:
95+
- 'declaration of "err" shadows declaration at' # Allow shadowing of `err` because it's so common
96+
- 'error-strings: error strings should not be capitalized or end with punctuation or a newline'
97+
max-same-issues: 10000
98+
max-issues-per-linter: 10000

.travis.yml

-33
This file was deleted.

Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: test lint build
2+
3+
test:
4+
go test ./...
5+
6+
lint:
7+
golangci-lint run --fix --config .golangci.yaml
8+
9+
build:
10+
mkdir -p bin
11+
go build -o ./bin/sql-migrate ./sql-migrate

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Up/down migrations to allow rollback
1515
* Supports multiple database types in one project
1616
* Works great with other libraries such as [sqlx](https://jmoiron.github.io/sqlx/)
17+
* Supported on go1.13+
1718

1819
## Installation
1920

bindata_test.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func bindata_read(data []byte, name string) ([]byte, error) {
1212
gz, err := gzip.NewReader(bytes.NewBuffer(data))
1313
if err != nil {
14-
return nil, fmt.Errorf("Read %q: %v", name, err)
14+
return nil, fmt.Errorf("Read %q: %w", name, err)
1515
}
1616

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

2323
if err != nil {
24-
return nil, fmt.Errorf("Read %q: %v", name, err)
24+
return nil, fmt.Errorf("Read %q: %w", name, err)
2525
}
2626

2727
return buf.Bytes(), nil
@@ -68,7 +68,7 @@ func test_migrations_2_record_sql() ([]byte, error) {
6868
// It returns an error if the asset could not be found or
6969
// could not be loaded.
7070
func Asset(name string) ([]byte, error) {
71-
canonicalName := strings.Replace(name, "\\", "/", -1)
71+
canonicalName := strings.ReplaceAll(name, "\\", "/")
7272
if f, ok := _bindata[canonicalName]; ok {
7373
return f()
7474
}
@@ -94,19 +94,21 @@ var _bindata = map[string]func() ([]byte, error){
9494
// directory embedded in the file by go-bindata.
9595
// For example if you run go-bindata on data/... and data contains the
9696
// following hierarchy:
97-
// data/
98-
// foo.txt
99-
// img/
100-
// a.png
101-
// b.png
97+
//
98+
// data/
99+
// foo.txt
100+
// img/
101+
// a.png
102+
// b.png
103+
//
102104
// then AssetDir("data") would return []string{"foo.txt", "img"}
103105
// AssetDir("data/img") would return []string{"a.png", "b.png"}
104106
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
105107
// AssetDir("") will return []string{"data"}.
106108
func AssetDir(name string) ([]string, error) {
107109
node := _bintree
108110
if len(name) != 0 {
109-
canonicalName := strings.Replace(name, "\\", "/", -1)
111+
canonicalName := strings.ReplaceAll(name, "\\", "/")
110112
pathList := strings.Split(canonicalName, "/")
111113
for _, p := range pathList {
112114
node = node.Children[p]
@@ -131,8 +133,8 @@ type _bintree_t struct {
131133
}
132134

133135
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
134-
"test-migrations": &_bintree_t{nil, map[string]*_bintree_t{
135-
"1_initial.sql": &_bintree_t{test_migrations_1_initial_sql, map[string]*_bintree_t{}},
136-
"2_record.sql": &_bintree_t{test_migrations_2_record_sql, map[string]*_bintree_t{}},
136+
"test-migrations": {nil, map[string]*_bintree_t{
137+
"1_initial.sql": {test_migrations_1_initial_sql, map[string]*_bintree_t{}},
138+
"2_record.sql": {test_migrations_2_record_sql, map[string]*_bintree_t{}},
137139
}},
138140
}}

0 commit comments

Comments
 (0)