Skip to content

Commit

Permalink
mig version
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed Dec 29, 2022
1 parent 6c200e8 commit a320ac6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ jobs:
goos: windows
steps:
- uses: actions/checkout@v3
- name: Set BUILD_TIME
run: echo BUILD_TIME=$(date +"%Y-%m-%dT%H:%M:%S%z") >> ${GITHUB_ENV}
- name: Set MIG_VERSION
run: echo MIG_VERSION=$(cat version.txt) >> ${GITHUB_ENV}
- uses: wangyoucao577/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "1.19"
binary_name: "mig"
md5sum: false
md5sum: false
ldflags: -s -w -X "github.com/tlhunter/mig/commands.Version=${{ env.MIG_VERSION }}" -X "github.com/tlhunter/mig/commands.BuildTime=${{ env.BUILD_TIME }}"
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
MIG_VERSION = $(shell cat version.txt)
BUILD_TIME = $(shell date +"%Y-%m-%dT%H:%M:%S%z")

# Strip debug info
GO_FLAGS += "-ldflags=-s -w"

# Avoid embedding the build path in the executable for more reproducible builds
GO_FLAGS += -trimpath
GO_FLAGS += "-ldflags=-s -w -X 'github.com/tlhunter/mig/commands.Version=$(MIG_VERSION)' -X 'github.com/tlhunter/mig/commands.BuildTime=$(BUILD_TIME)'"

build:
go build $(GO_FLAGS) -o mig
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ MIG_MIGRATIONS="./db" mig
# create the necessary migration tables
mig init

# get version information
mig version

# list all migrations
mig list

Expand Down Expand Up @@ -156,4 +159,15 @@ DROP TABLE accounts;
--END MIGRATION DOWN--
```

Transactions should only be disabled when a situation calls for it, like when using `CREATE INDEX CONCURRENTLY`. When in doubt, leave transactions enabled.
Transactions should only be disabled when a situation calls for it, like when using `CREATE INDEX CONCURRENTLY`. When in doubt, leave transactions enabled.


## Development

Checkout the project then run the following commands to install dependencies, build, and run the program:

```sh
go get
make
./mig version
```
3 changes: 3 additions & 0 deletions commands/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func Dispatch(cfg config.MigConfig) {
case "all":
CommandAll(cfg)

case "version":
CommandVersion(cfg)

default:
color.White("unsupported command %s", os.Args[1])
os.Exit(10)
Expand Down
16 changes: 16 additions & 0 deletions commands/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package commands

import (
"github.com/fatih/color"
"github.com/tlhunter/mig/config"
)

var Version string // set at compile time
var BuildTime string // set at compile time

func CommandVersion(cfg config.MigConfig) error {
color.Green("mig version: " + Version)
color.White("build time: " + BuildTime)

return nil
}
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module github.com/tlhunter/mig
go 1.19

require (
github.com/fatih/color v1.13.0 // indirect
github.com/joho/godotenv v1.4.0 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/fatih/color v1.13.0
github.com/joho/godotenv v1.4.0
github.com/lib/pq v1.10.7
)

require (
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"os"

"github.com/fatih/color"
"github.com/tlhunter/mig/commands"
"github.com/tlhunter/mig/config"
)
Expand All @@ -11,7 +12,7 @@ func main() {
cfg, err := config.GetConfig()

if err != nil {
os.Stderr.WriteString("unable to parse configuration\n")
color.Red("unable to parse configuration\n")
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.1.1

0 comments on commit a320ac6

Please sign in to comment.