Files
evig/scripts/db/migrations/055_missing_indexes.sql
T
g-butandClaude Opus 4.6 4c6f6d0086 fix: database SSOT violations — migrations, TABLE_NAMES, transactions, indexes
- Renumber 8 duplicate migration files (002, 004, 005, 008, 020, 027, 040)
  that caused silent skipping during execution
- Clean TABLE_NAMES: add 12 missing schema tables, keep legacy raw-SQL
  tables with clear comments, remove truly phantom entries
- Wrap bulk import product+inventory in transaction (was 2 separate writes)
- Wrap marketplace conversation+message+metadata in transaction (race fix)
- Add missing indexes: listings(verifiedAt), listings(priceChf),
  users(isStaff, createdAt) + migration 055
- Sync Drizzle schema with new indexes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 21:02:36 +02:00

18 lines
713 B
SQL

-- Migration 055: Add missing indexes for common query patterns
--
-- These columns are frequently filtered/sorted but lack indexes:
-- - listings.verified_at (IS NOT NULL filter for verified listings)
-- - listings.price_chf (range filters)
-- - users(is_staff, created_at) (admin user listing with sort)
-- Listings: verified filter
CREATE INDEX IF NOT EXISTS idx_listings_verified_at ON listings (verified_at)
WHERE verified_at IS NOT NULL;
-- Listings: price range filter
CREATE INDEX IF NOT EXISTS idx_listings_price_chf ON listings (price_chf);
-- Users: staff listing sorted by join date
CREATE INDEX IF NOT EXISTS idx_users_staff_created ON users (is_staff, created_at DESC)
WHERE is_staff = true;