Adds cmd/wallet-migrate (make wallet-migrate, args=-dry-run to only report), which moves customer_points and customer_tokens into the wallet (docs/prd-point-coin.md §10, PC-105). Each customer gets a MIGRATION ledger row and a non-expiring lot per currency, written through WalletProcessor in one transaction per customer. EnakCoin is the sum of every token type (Q6), with the legacy rows listed in the row's metadata. It credits the difference between the legacy balance and what earlier runs migrated, so running it again never doubles a balance and picks up only what the old code added since. A legacy balance that shrank after being migrated is reported and left alone, since only an admin adjustment may take balance away, and the command then exits non-zero. It ends with a legacy / migrated / wallet total per currency. Migration 000092 renames TOKENS to COINS in campaigns.type and campaign_rules.reward_type. The campaign API now validates COINS; it still accepts TOKENS, including as a list filter, and stores it as COINS so older dashboards keep working while they are updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
149 lines
3.5 KiB
Makefile
149 lines
3.5 KiB
Makefile
#PROJECT_NAME = "enaklo-pos-backend"
|
|
|
|
# ─── Environment (default: staging) ──────────────────────────────────────────
|
|
ENV ?= staging
|
|
|
|
ifeq ($(ENV),production)
|
|
DB_USERNAME :=apskel
|
|
DB_PASSWORD :=7a8UJbM2GgBWaseh0lnP3O5i1i5nINXk
|
|
DB_HOST :=62.72.45.250
|
|
DB_PORT :=5433
|
|
DB_NAME :=apskel_pos
|
|
else
|
|
DB_USERNAME :=apskel
|
|
DB_PASSWORD :=7a8UJbM2GgBWaseh0lnP3O5i1i5nINXk
|
|
DB_HOST :=62.72.45.250
|
|
DB_PORT :=5433
|
|
DB_NAME :=apskel_pos_staging
|
|
endif
|
|
|
|
DB_URL = postgres://$(DB_USERNAME):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
DETECTED_OS := Windows
|
|
else
|
|
DETECTED_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
|
|
endif
|
|
|
|
.SILENT: help
|
|
help:
|
|
@echo
|
|
@echo "Usage: make [command] [ENV=staging|production]"
|
|
@echo
|
|
@echo "Commands:"
|
|
@echo " run Run server (default: staging)"
|
|
@echo " run ENV=production Run server with production config"
|
|
@echo
|
|
@echo " rename-project name={name} Rename project"
|
|
@echo
|
|
@echo " build-http Build http server"
|
|
@echo
|
|
@echo " migration-create name={name} Create migration"
|
|
@echo " migration-up Up migrations"
|
|
@echo " migration-up ENV=production Up migrations (production DB)"
|
|
@echo " migration-down Down last migration"
|
|
@echo " wallet-migrate args=-dry-run Move legacy points/tokens into the wallet"
|
|
@echo
|
|
@echo " docker-up Up docker services"
|
|
@echo " docker-down Down docker services"
|
|
@echo
|
|
@echo " fmt Format source code"
|
|
@echo " test Run unit tests"
|
|
@echo
|
|
|
|
# Build
|
|
|
|
.SILENT: rename-project
|
|
rename-project:
|
|
ifeq ($(name),)
|
|
@echo 'new project name not set'
|
|
else
|
|
ifeq ($(DETECTED_OS),Darwin)
|
|
@grep -RiIl '$(PROJECT_NAME)' | xargs sed -i '' 's/$(PROJECT_NAME)/$(name)/g'
|
|
endif
|
|
|
|
ifeq ($(DETECTED_OS),Linux)
|
|
@grep -RiIl '$(PROJECT_NAME)' | xargs sed -i 's/$(PROJECT_NAME)/$(name)/g'
|
|
endif
|
|
|
|
ifeq ($(DETECTED_OS),Windows)
|
|
@grep 'target is not implemented on Windows platform'
|
|
endif
|
|
endif
|
|
|
|
.SILENT: build-http
|
|
build-http:
|
|
@go build -o ./bin/http-server ./cmd/http/main.go
|
|
@echo executable file \"http-server\" saved in ./bin/http-server
|
|
|
|
# Test
|
|
|
|
.SILENT: test
|
|
test:
|
|
@go test ./... -v
|
|
|
|
# Create migration
|
|
|
|
.SILENT: migration-create
|
|
migration-create:
|
|
@migrate create -ext sql -dir ./migrations -seq $(name)
|
|
|
|
# Up migration
|
|
|
|
.SILENT: migration-up
|
|
migration-up:
|
|
@migrate -database $(DB_URL) -path ./migrations up
|
|
|
|
# Down migration
|
|
|
|
.SILENT: migration-down
|
|
migration-down:
|
|
@migrate -database $(DB_URL) -path ./migrations down 1
|
|
|
|
# Force migration to specific version
|
|
|
|
.SILENT: migration-force
|
|
migration-force:
|
|
@migrate -database $(DB_URL) -path ./migrations force $(version)
|
|
|
|
# Move customer_points / customer_tokens into the wallet. Safe to run again.
|
|
# Pass args=-dry-run to only report.
|
|
|
|
.SILENT: wallet-migrate
|
|
wallet-migrate:
|
|
ENV_MODE=$(ENV) go run ./cmd/wallet-migrate $(args)
|
|
|
|
.SILENT: seeder-create
|
|
seeder-create:
|
|
@migrate create -ext sql -dir ./seeders -seq $(name)
|
|
|
|
.SILENT: seeder-up
|
|
seeder-up:
|
|
@migrate -database $(DB_URL) -path ./seeders up
|
|
|
|
# Docker
|
|
|
|
.SILENT: docker-up
|
|
docker-up:
|
|
@docker-compose up -d
|
|
|
|
.SILENT: docker-down
|
|
docker-down:
|
|
@docker-compose down
|
|
|
|
# Format
|
|
|
|
.SILENT: fmt
|
|
fmt:
|
|
@go fmt ./...
|
|
|
|
start:
|
|
ENV_MODE=$(ENV) go run cmd/server/main.go
|
|
|
|
.SILENT: run
|
|
run:
|
|
ENV_MODE=$(ENV) go run cmd/server/main.go
|
|
|
|
# Default
|
|
|
|
.DEFAULT_GOAL := help
|