-- Style-Palette Compatibility table
-- Stores the compatibility scores between styles and palettes
CREATE TABLE IF NOT EXISTS style_palette_compatibility (
style_id TEXT NOT NULL REFERENCES design_styles(id) ON DELETE CASCADE,
palette_id TEXT NOT NULL REFERENCES design_palettes(id) ON DELETE CASCADE,
score INTEGER NOT NULL CHECK (score >= 1 AND score <= 5),
created_at TIMESTAMP WITH TIME ZONE DEFAULT TIMEZONE('utc'::TEXT, NOW()) NOT NULL,
PRIMARY KEY (style_id, palette_id)
);
-- Indexes for better query performance
CREATE INDEX IF NOT EXISTS idx_compatibility_style_score ON style_palette_compatibility(style_id, score DESC);
CREATE INDEX IF NOT EXISTS idx_compatibility_palette_score ON style_palette_compatibility(palette_id, score DESC);
CREATE INDEX IF NOT EXISTS idx_compatibility_score ON style_palette_compatibility(score DESC);
-- RLS (Row Level Security) - allow read access for everyone
ALTER TABLE style_palette_compatibility ENABLE ROW LEVEL SECURITY;
CREATE POLICY IF NOT EXISTS "Allow read access to style_palette_compatibility" ON style_palette_compatibility
FOR SELECT USING (true);