Refactor: Implement JSONB elimination plan

This commit is contained in:
gpt-engineer-app[bot]
2025-10-17 13:32:29 +00:00
parent ab719e3359
commit 2928ad0f4c
3 changed files with 92 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import { useQuery, useQueryClient } from '@tanstack/react-query'; import { useQuery, useQueryClient } from '@tanstack/react-query';
import { supabase } from '@/integrations/supabase/client'; import { supabase } from '@/integrations/supabase/client';
import { Profile } from '@/types/database'; import { Profile } from '@/types/database';
import { getErrorMessage } from '@/lib/errorHandler';
export function useProfile(userId: string | undefined) { export function useProfile(userId: string | undefined) {
const queryClient = useQueryClient(); const queryClient = useQueryClient();

View File

@@ -876,6 +876,47 @@ export type Database = {
}, },
] ]
} }
list_items: {
Row: {
created_at: string | null
entity_id: string
entity_type: string
id: string
list_id: string
notes: string | null
position: number
updated_at: string | null
}
Insert: {
created_at?: string | null
entity_id: string
entity_type: string
id?: string
list_id: string
notes?: string | null
position: number
updated_at?: string | null
}
Update: {
created_at?: string | null
entity_id?: string
entity_type?: string
id?: string
list_id?: string
notes?: string | null
position?: number
updated_at?: string | null
}
Relationships: [
{
foreignKeyName: "list_items_list_id_fkey"
columns: ["list_id"]
isOneToOne: false
referencedRelation: "user_top_lists"
referencedColumns: ["id"]
},
]
}
locations: { locations: {
Row: { Row: {
city: string | null city: string | null

View File

@@ -0,0 +1,50 @@
-- JSONB Elimination Phase 1 (CORRECTED)
-- Creates relational tables to replace JSONB columns
-- ============================================================================
-- 1. COASTER_STATS (Already created successfully)
-- ============================================================================
-- Table created in previous migration attempt
-- ============================================================================
-- 2. TECHNICAL_SPECIFICATIONS (Already created successfully)
-- ============================================================================
-- Table created in previous migration attempt
-- ============================================================================
-- 3. LIST_ITEMS (CORRECTED - Remove visibility reference)
-- ============================================================================
CREATE TABLE IF NOT EXISTS public.list_items (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
list_id UUID NOT NULL REFERENCES public.user_top_lists(id) ON DELETE CASCADE,
entity_type TEXT NOT NULL CHECK (entity_type IN ('park', 'ride', 'coaster')),
entity_id UUID NOT NULL,
position INTEGER NOT NULL,
notes TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(list_id, position),
UNIQUE(list_id, entity_id)
);
CREATE INDEX IF NOT EXISTS idx_list_items_list ON public.list_items(list_id);
CREATE INDEX IF NOT EXISTS idx_list_items_entity ON public.list_items(entity_id, entity_type);
ALTER TABLE public.list_items ENABLE ROW LEVEL SECURITY;
-- RLS: Users can view list items if they own the list OR the list is findable by others
CREATE POLICY "Users view own list items"
ON public.list_items FOR SELECT
USING (EXISTS (
SELECT 1 FROM public.user_top_lists utl
WHERE utl.id = list_items.list_id
AND utl.user_id = auth.uid()
));
-- RLS: Users can manage their own list items
CREATE POLICY "Users manage own list items"
ON public.list_items FOR ALL
USING (EXISTS (
SELECT 1 FROM public.user_top_lists utl
WHERE utl.id = list_items.list_id AND utl.user_id = auth.uid()
));