-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase-setup.sql
More file actions
25 lines (20 loc) · 1.04 KB
/
database-setup.sql
File metadata and controls
25 lines (20 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
-- Run this SQL in your Supabase SQL Editor to add the missing fields
-- Add archive and delete fields to notebooks table
ALTER TABLE public.notebooks
ADD COLUMN IF NOT EXISTS is_archived BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN IF NOT EXISTS is_deleted BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMP WITH TIME ZONE;
-- Create indexes for better performance
CREATE INDEX IF NOT EXISTS idx_notebooks_archived ON public.notebooks(user_id, is_archived);
CREATE INDEX IF NOT EXISTS idx_notebooks_deleted ON public.notebooks(user_id, is_deleted);
CREATE INDEX IF NOT EXISTS idx_notebooks_deleted_at ON public.notebooks(user_id, deleted_at);
-- Update existing notebooks to ensure they have the default values
UPDATE public.notebooks
SET is_archived = false, is_deleted = false
WHERE is_archived IS NULL OR is_deleted IS NULL;
-- Verify the changes
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'notebooks'
AND table_schema = 'public'
ORDER BY ordinal_position;