-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration-templates.sql
More file actions
47 lines (39 loc) 路 1.68 KB
/
Copy pathmigration-templates.sql
File metadata and controls
47 lines (39 loc) 路 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
-- Migraci贸n: Sistema H铆brido de Rutinas Programadas + Plantillas
-- Ejecutar en Supabase SQL Editor
-- PASO 1: Hacer columna 'day' nullable
ALTER TABLE routines
ALTER COLUMN day DROP NOT NULL;
-- PASO 2: Agregar columna is_template (default false para rutinas existentes)
ALTER TABLE routines
ADD COLUMN IF NOT EXISTS is_template BOOLEAN DEFAULT FALSE;
-- PASO 3: Agregar columna description
ALTER TABLE routines
ADD COLUMN IF NOT EXISTS description TEXT;
-- PASO 4: Actualizar rutinas existentes - todas son rutinas programadas
UPDATE routines
SET is_template = FALSE
WHERE is_template IS NULL;
-- PASO 5: Crear 铆ndices para b煤squedas eficientes
CREATE INDEX IF NOT EXISTS idx_routines_is_template ON routines(user_id, is_template);
CREATE INDEX IF NOT EXISTS idx_routines_day ON routines(user_id, day) WHERE day IS NOT NULL;
-- PASO 6: Agregar comentarios para documentaci贸n
COMMENT ON COLUMN routines.day IS 'D铆a de la semana para rutinas programadas. NULL para plantillas reutilizables.';
COMMENT ON COLUMN routines.is_template IS 'true = plantilla reutilizable, false/undefined = rutina programada por d铆a';
COMMENT ON COLUMN routines.description IS 'Descripci贸n opcional de la plantilla (para ayudar a recordar su prop贸sito)';
-- VERIFICACI脫N: Ver estructura actualizada
SELECT
column_name,
data_type,
is_nullable,
column_default
FROM information_schema.columns
WHERE table_name = 'routines'
ORDER BY ordinal_position;
-- VERIFICACI脫N: Contar rutinas programadas vs plantillas
SELECT
is_template,
COUNT(*) as total,
COUNT(CASE WHEN day IS NOT NULL THEN 1 END) as con_dia,
COUNT(CASE WHEN day IS NULL THEN 1 END) as sin_dia
FROM routines
GROUP BY is_template;