Skip to content

Commit 8850ecb

Browse files
committed
Generate kallax files with make targets
kallax models should be generated with 'make generate-go', kallax migrations should be generated with 'MIGRTION_NAME=<name> make generate-migrations' and packed with 'make pack-migrations' All the code generation: kallax and vendor can be done at once with 'make generate' kallax does not work with go Modules, so it'll be disabled issue: src-d/go-kallax#296 Signed-off-by: David Pordomingo <[email protected]>
1 parent 2fcee77 commit 8850ecb

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ jobs:
8383
- name: 'Generated code'
8484
script:
8585
- make dependencies
86-
- go generate ./...
86+
- make generate-go
8787
- make no-changes-in-commit
88-
- kallax migrate --input ./store/models/ --out ./store/migrations --name test-changes
88+
- make generate-migrations
8989
- make no-changes-in-commit
9090
- make pack-migrations
9191
- make no-changes-in-commit

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ LOOKOUT_BIN := $(BIN_PATH)/lookoutd
4242
ESC_BIN := esc
4343
TOC_GENERATOR := $(CI_PATH)/gh-md-toc
4444

45+
# Migrations
46+
MIGRTION_NAME ?= test-changes
47+
4548
.PHONY: pack-migrations
4649
pack-migrations:
4750
chmod -R go=r $(MIGRATIONS_PATH); \
@@ -141,3 +144,18 @@ clean: clean_modcache
141144
.PHONY: clean_modcache
142145
clean_modcache:
143146
@$(GOCLEAN) -modcache
147+
148+
149+
.PHONY: generate
150+
generate: | generate-go generate-migrations pack-migrations vendor
151+
152+
.PHONY: generate-go
153+
generate-go:
154+
GO111MODULE=off $(GOCMD) generate ./...
155+
156+
.PHONY: generate-migrations
157+
generate-migrations:
158+
GO111MODULE=off kallax migrate \
159+
--input ./store/models/ \
160+
--out ./store/migrations \
161+
--name $(MIGRTION_NAME)

docs/CONTRIBUTING.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,37 @@ this project follows the following guidelines.
1414

1515
Before submitting a pull request make sure all the generated code changes are also committed.
1616

17+
To do so, you can generate all needed code and then ensure that nothing is pending to be committed running:
18+
19+
```shell
20+
$ make dependencies
21+
$ make generate
22+
$ make no-changes-in-commit
23+
```
24+
25+
The output of the last command should be empty if there is nothing pending to be committed.
26+
27+
Otherwise you must commit generated code as produced by the following steps:
28+
1729

1830
### kallax
1931

2032
To generate go code from [kallax](https://github.com/src-d/go-kallax) models, run:
2133

2234
```shell
23-
$ go generate ./...
35+
$ make generate-go
2436
```
2537

2638
To update embedded migrations with the new files:
2739

2840
```shell
29-
$ make dependencies
30-
$ kallax migrate --input ./store/models/ --out ./store/migrations --name <name>
41+
$ MIGRTION_NAME=<name> make generate-migrations
3142
$ make pack-migrations
3243
```
3344

45+
where `<name>` is a short and descriptive name of the purpose of the migration; example: `delete_users_table`
46+
47+
3448
### Dependencies
3549

3650
Go dependencies are managed with [go Modules](https://github.com/golang/go/wiki/Modules). Use `make vendor` to make sure the `vendor` directory is up to date, and commit any necessary changes.

0 commit comments

Comments
 (0)