## Description
Create the database schema for storing knowledge data exclusions/inclusions in the AI context.
## Requirements
Create a new database table `store_data_exclusions` with the following structure:
```sql
- id: UUID (primary key)
- store_id: UUID (FK to stores)
- data_type: TEXT ('product', 'order', 'customer')
- data_id: TEXT (original platform ID from e-commerce system)
- is_enabled: BOOLEAN (default: true, false = disabled/excluded from AI context)
- metadata: JSONB (name, sku, email, etc. for display purposes)
- created_at: TIMESTAMPTZ
- updated_at: TIMESTAMPTZ
- UNIQUE constraint on (store_id, data_type, data_id)
```
## Implementation Details
1. Create a new migration file in `supabase/migrations/`
2. Add the table creation SQL
3. Add indexes for optimal query performance:
- Index on `store_id`
- Index on `(store_id, data_type)`
- Index on `is_enabled`
4. Add RLS (Row Level Security) policies to ensure users can only access their own store data
5. Apply the migration using Supabase MCP tools
## Acceptance Criteria
- [ ] Migration file created and applied successfully
- [ ] Table structure matches requirements
- [ ] Indexes are properly created
- [ ] RLS policies are in place
- [ ] Foreign key constraints are properly configured
## Parent Issue
Part of #42 - Implement Manage Store Data feature
I'll create the store_data_exclusions database schema with the following approach:
Create a new migration file in supabase/migrations/ following the naming convention
Define the table structure with all required columns and constraints
Add indexes for optimal query performance (store_id, data_type, is_enabled)
Implement RLS policies to ensure users can only access their own store data
Apply the migration using Supabase MCP tools
Let me begin implementation now.
@claude I'm starting work on this issue now!
I'll create the `store_data_exclusions` database schema with the following approach:
1. Create a new migration file in `supabase/migrations/` following the naming convention
2. Define the table structure with all required columns and constraints
3. Add indexes for optimal query performance (store_id, data_type, is_enabled)
4. Implement RLS policies to ensure users can only access their own store data
5. Apply the migration using Supabase MCP tools
Let me begin implementation now.
toggle_data_exclusion() - Upsert function to enable/disable data items
get_enabled_data_items() - Query enabled items for a store (optionally filtered by data_type)
get_excluded_data_items() - Query excluded items for a store (optionally filtered by data_type)
✅ Verification
The migration has been successfully applied to the Supabase database and verified:
Table created and visible in database
All indexes properly created
All constraints properly configured
RLS enabled and all policies in place
Foreign key relationship established
📝 Next Steps (from migration notes)
Create Edge Function API endpoints for managing exclusions
Update AI context building logic to respect exclusions
Add frontend UI for managing store data exclusions (part of parent issue #42)
🔗 Changes Committed
Committed and pushed to repository: feat: add store_data_exclusions database schema #43
All acceptance criteria have been met! ✨
## ✅ Issue Completed Successfully!
I've successfully created and applied the `store_data_exclusions` database schema. Here's what was implemented:
### 📋 Implementation Summary
**Migration File Created**: `supabase/migrations/20251031_154326_store_data_exclusions.sql`
**Table Structure**:
- ✅ All required columns (id, store_id, data_type, data_id, is_enabled, metadata, created_at, updated_at)
- ✅ UUID primary key with auto-generation
- ✅ Foreign key constraint on `store_id` → `stores(id)` with CASCADE DELETE
- ✅ CHECK constraint on `data_type` (product, order, customer)
- ✅ UNIQUE constraint on (store_id, data_type, data_id)
- ✅ Default values: `is_enabled = true`, timestamps auto-set
**Indexes Created** (4 indexes for optimal performance):
1. `idx_store_data_exclusions_store_id` - Single column index on store_id
2. `idx_store_data_exclusions_store_data_type` - Composite index on (store_id, data_type)
3. `idx_store_data_exclusions_is_enabled` - Single column index on is_enabled
4. `idx_store_data_exclusions_store_type_enabled` - Composite index on (store_id, data_type, is_enabled)
**RLS Policies** (4 policies ensuring secure access):
1. SELECT - Users can view their store data exclusions
2. INSERT - Users can insert their store data exclusions
3. UPDATE - Users can update their store data exclusions
4. DELETE - Users can delete their store data exclusions
All policies verify ownership through the `stores` table, ensuring users can only access data for their own stores.
**Helper Functions Created**:
1. `update_store_data_exclusions_updated_at()` - Auto-updates updated_at timestamp (with trigger)
2. `toggle_data_exclusion()` - Upsert function to enable/disable data items
3. `get_enabled_data_items()` - Query enabled items for a store (optionally filtered by data_type)
4. `get_excluded_data_items()` - Query excluded items for a store (optionally filtered by data_type)
### ✅ Verification
The migration has been successfully applied to the Supabase database and verified:
- Table created and visible in database
- All indexes properly created
- All constraints properly configured
- RLS enabled and all policies in place
- Foreign key relationship established
### 📝 Next Steps (from migration notes)
1. Create Edge Function API endpoints for managing exclusions
2. Update AI context building logic to respect exclusions
3. Add frontend UI for managing store data exclusions (part of parent issue #42)
### 🔗 Changes Committed
Committed and pushed to repository: `feat: add store_data_exclusions database schema #43`
All acceptance criteria have been met! ✨
Issue #43 has been completed and closed. The store_data_exclusions database schema has been successfully implemented, migrated, and verified. All acceptance criteria have been met. 🎉
Issue #43 has been completed and closed. The `store_data_exclusions` database schema has been successfully implemented, migrated, and verified. All acceptance criteria have been met. 🎉
Description
Create the database schema for storing knowledge data exclusions/inclusions in the AI context.
Requirements
Create a new database table
store_data_exclusionswith the following structure:Implementation Details
supabase/migrations/store_id(store_id, data_type)is_enabledAcceptance Criteria
Parent Issue
Part of #42 - Implement Manage Store Data feature
@claude I'm starting work on this issue now!
I'll create the
store_data_exclusionsdatabase schema with the following approach:supabase/migrations/following the naming conventionLet me begin implementation now.
✅ Issue Completed Successfully!
I've successfully created and applied the
store_data_exclusionsdatabase schema. Here's what was implemented:📋 Implementation Summary
Migration File Created:
supabase/migrations/20251031_154326_store_data_exclusions.sqlTable Structure:
store_id→stores(id)with CASCADE DELETEdata_type(product, order, customer)is_enabled = true, timestamps auto-setIndexes Created (4 indexes for optimal performance):
idx_store_data_exclusions_store_id- Single column index on store_ididx_store_data_exclusions_store_data_type- Composite index on (store_id, data_type)idx_store_data_exclusions_is_enabled- Single column index on is_enabledidx_store_data_exclusions_store_type_enabled- Composite index on (store_id, data_type, is_enabled)RLS Policies (4 policies ensuring secure access):
All policies verify ownership through the
storestable, ensuring users can only access data for their own stores.Helper Functions Created:
update_store_data_exclusions_updated_at()- Auto-updates updated_at timestamp (with trigger)toggle_data_exclusion()- Upsert function to enable/disable data itemsget_enabled_data_items()- Query enabled items for a store (optionally filtered by data_type)get_excluded_data_items()- Query excluded items for a store (optionally filtered by data_type)✅ Verification
The migration has been successfully applied to the Supabase database and verified:
📝 Next Steps (from migration notes)
🔗 Changes Committed
Committed and pushed to repository:
feat: add store_data_exclusions database schema #43All acceptance criteria have been met! ✨
Issue #43 has been completed and closed. The
store_data_exclusionsdatabase schema has been successfully implemented, migrated, and verified. All acceptance criteria have been met. 🎉