From 0eb8f89848d2828f0f20b1ff57351730e7eff31e Mon Sep 17 00:00:00 2001 From: Ruhollah Date: Mon, 15 Jul 2024 15:26:14 +0330 Subject: [PATCH] feat(niki): add compile daemon (hot reload) and separate migration commands (#88) --- .gitignore | 1 + Makefile | 36 ++++++++++++++++++++++++++++++++++- repository/mysql/dbconfig.yml | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bfc531f..d66a986 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .vscode # Binaries for programs and plugins +niki *.exe *.exe~ *.dll diff --git a/Makefile b/Makefile index 9b6fe7a..8771526 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ ROOT=$(realpath $(dir $(lastword $(MAKEFILE_LIST)))) +confirm: + @echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ] + lint: which golangci-lint || (go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.0) golangci-lint run --config=$(ROOT)/.golangci.yml $(ROOT)/... @@ -27,4 +30,35 @@ docker: sudo docker compose up -d swagger: - swag init \ No newline at end of file + 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 \ No newline at end of file diff --git a/repository/mysql/dbconfig.yml b/repository/mysql/dbconfig.yml index addf2ad..ee6c624 100644 --- a/repository/mysql/dbconfig.yml +++ b/repository/mysql/dbconfig.yml @@ -1,5 +1,5 @@ production: dialect: mysql - datasource: niki:nikiappt0lk2o20(localhost:3306)/niki_db?parseTime=true + datasource: niki:nikiappt0lk2o20@(localhost:3306)/niki_db?parseTime=true dir: repository/mysql/migration table: gorp_migrations