Database Setup
Set up your Supabase database tables to enable the full functionality of Binman.
Manual Setup Required
Automatic setup failed. Please set up manually:
- Go to your Supabase project dashboard
- Navigate to the SQL Editor in the left sidebar
- Copy and paste each SQL command block below
- Click "Run" to execute each SQL block
- Refresh this page to verify the setup
1. Waste Items Table
This table stores classified waste items that users submit to the marketplace.
-- Create waste_items table
CREATE TABLE IF NOT EXISTS waste_items (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
description TEXT,
category VARCHAR(50) NOT NULL,
confidence VARCHAR(20),
explanation TEXT,
price DECIMAL(10,2) NOT NULL,
location VARCHAR(255),
contact_info VARCHAR(255),
image_url TEXT,
is_approved BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create indexes for better performance
CREATE INDEX IF NOT EXISTS idx_waste_items_category ON waste_items(category);
CREATE INDEX IF NOT EXISTS idx_waste_items_is_approved ON waste_items(is_approved);
CREATE INDEX IF NOT EXISTS idx_waste_items_created_at ON waste_items(created_at);2. Pickup Schedules Table
This table stores scheduled waste pickups and their status.
-- Create pickup_schedules table
CREATE TABLE IF NOT EXISTS pickup_schedules (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
waste_item_id UUID REFERENCES waste_items(id),
pickup_date TIMESTAMP WITH TIME ZONE NOT NULL,
address TEXT NOT NULL,
contact_name VARCHAR(255) NOT NULL,
contact_phone VARCHAR(50),
contact_email VARCHAR(255),
notes TEXT,
status VARCHAR(50) DEFAULT 'pending',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create indexes for better performance
CREATE INDEX IF NOT EXISTS idx_pickup_schedules_waste_item_id ON pickup_schedules(waste_item_id);
CREATE INDEX IF NOT EXISTS idx_pickup_schedules_status ON pickup_schedules(status);
CREATE INDEX IF NOT EXISTS idx_pickup_schedules_pickup_date ON pickup_schedules(pickup_date);3. Donations Table
This table stores donation items and their partner organizations.
-- Create donations table
CREATE TABLE IF NOT EXISTS donations (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
description TEXT,
category VARCHAR(50) NOT NULL,
confidence VARCHAR(20),
explanation TEXT,
quantity VARCHAR(100),
location VARCHAR(255),
contact_info VARCHAR(255),
image_url TEXT,
pickup_details TEXT,
partner_organization VARCHAR(255),
status VARCHAR(50) DEFAULT 'pending',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create indexes for better performance
CREATE INDEX IF NOT EXISTS idx_donations_category ON donations(category);
CREATE INDEX IF NOT EXISTS idx_donations_status ON donations(status);
CREATE INDEX IF NOT EXISTS idx_donations_created_at ON donations(created_at);4. Stored Procedure
This stored procedure allows the application to create tables automatically if they don't exist.
-- Create a stored procedure to create the waste_items table if it doesn't exist
CREATE OR REPLACE FUNCTION create_waste_items_table()
RETURNS void AS $$
BEGIN
-- Create waste_items table if it doesn't exist
CREATE TABLE IF NOT EXISTS waste_items (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
description TEXT,
category VARCHAR(50) NOT NULL,
confidence VARCHAR(20),
explanation TEXT,
price DECIMAL(10,2) NOT NULL,
location VARCHAR(255),
contact_info VARCHAR(255),
image_url TEXT,
is_approved BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
-- Create indexes for better performance
CREATE INDEX IF NOT EXISTS idx_waste_items_category ON waste_items(category);
CREATE INDEX IF NOT EXISTS idx_waste_items_is_approved ON waste_items(is_approved);
CREATE INDEX IF NOT EXISTS idx_waste_items_created_at ON waste_items(created_at);
END;
$$ LANGUAGE plpgsql;