Files
CrazeAnalytix/supabase/migrations/001_create_experiments_table.sql
T
Christian Vidal WolfandQwen-Coder f93d92da0b Add complete Experiments tracking system
New Features:
- Experiments tab with full CRUD operations
- Create experiments by ASIN or product line groups
- Track pricing, advertising, content, and promotion experiments
- Performance analytics with baseline vs experiment comparison
- Visual experiment badges in Weekly Sales grid
- Experiment detail view with metrics and learnings

Technical Changes:
- Add Supabase experiments table migration
- New services/experiments.ts for CRUD + calculations
- New components: ExperimentsView, ExperimentDetail, ExperimentForm, ExperimentBadge
- Integrate experiment indicators in WeeklyGrid
- Add navigation tab (desktop + mobile)
- Type definitions in types.ts

Usage:
1. Run SQL migration in Supabase
2. Navigate to Experiments tab
3. Create experiments with ASINs, dates, hypothesis
4. View performance lift after completion
5. See active experiments marked in Weekly Sales

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-02-20 19:31:44 +01:00

60 lines
1.7 KiB
PL/PgSQL

-- Experiments Tracking Table
CREATE TABLE IF NOT EXISTS experiments (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
description TEXT,
type TEXT NOT NULL CHECK (type IN ('pricing', 'advertising', 'content', 'promotion')),
status TEXT NOT NULL DEFAULT 'planned' CHECK (status IN ('planned', 'active', 'completed', 'paused')),
-- ASIN targeting
asins TEXT[] NOT NULL DEFAULT '{}',
marketplace TEXT NOT NULL,
-- Timing
start_date DATE NOT NULL,
end_date DATE,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
-- Hypothesis & Goals
hypothesis TEXT,
primary_metric TEXT NOT NULL DEFAULT 'units',
target_lift_percent NUMERIC,
-- Results (auto-calculated)
baseline_units NUMERIC,
baseline_revenue NUMERIC,
experiment_units NUMERIC,
experiment_revenue NUMERIC,
actual_lift_percent NUMERIC,
statistical_significance NUMERIC,
-- Notes
learnings TEXT,
owner TEXT
);
-- Indexes for performance
CREATE INDEX idx_experiments_status ON experiments(status);
CREATE INDEX idx_experiments_marketplace ON experiments(marketplace);
CREATE INDEX idx_experiments_type ON experiments(type);
CREATE INDEX idx_experiments_dates ON experiments(start_date, end_date);
CREATE INDEX idx_experiments_asins ON experiments USING GIN(asins);
-- Updated_at trigger
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER update_experiments_updated_at
BEFORE UPDATE ON experiments
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
-- RLS Policies (optional - enable if you need row-level security)
-- ALTER TABLE experiments ENABLE ROW LEVEL SECURITY;