A static analysis tool that predicts the production impact of database migrations before execution. TAPA analyzes migration files and provides risk assessments, lock predictions, time estimates, and safer alternatives.
Supported Databases: PostgreSQL 9.6+, MySQL 5.7+
- Lock Detection: Predicts lock types (ACCESS EXCLUSIVE, SHARE, etc.) and durations
- Risk Scoring: Calculates risk scores (0-100) with categorization (LOW, MEDIUM, HIGH, CRITICAL)
- Time Estimation: Estimates execution time including table rewrites and index builds
- Dependency Analysis: Identifies breaking changes (indexes, views, foreign keys)
- Safe Alternatives: Generates multi-step alternatives for high-risk operations
- Migration Batching: Groups operations by risk for safer deployment
- PostgreSQL: Full DDL parsing with pg_query, supports CONCURRENTLY operations
- MySQL: Native vitess parser with ALGORITHM/LOCK clause detection
- pt-online-schema-change: Automatic command generation for high-risk MySQL operations
- Schema Introspection: Queries live database metadata for accurate analysis
- GitHub Actions: Automatic PR analysis with risk-based blocking and comments
- GitLab CI: Pipeline integration with JSON and Markdown reports
- JSON Output: Machine-readable format for custom automation workflows
go install github.com/iamsr/tapa/cmd/tapa@latestPostgreSQL:
# Single file
tapa analyze migrations/001_add_column.sql --db postgres://localhost/mydb
# Directory
tapa analyze migrations/ --db postgres://user:pass@host/dbname
# Comprehensive analysis with all features
tapa analyze migrations/ --db $DATABASE_URL --comprehensiveMySQL:
# Basic analysis
tapa analyze migrations/001_add_index.sql --db-type mysql --db mysql://root@localhost/mydb
# With pt-osc recommendations
tapa analyze migrations/ --db-type mysql --db mysql://localhost/mydb
# Dry run (no database connection)
tapa analyze migrations/ --db-type mysql --dry-runHuman-readable (default):
TAPA provides beautiful, color-coded output with visual summary cards:
tapa analyze migrations/001_migration.sql --db $DATABASE_URLExample output:
✓ Dry-run mode (no database connection)
Parsing migration file(s)...
✓ Found 6 statements
Analyzing operations...
✓ Analysis complete
╭─ ANALYSIS RESULTS ────────────────────────────────────────────────────────╮
│ Risk Score │
│ ███████████████████░░░░░░░░░ 70/100 │
│ Status: HIGH RISK 🟠 │
│ │
│ Est. Time: 4.3m │
│ │
│ Risk Breakdown: │
│ ├── Low ▪ 1 │
│ ├── Medium ▪▪ 2 │
│ ├── High ▪▪▪ 3 │
│ └── Critical 0 │
│ │
│ Compatibility: │
│ ✓ All operations backward compatible (6/6) │
│ ✓ No breaking changes │
│ ⚠ Requires maintenance window │
╰──────────────────────────────────────────────────────────────────────────╯
Features:
- Visual progress bars with risk-based coloring
- Tree-style risk breakdown with operation counts
- Emoji status indicators for quick assessment
- Compatibility checks at a glance
JSON (for CI/CD):
tapa analyze migrations/ --db $DATABASE_URL --format json > report.jsonGenerate safer deployment strategies by grouping operations by risk level:
# Analyze and generate batching strategy
tapa batch migrations/ --db-type postgresql
# Output in JSON format
tapa batch migrations/ --format json > batches.jsonFeatures:
- Risk-based operation grouping
- Automatic prerequisite detection
- Parallel execution recommendations
- Per-batch time estimates
See Batching Guide for details.
TAPA displays step-by-step progress on stderr during analysis:
tapa analyze migrations/ --db $DATABASE_URLProgress output (on stderr):
Connecting to database...
✓ Connected to Postgresql
Parsing migration file(s)...
✓ Found 6 statements
Analyzing operations...
✓ Analysis complete
This keeps stdout clean for JSON output while showing progress:
tapa analyze migrations/ --format json > report.json # Progress on stderr, JSON on stdoutDisable emojis in progress output:
TAPA_NO_EMOJI=1 tapa analyze migrations/TAPA automatically displays risk levels and lock types in color for better visibility:
- Risk Levels: Green (LOW), Yellow (MEDIUM), Orange (HIGH), Red (CRITICAL)
- Lock Types: Color-coded based on severity
Disable colors or emojis if needed:
NO_COLOR=1 tapa analyze migrations/ # Disable colors
TAPA_NO_EMOJI=1 tapa analyze migrations/ # Replace emojis with textGitHub Actions:
- uses: ./.github/actions/tapa-analyzer
with:
migration-path: "migrations/"
db-type: "postgresql"
fail-on-risk: "high"
github-token: ${{ secrets.GITHUB_TOKEN }}GitLab CI:
migration-analysis:
script:
- ./.gitlab/tapa-analyzer.sh migrations/
variables:
DMA_DB_TYPE: postgresql
DMA_FAIL_ON_RISK: high- Architecture Guide - Comprehensive system design, algorithms, and extension points
- Migration Batching Guide - Safer incremental deployment strategies
- MySQL Support Guide - MySQL-specific features and pt-osc integration
- GitHub Actions Setup - Automated PR analysis
- GitLab CI Setup - Pipeline integration
Full documentation available in docs/.
TAPA uses a multi-stage pipeline architecture for comprehensive migration analysis:
cmd/tapa/ # CLI entry point
internal/
parser/ # SQL parsing (PostgreSQL pg_query, MySQL Vitess)
analyzer/ # Lock detection, risk scoring, time estimation
introspector/ # Live database metadata queries
db/ # Database connection management
batcher/ # Risk-based operation grouping
ui/ # Progress bars, summary cards, visual output
output/ # Multi-format output (table, JSON, YAML)
pkg/models/ # Core data structures
For detailed architecture documentation including data flows, algorithms, and extension points, see the Architecture Guide.
Requirements:
- Go 1.21+
- PostgreSQL 9.6+ or MySQL 5.7+ (for integration tests)
Build:
go build ./cmd/tapaTest:
TAPA has comprehensive test coverage across multiple levels:
Located in tests/unit/ and alongside code in internal packages:
# Run all unit tests
go test ./... -short
# Run specific package
go test ./internal/analyzer -vIntegration tests are co-located with code (see tests/integration/README.md):
# Requires Docker (PostgreSQL + MySQL)
cd tests/e2e && docker-compose up -d
go test ./internal/analyzer/postgres -v -run Integration
go test ./internal/analyzer/mysql -v -run Integration
cd tests/e2e && docker-compose down -vLocated in tests/e2e/:
cd tests/e2e
./run_tests.shThis runs the full E2E suite including:
- PostgreSQL integration tests
- MySQL integration tests
- Batch command tests
CI integration test scripts are in tests/ci/:
# GitHub Actions
bash tests/ci/test-github-action.sh
# GitLab CI
bash tests/ci/test-gitlab-ci.shTest with coverage:
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.outContributions are welcome! Please see CONTRIBUTING.md for guidelines.
Apache License 2.0 - see LICENSE