Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cashier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
cashier
Commits
f089aaf1
Commit
f089aaf1
authored
6 years ago
by
Niall Sheridan
Browse files
Options
Downloads
Patches
Plain Diff
Add a tool to create empty migrations
parent
b79648e0
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+5
-1
5 additions, 1 deletion
Makefile
generate/migration/migration.go
+53
-0
53 additions, 0 deletions
generate/migration/migration.go
generate/static/static.go
+0
-0
0 additions, 0 deletions
generate/static/static.go
with
58 additions
and
1 deletion
Makefile
+
5
−
1
View file @
f089aaf1
...
@@ -29,8 +29,12 @@ cashierd: generate
...
@@ -29,8 +29,12 @@ cashierd: generate
clean
:
clean
:
rm
-f
cashier cashierd
rm
-f
cashier cashierd
# usage: make migration name=whatever
migration
:
go run ./generate/migration/migration.go
$(
name
)
dep
:
dep
:
go get
-u
github.com/golang/lint/golint
go get
-u
github.com/golang/lint/golint
go get
-u
golang.org/x/tools/cmd/goimports
go get
-u
golang.org/x/tools/cmd/goimports
.PHONY
:
all build dep generate test cashier cashierd clean
.PHONY
:
all build dep generate test cashier cashierd clean
migration
This diff is collapsed.
Click to expand it.
generate/migration/migration.go
0 → 100644
+
53
−
0
View file @
f089aaf1
package
main
import
(
"flag"
"fmt"
"io/ioutil"
"log"
"os/exec"
"path"
"strings"
"time"
)
const
(
dateFormat
=
"20060102150405"
migrationsPath
=
"server/store/migrations"
)
var
(
contents
=
[]
byte
(
`-- +migrate Up
-- +migrate Down`
)
)
func
main
()
{
flag
.
Usage
=
func
()
{
fmt
.
Println
(
"Usage: migration <migration name>"
)
}
flag
.
Parse
()
if
len
(
flag
.
Args
())
!=
1
{
flag
.
Usage
()
}
name
:=
fmt
.
Sprintf
(
"%s_%s.sql"
,
time
.
Now
()
.
UTC
()
.
Format
(
dateFormat
),
flag
.
Arg
(
0
))
gitRoot
,
err
:=
exec
.
Command
(
"git"
,
"rev-parse"
,
"--show-toplevel"
)
.
Output
()
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
root
:=
strings
.
TrimSpace
(
string
(
gitRoot
))
ents
,
err
:=
ioutil
.
ReadDir
(
path
.
Join
(
root
,
migrationsPath
))
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
for
_
,
e
:=
range
ents
{
if
e
.
IsDir
()
{
filename
:=
path
.
Join
(
migrationsPath
,
e
.
Name
(),
name
)
fmt
.
Printf
(
"Wrote empty migration file: %s
\n
"
,
filename
)
if
err
:=
ioutil
.
WriteFile
(
filename
,
contents
,
0644
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
}
}
This diff is collapsed.
Click to expand it.
generate/static.go
→
generate/static
/static
.go
+
0
−
0
View file @
f089aaf1
File moved
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment