Skip to content

Commit

Permalink
*: bump versions, use embed
Browse files Browse the repository at this point in the history
- Update go version to 1.17
- Update golangci-lint version to 1.44.2
- Use //go:embed instead of an external embedding tool
- Migrate from DoneCI to Github actions
  • Loading branch information
lopezator committed Mar 7, 2022
1 parent b27b7dc commit b9d70d9
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 319 deletions.
51 changes: 0 additions & 51 deletions .drone.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "migrator build"

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: prepare
run: |
docker compose up -d --build
docker compose exec -T migrator make prepare
- name: sanity-check
run: docker compose exec -T migrator make sanity-check
- name: test
env:
POSTGRES_URL: postgres://postgres:migrator@postgres:5432/migrator?sslmode=disable
MYSQL_URL: root:migrator@tcp(mysql:3306)/migrator
run: |
docker compose exec -T migrator make test POSTGRES_URL="${POSTGRES_URL}" MYSQL_URL="${MYSQL_URL}"
docker compose cp migrator:/go/src/github.com/lopezator/migrator/coverage.txt .
- name: coverage
uses: codecov/codecov-action@v2
with:
files: ./coverage.txt
- name: clean
run: docker compose down -v
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ linters:
- errcheck
- gocritic
- goimports
- golint
- revive
- govet
- megacheck

Expand Down
5 changes: 2 additions & 3 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM golang:1.11.5-stretch
FROM golang:1.17

ENV OS linux
ENV GO111MODULE on
ENV PKGPATH github.com/lopezator/migrator
ENV CGO_ENABLED 0

# golangci-lint
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GOPATH/bin v1.15.0
RUN curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $GOPATH/bin v1.44.2

# copy current workspace
WORKDIR ${GOPATH}/src/${PKGPATH}
Expand Down
14 changes: 4 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@

SHELL = /bin/bash

GOPROXY = https://proxy.golang.org
POSTGRES_URL = postgres://postgres@postgres:5432/migrator?sslmode=disable
MYSQL_URL = root:mysql@tcp(mysql:3306)/migrator
POSTGRES_URL = postgres://postgres:migrator@postgres:5432/migrator?sslmode=disable
MYSQL_URL = root:migrator@tcp(mysql:3306)/migrator

.PHONY: setup-env
setup-env:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.31.0
GO111MODULE=off go get -u github.com/mjibson/esc

.PHONY: esc-gen
esc-gen:
esc -pkg migrator -private -include=".*.sql$$" -modtime="0" testdata > sql.go
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.44.2

.PHONY: prepare
prepare: setup-env mod-download

.PHONY: mod-download
mod-download:
@echo "Running download..."
GOPROXY="$(GOPROXY)" go mod download
go mod download

.PHONY: sanity-check
sanity-check: golangci-lint
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Dead simple Go database migration library.
* Usage as a library, embeddable and extensible on your behalf
* Support of any database supported by `database/sql`
* Go code migrations, either transactional or transaction-less, using `*sql.Tx` (`migrator.Migration`) or `*sql.DB` (`migrator.MigrationNoTx`)
* No need to use `packr`, `gobin` or others, since all migrations are just Go code
* No need to use `//go:embed` or others, since all migrations are just Go code

# Compatibility

Expand Down Expand Up @@ -106,7 +106,7 @@ Just examine the [migrator_test.go](migrator_test.go) file.

You still can use your favorite embedding tool to write your migrations inside `.sql` files and load them into migrator!

I provide a simple example using [esc](https://github.com/mjibson/esc) on the `Using tx, one embedded query` test here: [migrator_test](https://github.com/lopezator/migrator/blob/master/migrator_test.go)
I provide a simple example using `//go:embed` on the `Using tx, one embedded query` test here: [migrator_test](https://github.com/lopezator/migrator/blob/master/migrator_test.go)

### Erm... Where are the ID's of the migrations to know their order? 🤔

Expand Down
11 changes: 6 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ services:
tty: true

postgres:
image: postgres:11.2
image: postgres:14.2
environment:
POSTGRES_DB: migrator
POSTGRES_PASSWORD: migrator
ports:
- 2345:5432
- "2345:5432"

mysql:
image: mysql:8.0.15
image: mysql:8.0.28
environment:
MYSQL_DATABASE: migrator
MYSQL_ROOT_PASSWORD: mysql
MYSQL_ROOT_PASSWORD: migrator
ports:
- 6033:3306
- "6033:3306"
15 changes: 14 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
module github.com/lopezator/migrator

go 1.15
go 1.17

require (
github.com/go-sql-driver/mysql v1.4.1
github.com/jackc/pgx/v4 v4.9.0
)

require (
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.7.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.0.5 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.5.0 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
google.golang.org/appengine v1.4.0 // indirect
)
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,10 @@ github.com/jackc/puddle v1.1.2/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand Down Expand Up @@ -146,7 +143,6 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
Expand All @@ -166,7 +162,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
Expand Down
12 changes: 6 additions & 6 deletions migrator_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// +build integration
//go:build integration

package migrator

import (
"database/sql"
_ "embed"
"fmt"
"log"
"os"
Expand All @@ -13,6 +14,9 @@ import (
_ "github.com/jackc/pgx/v4/stdlib" // postgres driver
)

//go:embed testdata/0_bar.sql
var mig0bar string

var migrations = []interface{}{
&Migration{
Name: "Using tx, encapsulate two queries",
Expand All @@ -38,11 +42,7 @@ var migrations = []interface{}{
&Migration{
Name: "Using tx, one embedded query",
Func: func(tx *sql.Tx) error {
query, err := _escFSString(false, "/testdata/0_bar.sql")
if err != nil {
return err
}
if _, err := tx.Exec(query); err != nil {
if _, err := tx.Exec(mig0bar); err != nil {
return err
}
return nil
Expand Down
Loading

0 comments on commit b9d70d9

Please sign in to comment.