Skip to content

Commit

Permalink
Generate kallax files with make targets
Browse files Browse the repository at this point in the history
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 <David.Pordomingo.F@gmail.com>
  • Loading branch information
dpordomingo committed Apr 16, 2019
1 parent 2fcee77 commit 8850ecb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ jobs:
- name: 'Generated code'
script:
- make dependencies
- go generate ./...
- make generate-go
- make no-changes-in-commit
- kallax migrate --input ./store/models/ --out ./store/migrations --name test-changes
- make generate-migrations
- make no-changes-in-commit
- make pack-migrations
- make no-changes-in-commit
Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ LOOKOUT_BIN := $(BIN_PATH)/lookoutd
ESC_BIN := esc
TOC_GENERATOR := $(CI_PATH)/gh-md-toc

# Migrations
MIGRTION_NAME ?= test-changes

.PHONY: pack-migrations
pack-migrations:
chmod -R go=r $(MIGRATIONS_PATH); \
Expand Down Expand Up @@ -141,3 +144,18 @@ clean: clean_modcache
.PHONY: clean_modcache
clean_modcache:
@$(GOCLEAN) -modcache


.PHONY: generate
generate: | generate-go generate-migrations pack-migrations vendor

.PHONY: generate-go
generate-go:
GO111MODULE=off $(GOCMD) generate ./...

.PHONY: generate-migrations
generate-migrations:
GO111MODULE=off kallax migrate \
--input ./store/models/ \
--out ./store/migrations \
--name $(MIGRTION_NAME)
20 changes: 17 additions & 3 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,37 @@ this project follows the following guidelines.

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

To do so, you can generate all needed code and then ensure that nothing is pending to be committed running:

```shell
$ make dependencies
$ make generate
$ make no-changes-in-commit
```

The output of the last command should be empty if there is nothing pending to be committed.

Otherwise you must commit generated code as produced by the following steps:


### kallax

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

```shell
$ go generate ./...
$ make generate-go
```

To update embedded migrations with the new files:

```shell
$ make dependencies
$ kallax migrate --input ./store/models/ --out ./store/migrations --name <name>
$ MIGRTION_NAME=<name> make generate-migrations
$ make pack-migrations
```

where `<name>` is a short and descriptive name of the purpose of the migration; example: `delete_users_table`


### Dependencies

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.
Expand Down

0 comments on commit 8850ecb

Please sign in to comment.