diff --git a/veza-backend-api/migrations/095_products_enrichment.sql b/veza-backend-api/migrations/095_products_enrichment.sql new file mode 100644 index 000000000..6db566281 --- /dev/null +++ b/veza-backend-api/migrations/095_products_enrichment.sql @@ -0,0 +1,14 @@ +-- v0.401 M1: Add BPM, musical_key, category to products +-- Prerequisite: products table exists (GORM or prior migration) + +DO $$ +BEGIN + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'products') THEN + ALTER TABLE products ADD COLUMN IF NOT EXISTS bpm INTEGER; + ALTER TABLE products ADD COLUMN IF NOT EXISTS musical_key VARCHAR(10); + ALTER TABLE products ADD COLUMN IF NOT EXISTS category VARCHAR(50); + CREATE INDEX IF NOT EXISTS idx_products_category ON products(category) WHERE category IS NOT NULL; + CREATE INDEX IF NOT EXISTS idx_products_bpm ON products(bpm) WHERE bpm IS NOT NULL; + CREATE INDEX IF NOT EXISTS idx_products_musical_key ON products(musical_key) WHERE musical_key IS NOT NULL AND musical_key != ''; + END IF; +END $$; diff --git a/veza-backend-api/migrations/096_product_previews.sql b/veza-backend-api/migrations/096_product_previews.sql new file mode 100644 index 000000000..6522da05a --- /dev/null +++ b/veza-backend-api/migrations/096_product_previews.sql @@ -0,0 +1,18 @@ +-- v0.401 M1: Product previews (audio demo files) +-- Prerequisite: products table exists + +DO $$ +BEGIN + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'products') THEN + IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'product_previews') THEN + CREATE TABLE product_previews ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + product_id UUID NOT NULL REFERENCES products(id) ON DELETE CASCADE, + file_path VARCHAR(512) NOT NULL, + duration_sec INTEGER, + created_at TIMESTAMPTZ DEFAULT NOW() + ); + CREATE INDEX idx_product_previews_product_id ON product_previews(product_id); + END IF; + END IF; +END $$; diff --git a/veza-backend-api/migrations/097_product_images.sql b/veza-backend-api/migrations/097_product_images.sql new file mode 100644 index 000000000..93b019036 --- /dev/null +++ b/veza-backend-api/migrations/097_product_images.sql @@ -0,0 +1,18 @@ +-- v0.401 M1: Product images (multiple images per product) +-- Prerequisite: products table exists + +DO $$ +BEGIN + IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'products') THEN + IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'product_images') THEN + CREATE TABLE product_images ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + product_id UUID NOT NULL REFERENCES products(id) ON DELETE CASCADE, + url VARCHAR(512) NOT NULL, + sort_order INTEGER DEFAULT 0, + created_at TIMESTAMPTZ DEFAULT NOW() + ); + CREATE INDEX idx_product_images_product_id ON product_images(product_id); + END IF; + END IF; +END $$;