Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'rubenv-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsolofsson committed Jul 19, 2021
2 parents 4ef7730 + 4eaf0f9 commit a33d891
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!go.mod
!go.sum
!*.go
!sql-migrate/*.go
!sqlparse/*.go
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release

on:
release:
types: [ created ]

jobs:
releases-matrix:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux, windows, darwin ]
goarch: [ amd64 ]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: 1.16
pre_command: export CGO_ENABLED=0
project_path: "./sql-migrate"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.*.swp
*.test
.idea
/vendor/

/sql-migrate/test.db
/test.db
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ sudo: false
go:
- "1.13"
- "1.14"
- "1.15"
- "1.16"

services:
- mysql
Expand Down
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG GO_VERSION=1.16.2
ARG ALPINE_VERSION=3.12

### Vendor
FROM golang:${GO_VERSION} as vendor
COPY . /project
WORKDIR /project
RUN go mod tidy && go mod vendor

### Build binary
FROM golang:${GO_VERSION} as build-binary
COPY . /project
COPY --from=vendor /project/vendor /project/vendor
WORKDIR /project
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=on go build \
-v \
-mod vendor \
-o /project/bin/sql-migrate \
/project/sql-migrate

### Image
FROM alpine:${ALPINE_VERSION} as image
COPY --from=build-binary /project/bin/sql-migrate /usr/local/bin/sql-migrate
RUN chmod +x /usr/local/bin/sql-migrate
ENTRYPOINT ["sql-migrate"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (C) 2014-2019 by Ruben Vermeersch <[email protected]>
Copyright (C) 2014-2021 by Ruben Vermeersch <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module github.com/togglhire/sql-migrate

go 1.11
go 1.16

require (
github.com/denisenkom/go-mssqldb v0.9.0
github.com/go-sql-driver/mysql v1.5.0
github.com/gobuffalo/packr/v2 v2.8.1
github.com/godror/godror v0.24.2
github.com/lib/pq v1.10.0
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/mattn/go-oci8 v0.1.1
github.com/mattn/go-sqlite3 v1.14.6
github.com/mitchellh/cli v1.1.2
github.com/olekukonko/tablewriter v0.0.5
github.com/ziutek/mymysql v1.5.4 // indirect
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/gorp.v1 v1.7.2
gopkg.in/yaml.v2 v2.4.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ github.com/markbates/safe v1.0.1 h1:yjZkbvRM6IzKj9tlu/zMJLS0n/V351OZWRnF3QfaUxI=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-oci8 v0.1.1 h1:aEUDxNAyDG0tv8CA3TArnDQNyc4EhnWlsfxRgDHABHM=
github.com/mattn/go-oci8 v0.1.1/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
Expand Down Expand Up @@ -210,9 +209,8 @@ golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f h1:68K/z8GLUxV76xGSqwTWw2gyk/jwn79LUL43rES2g8o=
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
14 changes: 7 additions & 7 deletions migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ type HttpFileSystemMigrationSource struct {
var _ MigrationSource = (*HttpFileSystemMigrationSource)(nil)

func (f HttpFileSystemMigrationSource) FindMigrations() ([]*Migration, error) {
return findMigrations(f.FileSystem)
return findMigrations(f.FileSystem, "/")
}

// A set of migrations loaded from a directory.
Expand All @@ -243,13 +243,13 @@ var _ MigrationSource = (*FileMigrationSource)(nil)

func (f FileMigrationSource) FindMigrations() ([]*Migration, error) {
filesystem := http.Dir(f.Dir)
return findMigrations(filesystem)
return findMigrations(filesystem, "/")
}

func findMigrations(dir http.FileSystem) ([]*Migration, error) {
func findMigrations(dir http.FileSystem, root string) ([]*Migration, error) {
migrations := make([]*Migration, 0)

file, err := dir.Open("/")
file, err := dir.Open(root)
if err != nil {
return nil, err
}
Expand All @@ -261,7 +261,7 @@ func findMigrations(dir http.FileSystem) ([]*Migration, error) {

for _, info := range files {
if strings.HasSuffix(info.Name(), ".sql") {
migration, err := migrationFromFile(dir, info)
migration, err := migrationFromFile(dir, root, info)
if err != nil {
return nil, err
}
Expand All @@ -276,8 +276,8 @@ func findMigrations(dir http.FileSystem) ([]*Migration, error) {
return migrations, nil
}

func migrationFromFile(dir http.FileSystem, info os.FileInfo) (*Migration, error) {
path := fmt.Sprintf("/%s", strings.TrimPrefix(info.Name(), "/"))
func migrationFromFile(dir http.FileSystem, root string, info os.FileInfo) (*Migration, error) {
path := path.Join(root, info.Name())
file, err := dir.Open(path)
if err != nil {
return nil, fmt.Errorf("Error while opening %s: %s", info.Name(), err)
Expand Down
22 changes: 22 additions & 0 deletions migrate_go116.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build go1.16

package migrate

import (
"embed"
"net/http"
)

// A set of migrations loaded from an go1.16 embed.FS

type EmbedFileSystemMigrationSource struct {
FileSystem embed.FS

Root string
}

var _ MigrationSource = (*EmbedFileSystemMigrationSource)(nil)

func (f EmbedFileSystemMigrationSource) FindMigrations() ([]*Migration, error) {
return findMigrations(http.FS(f.FileSystem), f.Root)
}
29 changes: 29 additions & 0 deletions migrate_go116_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// +build go1.16

package migrate

import (
"embed"

. "gopkg.in/check.v1"
)

//go:embed test-migrations/*
var testEmbedFS embed.FS

func (s *SqliteMigrateSuite) TestEmbedSource(c *C) {
migrations := EmbedFileSystemMigrationSource{
FileSystem: testEmbedFS,
Root: "test-migrations",
}

// Executes two migrations
n, err := Exec(s.Db, "sqlite3", migrations, Up)
c.Assert(err, IsNil)
c.Assert(n, Equals, 2)

// Has data
id, err := s.DbMap.SelectInt("SELECT id FROM people")
c.Assert(err, IsNil)
c.Assert(id, Equals, int64(1))
}
2 changes: 1 addition & 1 deletion migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (s *SqliteMigrateSuite) TestPackrMigrate(c *C) {

func (s *SqliteMigrateSuite) TestPackrMigrateDir(c *C) {
migrations := &PackrMigrationSource{
Box: packr.NewBox("."),
Box: packr.New(".", "."),
Dir: "./test-migrations/",
}

Expand Down

0 comments on commit a33d891

Please sign in to comment.