forked from ebhomengo/niki
1
0
Fork 0

feat(niki): add compile daemon (hot reload) and separate migration commands (#88)

This commit is contained in:
Ruhollah 2024-07-15 15:26:14 +03:30
parent 15698b18f9
commit 0eb8f89848
3 changed files with 37 additions and 2 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
.vscode .vscode
# Binaries for programs and plugins # Binaries for programs and plugins
niki
*.exe *.exe
*.exe~ *.exe~
*.dll *.dll

View File

@ -2,6 +2,9 @@
ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST)))) ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST))))
confirm:
@echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]
lint: lint:
which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0) which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0)
golangci-lint run --config=$(ROOT)/.golangci.yml $(ROOT)/... golangci-lint run --config=$(ROOT)/.golangci.yml $(ROOT)/...
@ -28,3 +31,34 @@ docker:
swagger: swagger:
swag init swag init
# Live Reload
watch:
@if command -v CompileDaemon > /dev/null; then \
CompileDaemon -exclude-dir=.git -exclude=".#*" -command="./niki"; \
else \
read -p "Go's 'CompileDaemon' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/githubnemo/CompileDaemon@latest; \
CompileDaemon -exclude-dir=.git -exclude=".#*" -command="./niki"; \
else \
echo "You chose not to install CompileDaemon. Exiting..."; \
exit 1; \
fi; \
fi
migrate/status:
@sql-migrate status -env="production" -config=repository/mysql/dbconfig.yml
# Example: make migrate/new name=add_kindbox_permission
migrate/new:
@echo 'Creating migration file for ${name}...'
@sql-migrate new -env="production" -config=repository/mysql/dbconfig.yml ${name}
migrate/up: confirm
@echo 'Running all migrations...'
@sql-migrate up -env="production" -config=repository/mysql/dbconfig.yml
migrate/down: confirm
@echo 'Tearing down last migration...'
@sql-migrate down -env="production" -config=repository/mysql/dbconfig.yml -limit=1

View File

@ -1,5 +1,5 @@
production: production:
dialect: mysql dialect: mysql
datasource: niki:nikiappt0lk2o20(localhost:3306)/niki_db?parseTime=true datasource: niki:nikiappt0lk2o20@(localhost:3306)/niki_db?parseTime=true
dir: repository/mysql/migration dir: repository/mysql/migration
table: gorp_migrations table: gorp_migrations