- Remove KRW pricing calculations from all pricing tables - Simplify pricing table to store only wholesale USD prices - Simplify anvil_pricing to store only retail USD prices - Remove KRW environment variables (KRW_EXCHANGE_RATE, KRW_MARGIN_RATE) - Remove KRW functions from constants.ts - Update GPU/G8/VPU pricing repositories to match - Add Anvil tables and repositories for branded product support Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Database Migrations
This directory contains SQL migration files for database schema changes.
Migration Files
002_add_composite_indexes.sql
Date: 2026-01-21 Purpose: Add composite indexes to optimize query performance
Indexes Added:
idx_instance_types_provider_family_specs- Optimizes instance filtering by provider, family, and specsidx_pricing_instance_region_price- Optimizes pricing queries with JOIN operations and sortingidx_regions_provider_code- Optimizes region lookups by provider and region code
Performance Impact:
- Reduces query execution time for filtered instance searches
- Improves JOIN performance between instance_types, pricing, and regions tables
- Enables efficient ORDER BY on hourly_price without additional sort operations
Running Migrations
Local Development
npm run db:migrate
Production
npm run db:migrate:remote
Migration Best Practices
- Idempotent Operations: All migrations use
IF NOT EXISTSto ensure safe re-execution - Backwards Compatible: New indexes don't break existing queries
- Performance Testing: Test migration impact on query performance before deploying
- Rollback Plan: Each migration includes rollback instructions in comments
Query Optimization Details
Main Query Pattern (query.ts)
SELECT ...
FROM instance_types it
JOIN providers p ON it.provider_id = p.id
JOIN pricing pr ON pr.instance_type_id = it.id
JOIN regions r ON pr.region_id = r.id
WHERE p.name = ?
AND r.region_code = ?
AND it.instance_family = ?
AND it.vcpu >= ?
AND it.memory_mb >= ?
ORDER BY pr.hourly_price
Optimized By:
idx_instance_types_provider_family_specs- Covers WHERE conditions on instance_typesidx_pricing_instance_region_price- Covers JOIN and ORDER BY on pricingidx_regions_provider_code- Covers JOIN conditions on regions
Expected Performance Improvement
- Before: Full table scans on instance_types and pricing tables
- After: Index seeks with reduced disk I/O
- Estimated Speedup: 3-10x for filtered queries with sorting
Verifying Index Usage
You can verify that indexes are being used with SQLite EXPLAIN QUERY PLAN:
# Check query execution plan
npm run db:query "EXPLAIN QUERY PLAN SELECT ... FROM instance_types it JOIN ..."
Look for "USING INDEX" in the output to confirm index usage.
Notes
- SQLite automatically chooses the most efficient index for each query
- Composite indexes follow the "leftmost prefix" rule
- Indexes add minimal storage overhead but significantly improve read performance
- Write operations (INSERT/UPDATE) are slightly slower with more indexes, but read performance gains outweigh this for read-heavy workloads