Actualized code, mod was added, travis CI setup added, license.

v1 1.0.0
Alex 2020-01-08 17:34:31 +01:00
parent 36a094ba1d
commit 84695b56b7
24 changed files with 860 additions and 32 deletions

94
.gitignore vendored
View File

@ -0,0 +1,94 @@
# Created by .ignore support plugin (hsz.mobi)
### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
vendor/
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
*.log
*.bak
#swagger.json
bin/*-x64.*
.cache/
coverage.*
data/

60
.travis.yml Normal file
View File

@ -0,0 +1,60 @@
language: go
cache:
directories:
- "$GOPATH/pkg/mod"
install: true
addons:
artifacts:
debug: true
go:
- 1.13.x
env:
global:
- GOPROXY=https://proxy.golang.org
- GO111MODULE=on
- GOARCH=amd64
- GO_FOR_RELEASE=1.13
jobs:
allow_failures:
- go: master
include:
- go: master
env: JOB=test
script:
- go test -race -coverprofile=coverage.txt -covermode=atomic ./...
after_success:
- bash <(curl -s https://codecov.io/bash)
- stage: build
script:
- go get -t -v ./...
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w
-X 'github.com/go-migration/gorm-goose/version.BuildVersion=`git tag|tail -n1`'
-X 'github.com/go-migration/gorm-goose/version.BuildHash=`git rev-parse HEAD`'
-X 'github.com/go-migration/gorm-goose/version.BuildTime=`date`'"
-o ./gorm-goose-x64.linux ./cmd/gorm-goose/
- CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w
-X 'github.com/go-migration/gorm-goose/version.BuildVersion=`git tag|tail -n1`'
-X 'github.com/go-migration/gorm-goose/version.BuildHash=`git rev-parse HEAD`'
-X 'github.com/go-migration/gorm-goose/version.BuildTime=`date`'"
-o ./gorm-goose-x64.macos ./cmd/gorm-goose/
- CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w
-X 'github.com/go-migration/gorm-goose/version.BuildVersion=`git tag|tail -n1`'
-X 'github.com/go-migration/gorm-goose/version.BuildHash=`git rev-parse HEAD`'
-X 'github.com/go-migration/gorm-goose/version.BuildTime=`date`'"
-o ./gorm-goose-x64.exe ./cmd/gorm-goose/
deploy:
provider: releases
api_key:
secure: FgbZF11lCGwGWjnd+9A4Wn1mSE9Iv3p1g7cjZyQ5CeT5HULkWC3HioZACyl6TtKV7Mtvz8CEOBb24clkDyzbmBNV8E8p5Sb+IkOiYm7T5ardTi1R+PAuhE7AAwT8kR25JtZSTjXaOrAdzgcqp8S/eID1e+PpOAgs1GWEKgvE4ff8Q4WGJs7edipdBJjLyWwHlKFjAIb+53eRZcrKpP0M+oVMS9E/IT7Dax0n+rIeJ45P9XO+xvIREW8eTM+xHY+J94tXKylY5kXU/4IZ4iLMDbN84lrs7T+QeeViSNxkfCpinapFIpkbxbgNH6EXEBUXXe6LmcZA2VnyVIHHwbiA3CsSn4UjCn4DSiTaOtPDNnqPFdhApvxKgeTP/qvi1HPpkI/g7xrwvdd/QZCwVaLnY+C4T55wj0qdaceIpj0dbDFNm1IcRtLmqXxZ3wL374O/PlAtFW8K/dVmYYKeMZ7sS/78ou6tNoj7bqWigg3B7fz+AOmhuOre8TY18rlFj9Icw8Ck+2jk0Cb0WCbZNfak9RMFfRa3mBJwx/tKIq8ZwtJB03JOf7UZqFkQ3EmoUYEX3exdSldfJQL2KHHHAhgMOR2/Qn5k/U0WAtvB3R8qdga6iwxHFHgM8FuTDt1qitFIE+lpbq0hjHfF5yW0MoivlwF7n8e8B7M5tHy8FD2qNLI=
skip_cleanup: true
file:
- gorm-goose-x64.linux
- gorm-goose-x64.macos
- gorm-goose-x64.exe
on:
repo: go-migration/gorm-goose
tags: true
notifications:
email:
on_success: change
on_failure: always

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2020 Alex aka mailoman <alex@webz.asia>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,25 +1,29 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/go-migration/gorm-goose)](https://goreportcard.com/report/github.com/go-migration/gorm-goose)
[![Build Status](https://travis-ci.org/go-migration/gorm-goose.svg?branch=master)](https://travis-ci.org/go-migration/gorm-goose)
[![codecov](https://codecov.io/gh/go-migration/gorm-goose/branch/master/graph/badge.svg)](https://codecov.io/gh/go-migration/gorm-goose)
# gorm-goose
This is a fork of [https://bitbucket.org/liamstask/goose](https://bitbucket.org/liamstask/goose) for [gorm](https://github.com/jinzhu/gorm).
This is a fork of (https://github.com/Altoros/gorm-goose)[https://github.com/Altoros/gorm-goose] which is also fork of [https://bitbucket.org/liamstask/goose](https://bitbucket.org/liamstask/goose) for [gorm](https://github.com/jinzhu/gorm).
gorm-goose is a database migration tool for [gorm](https://github.com/jinzhu/gorm).
Currently, available drivers are: "postgres", "mysql", or "sqlite3".
You can manage your database's evolution by creating incremental SQL or Go scripts.
# Install
## Install
$ go get github.com/Altoros/gorm-goose/cmd/gorm-goose
$ go get github.com/go-migration/gorm-goose/cmd/gorm-goose
This will install the `gorm-goose` binary to your `$GOPATH/bin` directory.
You can also build gorm-goose into your own applications by importing `github.com/Altoros/gorm-goose/lib/gorm-goose`.
You can also build gorm-goose into your own applications by importing `github.com/go-migration/gorm-goose/lib/gorm-goose`.
# Usage
## Usage
gorm-goose provides several commands to help manage your database schema.
## create
### create
Create a new Go migration.
@ -33,7 +37,7 @@ You can also create an SQL migration:
$ gorm-goose create AddSomeColumns sql
$ goose: created db/migrations/20130106093224_AddSomeColumns.sql
## up
### up
Apply all available migrations.
@ -43,7 +47,7 @@ Apply all available migrations.
$ OK 002_next.sql
$ OK 003_and_again.go
### option: pgschema
#### option: pgschema
Use the `pgschema` flag with the `up` command specify a postgres schema.
@ -53,7 +57,7 @@ Use the `pgschema` flag with the `up` command specify a postgres schema.
$ OK 002_next.sql
$ OK 003_and_again.go
## down
### down
Roll back a single migration from the current version.
@ -61,7 +65,7 @@ Roll back a single migration from the current version.
$ goose: migrating db environment 'development', current version: 3, target: 2
$ OK 003_and_again.go
## redo
### redo
Roll back the most recently applied migration, then run it again.
@ -71,7 +75,7 @@ Roll back the most recently applied migration, then run it again.
$ goose: migrating db environment 'development', current version: 2, target: 3
$ OK 003_and_again.go
## status
### status
Print the status of all migrations:
@ -83,7 +87,7 @@ Print the status of all migrations:
$ Sun Jan 6 11:25:03 2013 -- 002_next.sql
$ Pending -- 003_and_again.go
## dbversion
### dbversion
Print the current version of the database:
@ -94,11 +98,11 @@ Print the current version of the database:
`gorm-goose -h` provides more detailed info on each command.
# Migrations
## Migrations
gorm-goose supports migrations written in SQL or in Go - see the `gorm-goose create` command above for details on how to generate them.
## SQL Migrations
### SQL Migrations
A sample SQL migration looks like:
@ -176,7 +180,7 @@ The numeric portion of the function name (`20130106222315`) must be the leading
A transaction is provided, rather than the DB instance directly, since gorm-goose also needs to record the schema version within the same transaction. Each migration should run as a single transaction to ensure DB integrity, so it's good practice anyway.
# Configuration
## Configuration
gorm-goose expects you to maintain a folder (typically called "db"), which contains the following:
@ -199,7 +203,7 @@ You may include as many environments as you like, and you can use the `-env` com
gorm-goose will expand environment variables in the `open` element. For an example, see the Heroku section below.
## Using goose with Heroku
### Using goose with Heroku
These instructions assume that you're using [Keith Rarick's Heroku Go buildpack](https://github.com/kr/heroku-buildpack-go). First, add a file to your project called (e.g.) `install_goose.go` to trigger building of the goose executable during deployment, with these contents:
@ -210,7 +214,7 @@ These instructions assume that you're using [Keith Rarick's Heroku Go buildpack]
// note: need at least one blank line after build constraint
package main
import _ "github.com/Altoros/gorm-goose/cmd/gorm-goose"
import _ "github.com/go-migration/gorm-goose/cmd/gorm-goose"
```
[Set up your Heroku database(s) as usual.](https://devcenter.heroku.com/articles/heroku-postgresql)
@ -226,3 +230,19 @@ production:
To run gorm-goose in production, use `heroku run`:
heroku run gorm-goose -env production up
## License
Copyright 2020 Alex aka mailoman <alex@webz.asia>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package main
import (

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package main
import (
@ -7,7 +28,7 @@ import (
"path/filepath"
"time"
goose "github.com/Altoros/gorm-goose/lib/gorm-goose"
goose "github.com/go-migration/gorm-goose/lib/gorm-goose"
)
var createCmd = &Command{

View File

@ -1,10 +1,31 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package main
import (
"fmt"
"log"
goose "github.com/Altoros/gorm-goose/lib/gorm-goose"
goose "github.com/go-migration/gorm-goose/lib/gorm-goose"
)
var dbVersionCmd = &Command{

View File

@ -1,9 +1,30 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package main
import (
"log"
goose "github.com/Altoros/gorm-goose/lib/gorm-goose"
goose "github.com/go-migration/gorm-goose/lib/gorm-goose"
)
var downCmd = &Command{

View File

@ -1,9 +1,30 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package main
import (
"log"
goose "github.com/Altoros/gorm-goose/lib/gorm-goose"
goose "github.com/go-migration/gorm-goose/lib/gorm-goose"
)
var redoCmd = &Command{

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package main
import (
@ -6,7 +27,7 @@ import (
"path/filepath"
"time"
goose "github.com/Altoros/gorm-goose/lib/gorm-goose"
goose "github.com/go-migration/gorm-goose/lib/gorm-goose"
"github.com/jinzhu/gorm"
)

View File

@ -1,9 +1,30 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package main
import (
"log"
goose "github.com/Altoros/gorm-goose/lib/gorm-goose"
goose "github.com/go-migration/gorm-goose/lib/gorm-goose"
)
var upCmd = &Command{

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package main
import (
@ -7,13 +28,20 @@ import (
"strings"
"text/template"
goose "github.com/Altoros/gorm-goose/lib/gorm-goose"
goose "github.com/go-migration/gorm-goose/lib/gorm-goose"
"github.com/go-migration/gorm-goose/version"
)
// global options. available to any subcommands.
var flagPath = flag.String("path", "db", "folder containing db info")
var flagEnv = flag.String("env", "development", "which DB environment to use")
var flagPgSchema = flag.String("pgschema", "", "which postgres-schema to migrate (default = none)")
var (
flagPath = flag.String("path", "db", "folder containing db info")
flagEnv = flag.String("env", "development", "which DB environment to use")
flagPgSchema = flag.String("pgschema", "", "which postgres-schema to migrate (default = none)")
showVersion1 = flag.Bool("version", false, "show version")
showVersion2 = flag.Bool("v", false, "show version")
showInfo1 = flag.Bool("info", false, "show version")
showInfo2 = flag.Bool("i", false, "show version")
)
// helper to create a DBConf from the given flags
func dbConfFromFlags() (dbconf *goose.DBConf, err error) {
@ -36,7 +64,21 @@ func main() {
args := flag.Args()
if len(args) == 0 || args[0] == "-h" {
if len(args) == 0 {
if *showVersion1 || *showVersion2 {
fmt.Fprintf(os.Stderr, "version: %s\n", version.Version())
return
}
if *showInfo1 || *showInfo2 {
fmt.Fprintf(os.Stderr, "version: %s\nbuild: %s\ntime: %s\n", version.Version(), version.Build(), version.Time())
return
}
}
flag.Usage()
return
}
@ -64,14 +106,15 @@ func usage() {
usageTmpl.Execute(os.Stdout, commands)
}
var usagePrefix = `
var usagePrefix = fmt.Sprintf(`
gorm-goose is a database migration management system for Go projects.
version: %s(%s, %s)
Usage:
gorm-goose [options] <subcommand> [subcommand options]
Options:
`
`, version.Version(), version.Build(), version.Time())
var usageTmpl = template.Must(template.New("usage").Parse(
`
Commands:{{range .}}

View File

@ -1,4 +1,4 @@
package main
package migrations
import (
"fmt"

8
go.mod Normal file
View File

@ -0,0 +1,8 @@
module github.com/go-migration/gorm-goose
go 1.13
require (
github.com/jinzhu/gorm v1.9.12
github.com/kylelemons/go-gypsy v0.0.0-20160905020020-08cad365cd28
)

27
go.sum Normal file
View File

@ -0,0 +1,27 @@
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/jinzhu/gorm v1.9.12 h1:Drgk1clyWT9t9ERbzHza6Mj/8FY/CqMyVzOiHviMo6Q=
github.com/jinzhu/gorm v1.9.12/go.mod h1:vhTjlKSJUTWNtcbQtrMBFCxy7eXTzeCAzfL5fBZT/Qs=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kylelemons/go-gypsy v0.0.0-20160905020020-08cad365cd28 h1:mkl3tvPHIuPaWsLtmHTybJeoVEW7cbePK73Ir8VtruA=
github.com/kylelemons/go-gypsy v0.0.0-20160905020020-08cad365cd28/go.mod h1:T/T7jsxVqf9k/zYOqbgNAsANsjxTd1Yq3htjDhQ1H0c=
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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=

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package gormgoose
import (

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package gormgoose
import (

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package gormgoose
import (

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package gormgoose
import (

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package gormgoose
import (
@ -97,7 +118,7 @@ import (
"encoding/gob"
_ "{{.Import}}"
goose "github.com/Altoros/gorm-goose/lib/gorm-goose"
goose "github.com/go-migration/gorm-goose/lib/gorm-goose"
)
func main() {

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package gormgoose
import (

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package gormgoose
import (

View File

@ -1,3 +1,24 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package gormgoose
import (

60
version/version.go Normal file
View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Alex aka mailoman <alex@webz.asia>
* @copyright Copyright (c) 2020 Alex aka mailoman <alex@webz.asia>
* @since 08.01.2020
*
*/
package version
type buildInfo struct {
version string
hash string
time string
}
var (
BuildVersion = "unknown"
BuildHash = "unknown"
BuildTime = "unknown"
serverBuildInfo *buildInfo
)
func init() {
serverBuildInfo = New()
}
func New() *buildInfo {
if serverBuildInfo == nil {
serverBuildInfo = &buildInfo{
BuildVersion, BuildHash, BuildTime,
}
}
return serverBuildInfo
}
func Version() string {
return serverBuildInfo.version
}
func Build() string {
return serverBuildInfo.hash
}
func Time() string {
return serverBuildInfo.time
}