Skip to content

Commit e6319b2

Browse files
chuckcarpenterRobbieTheWagner
authored andcommitted
Fix unique constraint to allow multiple regular palettes
- Remove UNIQUE(user_id, is_color_history) constraint that prevented multiple regular palettes per user (FALSE values treated as identical) - Add partial unique index that only enforces uniqueness for color history rows (WHERE is_color_history = TRUE) - Move constraint to indexes section for proper organization
1 parent 0a1cf1e commit e6319b2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

supabase-schema.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ CREATE TABLE IF NOT EXISTS palettes (
2323

2424
-- Constraints
2525
CONSTRAINT palettes_user_not_null CHECK (user_id IS NOT NULL),
26-
CONSTRAINT palettes_single_color_history_per_user UNIQUE (user_id, is_color_history)
27-
DEFERRABLE INITIALLY DEFERRED,
2826
CONSTRAINT palettes_name_length CHECK (char_length(name) <= 255)
2927
);
3028

@@ -67,6 +65,10 @@ CREATE INDEX IF NOT EXISTS idx_colors_created_at ON colors(created_at);
6765
-- GIN indexes for JSONB columns
6866
CREATE INDEX IF NOT EXISTS idx_palettes_color_order ON palettes USING GIN(color_order);
6967

68+
-- Unique constraint: Only one color history palette per user
69+
CREATE UNIQUE INDEX IF NOT EXISTS idx_palettes_single_color_history_per_user
70+
ON palettes(user_id) WHERE is_color_history = TRUE;
71+
7072
-- ============================================
7173
-- Row Level Security (RLS) Policies
7274
-- ============================================

0 commit comments

Comments
 (0)