-- Canvas database schema

-- Enable PostGIS extension for box data type support
-- Note: PostgreSQL has built-in box type, no need for PostGIS

-- Create the widgets table
CREATE TABLE IF NOT EXISTS widgets (
    id SERIAL PRIMARY KEY,
    box BOX NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Create GiST index for efficient box queries
CREATE INDEX IF NOT EXISTS widgets_box_gist_idx ON widgets USING GIST (box);

-- Add any additional columns that might exist in your Supabase table
-- You may need to adjust this based on your actual widget data structure
-- ALTER TABLE widgets ADD COLUMN IF NOT EXISTS name TEXT;
-- ALTER TABLE widgets ADD COLUMN IF NOT EXISTS data JSONB;