Skip to content

Commit fed8032

Browse files
committed
add command, instructions
1 parent 1641f3a commit fed8032

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

taco/Makefile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ help: ## Show this help
9595
# Migration name variable (use with: make atlas-diff-all name=add_new_feature)
9696
NAME ?= $(shell date +%Y%m%d%H%M%S)
9797

98-
.PHONY: atlas-install atlas-diff-all atlas-apply-all atlas-lint-all atlas-hash-all
98+
.PHONY: atlas-install atlas-diff-all atlas-plan atlas-apply-all atlas-lint-all atlas-hash-all
9999

100100
# Install Atlas CLI and GORM provider
101101
atlas-install: ## Install Atlas CLI and GORM provider
@@ -104,6 +104,20 @@ atlas-install: ## Install Atlas CLI and GORM provider
104104
@go install ariga.io/atlas-provider-gorm@latest
105105
@echo "✅ Atlas tools installed successfully"
106106

107+
# Preview migration changes without generating files
108+
atlas-plan: ## Preview what migrations would be generated (use: make atlas-plan name=my_change)
109+
@echo "Previewing migration changes for all databases..."
110+
@if [ -z "$(filter-out $(NAME),$(shell date +%Y%m%d%H%M%S))" ]; then \
111+
echo "⚠️ Using auto-generated name: $(NAME)"; \
112+
echo "💡 Tip: Use 'make atlas-plan name=descriptive_name' for better naming"; \
113+
fi
114+
@echo "\n🔐 Generating checksums for existing migrations..."
115+
@$(MAKE) atlas-hash-all
116+
@echo "\n📊 PostgreSQL (dry-run)..." && atlas migrate diff $(NAME) --env postgres --dry-run || true
117+
@echo "\n📊 MySQL (dry-run)..." && atlas migrate diff $(NAME) --env mysql --dry-run || true
118+
@echo "\n📊 SQLite (dry-run)..." && atlas migrate diff $(NAME) --env sqlite --dry-run || true
119+
@echo "\n✅ Preview complete (no files generated)"
120+
107121
# Generate migrations for all database dialects (Postgres, MySQL, SQLite)
108122
atlas-diff-all: ## Generate migrations for all databases (use: make atlas-diff-all name=my_change)
109123
@echo "Generating migrations for all databases..."

taco/migrations/MIGRATIONS.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Database Migrations
2+
3+
Atlas-based schema migrations for PostgreSQL, MySQL, and SQLite.
4+
5+
## Quick Reference
6+
7+
```bash
8+
# Preview changes (dry-run)
9+
make atlas-plan name=my_change
10+
11+
# Generate migrations
12+
make atlas-diff-all name=my_change
13+
14+
# Validate migrations
15+
make atlas-lint-all
16+
17+
# Apply migrations locally
18+
atlas migrate apply --env postgres
19+
atlas migrate apply --env mysql
20+
atlas migrate apply --env sqlite
21+
```
22+
23+
## Local Development
24+
25+
### First-time setup
26+
```bash
27+
# Install Atlas CLI
28+
make atlas-install
29+
30+
# Ensure Docker is running (required for Postgres/MySQL dev databases)
31+
docker info
32+
```
33+
34+
### Modifying schema
35+
36+
1. Edit GORM models in `internal/query/types/models.go`
37+
2. Preview changes: `make atlas-plan name=add_user_field`
38+
3. Generate migrations: `make atlas-diff-all name=add_user_field`
39+
4. Review generated SQL in `migrations/{postgres,mysql,sqlite}/`
40+
5. Apply locally: `atlas migrate apply --env [postgres|mysql|sqlite]`
41+
6. Commit: `git add migrations/ && git commit -m "Add user field migration"`
42+
43+
## Docker/Production
44+
45+
Migrations are **automatically applied** via `scripts/entrypoint.sh` before the app starts.
46+
47+

0 commit comments

Comments
 (0)