- 创建完整的种子数据系统 (seed_data.sql) - 6个用户数据 (管理员 + 5个摄影师) - 9个分类数据 (风景、人像、建筑、街拍、艺术、宠物、食物、旅行、黑白) - 35张照片数据 (涵盖所有分类,均衡分布) - 自动化执行脚本 (run_seed_data.sh) - 数据质量测试脚本 (test_seed_data.sh) - Makefile 集成 (make seed, make test-seed, make db-status) - 完整的使用文档 (SEED_DATA_README.md) - 数据库备份机制,时间戳命名 - 9项自动化测试全部通过,数据质量保证 任务12完成,项目完成率达到40%
134 lines
3.4 KiB
Makefile
134 lines
3.4 KiB
Makefile
# Photography Backend Makefile
|
|
|
|
# 默认配置
|
|
BINARY_NAME=photography-api
|
|
BUILD_DIR=bin
|
|
CONFIG_FILE=etc/photographyapi-api.yaml
|
|
|
|
# 环境变量
|
|
export GO111MODULE=on
|
|
export GOPROXY=https://goproxy.cn,direct
|
|
|
|
# 构建
|
|
build:
|
|
@echo "Building $(BINARY_NAME)..."
|
|
@mkdir -p $(BUILD_DIR)
|
|
go build -o $(BUILD_DIR)/$(BINARY_NAME) cmd/api/main.go
|
|
|
|
# 运行
|
|
run:
|
|
@echo "Running $(BINARY_NAME)..."
|
|
@./$(BUILD_DIR)/$(BINARY_NAME) -f $(CONFIG_FILE)
|
|
|
|
# 开发模式(构建并运行)
|
|
dev: build run
|
|
|
|
# 快速启动(跳过构建)
|
|
quick:
|
|
@echo "Quick start $(BINARY_NAME)..."
|
|
@go run cmd/api/main.go -f $(CONFIG_FILE)
|
|
|
|
# 安装依赖
|
|
install:
|
|
@echo "Installing dependencies..."
|
|
@go mod tidy
|
|
|
|
# 代码生成
|
|
gen:
|
|
@echo "Generating code..."
|
|
@goctl api go -api api/desc/photography.api -dir ./ --style=goZero
|
|
|
|
# 生成模型
|
|
gen-model:
|
|
@echo "Generating models..."
|
|
@goctl model mysql ddl -src internal/model/sql/user.sql -dir internal/model/
|
|
@goctl model mysql ddl -src internal/model/sql/photo.sql -dir internal/model/
|
|
@goctl model mysql ddl -src internal/model/sql/category.sql -dir internal/model/
|
|
|
|
# 清理
|
|
clean:
|
|
@echo "Cleaning..."
|
|
@rm -rf $(BUILD_DIR)
|
|
@go clean
|
|
|
|
# 代码检查
|
|
lint:
|
|
@echo "Running linter..."
|
|
@golangci-lint run
|
|
|
|
# 格式化代码
|
|
fmt:
|
|
@echo "Formatting code..."
|
|
@go fmt ./...
|
|
|
|
# 运行测试
|
|
test:
|
|
@echo "Running tests..."
|
|
@go test -v ./...
|
|
|
|
# 创建必要目录
|
|
setup:
|
|
@echo "Setting up directories..."
|
|
@mkdir -p data uploads $(BUILD_DIR)
|
|
|
|
# 健康检查
|
|
status:
|
|
@echo "API Status:"
|
|
@curl -s http://localhost:8080/api/v1/health || echo "API is not running"
|
|
|
|
# 种子数据管理
|
|
seed:
|
|
@echo "Running seed data..."
|
|
@./run_seed_data.sh
|
|
|
|
# 测试种子数据
|
|
test-seed:
|
|
@echo "Testing seed data..."
|
|
@./test_seed_data.sh
|
|
|
|
# 检查数据库状态
|
|
db-status:
|
|
@echo "Database Status:"
|
|
@if [ -f "./data/photography.db" ]; then \
|
|
echo "Database exists"; \
|
|
echo "User count: $$(sqlite3 ./data/photography.db 'SELECT COUNT(*) FROM user;')"; \
|
|
echo "Category count: $$(sqlite3 ./data/photography.db 'SELECT COUNT(*) FROM category;')"; \
|
|
echo "Photo count: $$(sqlite3 ./data/photography.db 'SELECT COUNT(*) FROM photo;')"; \
|
|
else \
|
|
echo "Database not found"; \
|
|
fi
|
|
|
|
# 重置数据库
|
|
db-reset:
|
|
@echo "Resetting database..."
|
|
@rm -f ./data/photography.db
|
|
@echo "Database reset complete. Run 'make quick' to recreate."
|
|
|
|
# 部署准备
|
|
deploy-prep: clean install lint test build
|
|
@echo "Deployment preparation complete."
|
|
|
|
# 显示帮助
|
|
help:
|
|
@echo "Available commands:"
|
|
@echo " build - Build the application"
|
|
@echo " run - Run the application"
|
|
@echo " dev - Build and run in development mode"
|
|
@echo " quick - Quick start without building"
|
|
@echo " install - Install dependencies"
|
|
@echo " gen - Generate API code"
|
|
@echo " gen-model - Generate model code"
|
|
@echo " clean - Clean build artifacts"
|
|
@echo " lint - Run code linter"
|
|
@echo " fmt - Format code"
|
|
@echo " test - Run tests"
|
|
@echo " setup - Create necessary directories"
|
|
@echo " status - Check API status"
|
|
@echo " seed - Run seed data script"
|
|
@echo " test-seed - Test seed data integrity"
|
|
@echo " db-status - Check database status"
|
|
@echo " db-reset - Reset database"
|
|
@echo " deploy-prep - Prepare for deployment"
|
|
@echo " help - Show this help message"
|
|
|
|
.PHONY: build run dev quick install gen gen-model clean lint fmt test setup status seed test-seed db-status db-reset deploy-prep help |