โ Configuraciรณn inicial
1
Ve a supabase.com โ nuevo proyecto โ SQL Editor โ ejecuta:
CREATE TABLE IF NOT EXISTS users (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS rooms (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
code TEXT UNIQUE NOT NULL, status TEXT DEFAULT 'waiting',
grid TEXT[] DEFAULT '{}', duration_seconds INTEGER DEFAULT 180,
grid_size INTEGER DEFAULT 4, min_word INTEGER DEFAULT 3,
created_at TIMESTAMPTZ DEFAULT NOW(),
started_at TIMESTAMPTZ, ends_at TIMESTAMPTZ
);
CREATE TABLE IF NOT EXISTS players (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
room_id UUID REFERENCES rooms(id) ON DELETE CASCADE,
user_id UUID REFERENCES users(id) ON DELETE SET NULL,
name TEXT NOT NULL, is_host BOOLEAN DEFAULT FALSE,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS found_words (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
room_id UUID REFERENCES rooms(id) ON DELETE CASCADE,
player_id UUID REFERENCES players(id) ON DELETE CASCADE,
user_id UUID REFERENCES users(id) ON DELETE SET NULL,
word TEXT NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW(),
UNIQUE(room_id, player_id, word)
);
CREATE TABLE IF NOT EXISTS game_results (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
room_id UUID REFERENCES rooms(id) ON DELETE SET NULL,
score INTEGER DEFAULT 0, words_found INTEGER DEFAULT 0,
longest_word TEXT DEFAULT '', grid_size INTEGER DEFAULT 4,
duration_seconds INTEGER DEFAULT 180, rank INTEGER DEFAULT 1,
total_players INTEGER DEFAULT 1,
played_at TIMESTAMPTZ DEFAULT NOW()
);
ALTER TABLE rooms ADD COLUMN IF NOT EXISTS duration_seconds INTEGER DEFAULT 180;
ALTER TABLE rooms ADD COLUMN IF NOT EXISTS grid_size INTEGER DEFAULT 4;
ALTER TABLE rooms ADD COLUMN IF NOT EXISTS min_word INTEGER DEFAULT 3;
ALTER TABLE players ADD COLUMN IF NOT EXISTS user_id UUID REFERENCES users(id) ON DELETE SET NULL;
ALTER TABLE found_words ADD COLUMN IF NOT EXISTS user_id UUID REFERENCES users(id) ON DELETE SET NULL;
ALTER TABLE users DISABLE ROW LEVEL SECURITY;
ALTER TABLE rooms DISABLE ROW LEVEL SECURITY;
ALTER TABLE players DISABLE ROW LEVEL SECURITY;
ALTER TABLE found_words DISABLE ROW LEVEL SECURITY;
ALTER TABLE game_results DISABLE ROW LEVEL SECURITY;
ALTER PUBLICATION supabase_realtime ADD TABLE rooms;
ALTER PUBLICATION supabase_realtime ADD TABLE players;
ALTER PUBLICATION supabase_realtime ADD TABLE found_words;
2
Ve a Project Settings โ API โ copia URL y clave anon: