67 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			Makefile
		
	
	
	
	
	
| # Go parameters
 | |
| GOCMD = go
 | |
| GOBUILD = $(GOCMD) build
 | |
| GOCLEAN = $(GOCMD) clean
 | |
| GOTEST = $(GOCMD) test
 | |
| GOGET = $(GOCMD) get
 | |
| 
 | |
| # SQLite database filename
 | |
| DB_FILE = db.sqlite3
 | |
| 
 | |
| # Directory containing migration SQL scripts
 | |
| MIGRATIONS_DIR = internal/database/migrations
 | |
| 
 | |
| # Build target
 | |
| build:
 | |
| 	$(GOBUILD) -o bin/server cmd/*.go
 | |
| 
 | |
| # Run target
 | |
| run: build
 | |
| 	./bin/server
 | |
| 
 | |
| watch: build
 | |
| 	watchexec -c -w . -r make run
 | |
| 
 | |
| # Clean target
 | |
| clean:
 | |
| 	$(GOCLEAN)
 | |
| 	rm -rf bin
 | |
| 	rm -f db.sqlite3
 | |
| 
 | |
| # Test target
 | |
| test: db.sqlite3
 | |
| 	$(GOTEST) ./... -count=1 -v
 | |
| 
 | |
| # Get dependencies target
 | |
| deps:
 | |
| 	$(GOGET) -v ./...
 | |
| 
 | |
| # Update dependencies target
 | |
| update:
 | |
| 	$(GOGET) -u -v ./...
 | |
| 	$(GOCMD) mod tidy
 | |
| 
 | |
| # Migration target
 | |
| migrate:
 | |
| 	@echo "Migrating database $(DB_FILE) using SQL scripts in $(MIGRATIONS_DIR)"
 | |
| 	@for file in $(wildcard $(MIGRATIONS_DIR)/*.sql); do \
 | |
| 		echo "Applying migration: $$file"; \
 | |
| 		sqlite3 $(DB_FILE) < $$file; \
 | |
| 	done
 | |
| 
 | |
| # Target added primarily for CI/CD to ensure that the database is created before running tests
 | |
| db.sqlite3:
 | |
| 	make migrate
 | |
| 
 | |
| backup:
 | |
| 	mkdir -p backups
 | |
| 	sqlite3 $(DB_FILE) .dump | gzip -9 > ./backups/BACKUP_$(DB_FILE)_$(shell date +"%Y-%m-%d_%H:%M:%S").sql.gz
 | |
| 	# Restore with:
 | |
| 	# gzip -cd BACKUP_FILE.sql.gz | sqlite3 $(DB_FILE)
 | |
| 
 | |
| # Format
 | |
| fmt:
 | |
| 	$(GOCMD) fmt ./...
 | |
| 	
 | |
| # Default target
 | |
| default: build	
 | 
