Skip to content

Commit

Permalink
Fix migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Khang Ha committed Sep 5, 2020
1 parent 8b27601 commit 7682fd4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ it uses:
- [gorm](https://github.com/go-gorm/gorm)
- mysql
- [swaggo](https://github.com/swaggo/swag) for docs
- [goose](https://github.com/pressly/goose) for migrations
- [beego](https://github.com/beego/bee) for migrations

## Installation
```
Expand Down
2 changes: 2 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ var initCmd = &cobra.Command{
logrus.Fatal(err)
}

err = utils.CreateFile(fmt.Sprintf("./%v",".env"), []byte(templates.EnvTemplate))

folder, _ := os.Getwd()
output, err := utils.GoModInit(moduleName, folder)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions templates/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package templates

const EnvTemplate = `export MYSQL_USER=root
export MYSQL_PASS=root
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_DB=test
`
16 changes: 8 additions & 8 deletions templates/makefile.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package templates

const MakefileTemplate = `prepare:
@go get -u github.com/pressly/goose
@go get -u github.com/beego/bee
@go get -u github.com/swaggo/swag
@go mod download
migration:
@cd $(PWD)/migrations && read -p "Enter migration name: " migration_name; \
goose create $${migration_name} sql
migration: ## Generate new migration
@read -p "Enter migration name:" migration_name; \
cd $(PWD); bee generate migration $${migration_name}
migrate:
@goose up
migrate: ## Run database migrations
@cd $(PWD) && bee migrate --conn="$(MYSQL_USER):$(MYSQL_PASS)@tcp($(MYSQL_HOST):$(MYSQL_PORT))/$(MYSQL_DB)?charset=utf8"
run:
@cd $(PWD)/cmd && go run *.go
Expand All @@ -19,9 +19,9 @@ build:
@cd $(PWD)/cmd && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
gen_docs:
@cp $(PWD)/cmd/main.go $(PWD)/src
@cp $(PWD)/cmd/main.go $(PWD)
@cd $(PWD) && swag init
@rm -rf $(PWD)/main.go
@rm -rf $(PWD)/cmd/docs
@mv $(PWD)/docs $(PWD)/cmd/mobile
@mv $(PWD)/docs $(PWD)/cmd
`

0 comments on commit 7682fd4

Please sign in to comment.