-- Description: Création de la table tools pour le catalogue d'outils
-- Created: 2024-01-15
-- Author: Kit'Asso Team
-- ============================================
-- 1. CREATE TABLE
-- ============================================
CREATE TABLE IF NOT EXISTS tools (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT UNIQUE NOT NULL,
description TEXT NOT NULL,
pricing_tier TEXT CHECK (pricing_tier IN ('Gratuit', 'Freemium', 'Payant', 'Entreprise')),
category_id UUID REFERENCES categories(id) ON DELETE SET NULL,
logo_url TEXT,
website_url TEXT,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- ============================================
-- 2. CREATE INDEXES
-- ============================================
CREATE INDEX IF NOT EXISTS idx_tools_category_id ON tools(category_id);
CREATE INDEX IF NOT EXISTS idx_tools_pricing_tier ON tools(pricing_tier);
CREATE INDEX IF NOT EXISTS idx_tools_name ON tools(name);
-- ============================================
-- 3. ENABLE ROW LEVEL SECURITY
-- ============================================
ALTER TABLE tools ENABLE ROW LEVEL SECURITY;
-- ============================================
-- 4. CREATE RLS POLICIES
-- ============================================
-- Public read
CREATE POLICY "Allow public read on tools"
ON tools
FOR SELECT
TO public
USING (true);
-- Authenticated insert
CREATE POLICY "Allow authenticated insert on tools"
ON tools
FOR INSERT
TO authenticated
WITH CHECK (true);
-- Authenticated update
CREATE POLICY "Allow authenticated update on tools"
ON tools
FOR UPDATE
TO authenticated
USING (true)
WITH CHECK (true);
-- Authenticated delete
CREATE POLICY "Allow authenticated delete on tools"
ON tools
FOR DELETE
TO authenticated
USING (true);
-- ============================================
-- 5. COMMENTS (Documentation)
-- ============================================
COMMENT ON TABLE tools IS 'Catalogue des outils numériques pour associations';
COMMENT ON COLUMN tools.name IS 'Nom unique de l''outil';
COMMENT ON COLUMN tools.pricing_tier IS 'Modèle tarifaire (Gratuit, Freemium, Payant, Entreprise)';