cmc-sales/go/Makefile

124 lines
3.3 KiB
Makefile

.PHONY: help
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: install
install: ## Install dependencies
@echo "Setting up private module configuration..."
go env -w GOPRIVATE=code.springupsoftware.com
go mod download
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
go install github.com/pressly/goose/v3/cmd/goose@latest
.PHONY: sqlc
sqlc: ## Generate Go code from SQL queries
sqlc generate
.PHONY: build
build: sqlc ## Build the application
go build -o bin/server cmd/server/main.go
go build -o bin/vault cmd/vault/main.go
.PHONY: build-server
build-server: sqlc ## Build only the server
go build -o bin/server cmd/server/main.go
.PHONY: build-vault
build-vault: ## Build only the vault command
go build -o bin/vault cmd/vault/main.go
.PHONY: run
run: ## Run the application
go run cmd/server/main.go
.PHONY: run-vault
run-vault: ## Run the vault command
go run cmd/vault/main.go
.PHONY: dev
dev: sqlc ## Run the application with hot reload (requires air)
air
.PHONY: test
test: ## Run tests
go test -v ./...
.PHONY: clean
clean: ## Clean build artifacts
rm -rf bin/
rm -rf internal/cmc/db/*.go
.PHONY: docker-build
docker-build: ## Build Docker image
docker build -t cmc-go:latest -f Dockerfile.go .
.PHONY: docker-run
docker-run: ## Run application in Docker
docker run --rm -p 8080:8080 --network=host cmc-go:latest
.PHONY: dbshell
dbshell: ## Connect to MariaDB database interactively
@echo "Connecting to MariaDB..."
@if [ -z "$$DB_PASSWORD" ]; then \
echo "Reading password from docker-compose environment..."; \
docker compose exec db mariadb -u cmc -p cmc; \
else \
docker compose exec -e MYSQL_PWD="$$DB_PASSWORD" db mariadb -u cmc cmc; \
fi
.PHONY: dbshell-root
dbshell-root: ## Connect to MariaDB as root user
@echo "Connecting to MariaDB as root..."
@if [ -z "$$DB_ROOT_PASSWORD" ]; then \
echo "Please set DB_ROOT_PASSWORD environment variable"; \
exit 1; \
else \
docker compose exec -e MYSQL_PWD="$$DB_ROOT_PASSWORD" db mariadb -u root; \
fi
.PHONY: migrate
migrate: ## Run database migrations
@echo "Running database migrations..."
@if [ -f goose.env ]; then \
export $$(cat goose.env | xargs) && goose up; \
else \
echo "Error: goose.env file not found"; \
exit 1; \
fi
.PHONY: migrate-down
migrate-down: ## Rollback last migration
@echo "Rolling back last migration..."
@if [ -f goose.env ]; then \
export $$(cat goose.env | xargs) && goose down; \
else \
echo "Error: goose.env file not found"; \
exit 1; \
fi
.PHONY: migrate-status
migrate-status: ## Show migration status
@echo "Migration status:"
@if [ -f goose.env ]; then \
export $$(cat goose.env | xargs) && goose status; \
else \
echo "Error: goose.env file not found"; \
exit 1; \
fi
.PHONY: migrate-create
migrate-create: ## Create a new migration file (use: make migrate-create name=add_new_table)
@if [ -z "$(name)" ]; then \
echo "Error: Please provide a migration name. Usage: make migrate-create name=add_new_table"; \
exit 1; \
fi
@echo "Creating new migration: $(name)"
@if [ -f goose.env ]; then \
export $$(cat goose.env | xargs) && goose create $(name) sql; \
else \
echo "Error: goose.env file not found"; \
exit 1; \
fi