mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-16 21:37:51 +00:00
This commit is contained in:
parent
663c2fb8ff
commit
a0cfccc14d
32
create_phonics_policies.sql
Normal file
32
create_phonics_policies.sql
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
-- Políticas para permitir leitura por usuários autenticados
|
||||||
|
CREATE POLICY "Permitir leitura de exercícios fonéticos para usuários autenticados" ON phonics_exercises
|
||||||
|
FOR SELECT
|
||||||
|
TO authenticated
|
||||||
|
USING (true);
|
||||||
|
|
||||||
|
CREATE POLICY "Permitir leitura de categorias fonéticas para usuários autenticados" ON phonics_categories
|
||||||
|
FOR SELECT
|
||||||
|
TO authenticated
|
||||||
|
USING (true);
|
||||||
|
|
||||||
|
CREATE POLICY "Permitir leitura de tipos de exercícios fonéticos para usuários autenticados" ON phonics_exercise_types
|
||||||
|
FOR SELECT
|
||||||
|
TO authenticated
|
||||||
|
USING (true);
|
||||||
|
|
||||||
|
CREATE POLICY "Permitir leitura de palavras fonéticas para usuários autenticados" ON phonics_words
|
||||||
|
FOR SELECT
|
||||||
|
TO authenticated
|
||||||
|
USING (true);
|
||||||
|
|
||||||
|
CREATE POLICY "Permitir leitura de relações exercício-palavra para usuários autenticados" ON phonics_exercise_words
|
||||||
|
FOR SELECT
|
||||||
|
TO authenticated
|
||||||
|
USING (true);
|
||||||
|
|
||||||
|
-- Habilitar RLS nas tabelas
|
||||||
|
ALTER TABLE phonics_exercises ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE phonics_categories ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE phonics_exercise_types ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE phonics_words ENABLE ROW LEVEL SECURITY;
|
||||||
|
ALTER TABLE phonics_exercise_words ENABLE ROW LEVEL SECURITY;
|
||||||
@ -10,12 +10,21 @@ export function usePhonicsExercises(categoryId?: string) {
|
|||||||
.from('phonics_exercises')
|
.from('phonics_exercises')
|
||||||
.select(`
|
.select(`
|
||||||
*,
|
*,
|
||||||
category:phonics_categories(id, name, description, level),
|
category:phonics_categories(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
level
|
||||||
|
),
|
||||||
|
type:phonics_exercise_types(
|
||||||
|
id,
|
||||||
|
name
|
||||||
|
),
|
||||||
words:phonics_exercise_words(
|
words:phonics_exercise_words(
|
||||||
id,
|
id,
|
||||||
is_correct_answer,
|
is_correct_answer,
|
||||||
order_index,
|
order_index,
|
||||||
word:phonics_words(*)
|
word:phonics_words(word)
|
||||||
)
|
)
|
||||||
`)
|
`)
|
||||||
.eq('is_active', true)
|
.eq('is_active', true)
|
||||||
|
|||||||
146
supabase/migrations/20240321000001_insert_phonics_data.sql
Normal file
146
supabase/migrations/20240321000001_insert_phonics_data.sql
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
-- Inserir categorias de exercícios
|
||||||
|
WITH inserted_categories AS (
|
||||||
|
INSERT INTO phonics_categories (name, description, level, order_index) VALUES
|
||||||
|
('Rimas', 'Exercícios para praticar rimas', 1, 1),
|
||||||
|
('Sons Iniciais', 'Exercícios com sons iniciais', 1, 2),
|
||||||
|
('Sons Finais', 'Exercícios com sons finais', 2, 3),
|
||||||
|
('Sílabas', 'Exercícios de contagem de sílabas', 2, 4)
|
||||||
|
RETURNING id, name, level -- Include level in the RETURNING clause
|
||||||
|
),
|
||||||
|
|
||||||
|
-- Inserir tipos de exercícios
|
||||||
|
inserted_types AS (
|
||||||
|
INSERT INTO phonics_exercise_types (name, description) VALUES
|
||||||
|
('rhyme', 'Exercícios de rima'),
|
||||||
|
('initial_sound', 'Exercícios de som inicial'),
|
||||||
|
('final_sound', 'Exercícios de som final'),
|
||||||
|
('syllables', 'Exercícios de sílabas')
|
||||||
|
RETURNING id, name
|
||||||
|
),
|
||||||
|
|
||||||
|
-- Inserir palavras para os exercícios
|
||||||
|
inserted_words AS (
|
||||||
|
INSERT INTO phonics_words (word, phonetic_transcription, syllables_count) VALUES
|
||||||
|
-- Palavras para rimas
|
||||||
|
('bola', 'bɔ.la', 2),
|
||||||
|
('cola', 'kɔ.la', 2),
|
||||||
|
('mola', 'mɔ.la', 2),
|
||||||
|
('sala', 'sa.la', 2),
|
||||||
|
-- Palavras para sons iniciais
|
||||||
|
('pato', 'pa.to', 2),
|
||||||
|
('pera', 'pe.ɾa', 2),
|
||||||
|
('gato', 'ga.to', 2),
|
||||||
|
('mesa', 'me.za', 2),
|
||||||
|
-- Palavras para sons finais
|
||||||
|
('casa', 'ka.za', 2),
|
||||||
|
('rosa', 'ʁo.za', 2),
|
||||||
|
('rato', 'ʁa.to', 2),
|
||||||
|
('mato', 'ma.to', 2),
|
||||||
|
-- Palavras para sílabas
|
||||||
|
('borboleta', 'boʁ.bo.le.ta', 4),
|
||||||
|
('sol', 'sɔw', 1),
|
||||||
|
('cachorro', 'ka.ʃo.ʁo', 3),
|
||||||
|
('pé', 'pɛ', 1)
|
||||||
|
RETURNING id, word
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Inserir exercícios
|
||||||
|
, inserted_exercises AS (
|
||||||
|
INSERT INTO phonics_exercises (
|
||||||
|
category_id,
|
||||||
|
type_id,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
difficulty_level,
|
||||||
|
estimated_time_seconds,
|
||||||
|
instructions,
|
||||||
|
points,
|
||||||
|
is_active,
|
||||||
|
required_score
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
c.id,
|
||||||
|
t.id,
|
||||||
|
CASE t.name
|
||||||
|
WHEN 'rhyme' THEN 'Encontre a Rima: Bola'
|
||||||
|
WHEN 'initial_sound' THEN 'Som Inicial: Pato'
|
||||||
|
WHEN 'final_sound' THEN 'Som Final: Casa'
|
||||||
|
WHEN 'syllables' THEN 'Conte as Sílabas: Borboleta'
|
||||||
|
END,
|
||||||
|
CASE t.name
|
||||||
|
WHEN 'rhyme' THEN 'Encontre a palavra que rima com BOLA'
|
||||||
|
WHEN 'initial_sound' THEN 'Encontre a palavra que começa com o mesmo som de PATO'
|
||||||
|
WHEN 'final_sound' THEN 'Encontre a palavra que termina com o mesmo som de CASA'
|
||||||
|
WHEN 'syllables' THEN 'Quantas sílabas tem a palavra BORBOLETA?'
|
||||||
|
END,
|
||||||
|
CASE
|
||||||
|
WHEN c.level = 1 THEN 1
|
||||||
|
ELSE 2
|
||||||
|
END,
|
||||||
|
60,
|
||||||
|
CASE t.name
|
||||||
|
WHEN 'rhyme' THEN 'Clique na palavra que rima com BOLA'
|
||||||
|
WHEN 'initial_sound' THEN 'Clique na palavra que começa com o mesmo som de PATO'
|
||||||
|
WHEN 'final_sound' THEN 'Clique na palavra que termina com o mesmo som de CASA'
|
||||||
|
WHEN 'syllables' THEN 'Clique no número que representa a quantidade de sílabas da palavra BORBOLETA'
|
||||||
|
END,
|
||||||
|
10,
|
||||||
|
true,
|
||||||
|
0.7
|
||||||
|
FROM inserted_categories c
|
||||||
|
JOIN inserted_types t ON
|
||||||
|
(c.name = 'Rimas' AND t.name = 'rhyme') OR
|
||||||
|
(c.name = 'Sons Iniciais' AND t.name = 'initial_sound') OR
|
||||||
|
(c.name = 'Sons Finais' AND t.name = 'final_sound') OR
|
||||||
|
(c.name = 'Sílabas' AND t.name = 'syllables')
|
||||||
|
RETURNING id, type_id
|
||||||
|
)
|
||||||
|
|
||||||
|
-- Relacionar exercícios com palavras
|
||||||
|
INSERT INTO phonics_exercise_words (exercise_id, word_id, is_correct_answer, order_index)
|
||||||
|
SELECT
|
||||||
|
e.id,
|
||||||
|
w.id,
|
||||||
|
CASE
|
||||||
|
-- Exercício de rima (bola)
|
||||||
|
WHEN t.name = 'rhyme' AND w.word IN ('bola', 'cola') THEN true
|
||||||
|
WHEN t.name = 'rhyme' AND w.word IN ('gato', 'mesa') THEN false
|
||||||
|
-- Exercício de som inicial (pato)
|
||||||
|
WHEN t.name = 'initial_sound' AND w.word IN ('pato', 'pera') THEN true
|
||||||
|
WHEN t.name = 'initial_sound' AND w.word IN ('gato', 'mesa') THEN false
|
||||||
|
-- Exercício de som final (casa)
|
||||||
|
WHEN t.name = 'final_sound' AND w.word IN ('casa', 'rosa') THEN true
|
||||||
|
WHEN t.name = 'final_sound' AND w.word IN ('rato', 'mato') THEN false
|
||||||
|
-- Exercício de sílabas (borboleta)
|
||||||
|
WHEN t.name = 'syllables' AND w.word = 'borboleta' THEN true
|
||||||
|
WHEN t.name = 'syllables' AND w.word IN ('sol', 'cachorro', 'pé') THEN false
|
||||||
|
END,
|
||||||
|
CASE
|
||||||
|
-- Ordem para exercício de rima
|
||||||
|
WHEN t.name = 'rhyme' AND w.word = 'bola' THEN 1
|
||||||
|
WHEN t.name = 'rhyme' AND w.word = 'cola' THEN 2
|
||||||
|
WHEN t.name = 'rhyme' AND w.word = 'gato' THEN 3
|
||||||
|
WHEN t.name = 'rhyme' AND w.word = 'mesa' THEN 4
|
||||||
|
-- Ordem para exercício de som inicial
|
||||||
|
WHEN t.name = 'initial_sound' AND w.word = 'pato' THEN 1
|
||||||
|
WHEN t.name = 'initial_sound' AND w.word = 'pera' THEN 2
|
||||||
|
WHEN t.name = 'initial_sound' AND w.word = 'gato' THEN 3
|
||||||
|
WHEN t.name = 'initial_sound' AND w.word = 'mesa' THEN 4
|
||||||
|
-- Ordem para exercício de som final
|
||||||
|
WHEN t.name = 'final_sound' AND w.word = 'casa' THEN 1
|
||||||
|
WHEN t.name = 'final_sound' AND w.word = 'rosa' THEN 2
|
||||||
|
WHEN t.name = 'final_sound' AND w.word = 'rato' THEN 3
|
||||||
|
WHEN t.name = 'final_sound' AND w.word = 'mato' THEN 4
|
||||||
|
-- Ordem para exercício de sílabas
|
||||||
|
WHEN t.name = 'syllables' AND w.word = 'borboleta' THEN 1
|
||||||
|
WHEN t.name = 'syllables' AND w.word = 'sol' THEN 2
|
||||||
|
WHEN t.name = 'syllables' AND w.word = 'cachorro' THEN 3
|
||||||
|
WHEN t.name = 'syllables' AND w.word = 'pé' THEN 4
|
||||||
|
END
|
||||||
|
FROM inserted_exercises e
|
||||||
|
JOIN inserted_types t ON t.id = e.type_id
|
||||||
|
JOIN inserted_words w ON
|
||||||
|
(t.name = 'rhyme' AND w.word IN ('bola', 'cola', 'gato', 'mesa')) OR
|
||||||
|
(t.name = 'initial_sound' AND w.word IN ('pato', 'pera', 'gato', 'mesa')) OR
|
||||||
|
(t.name = 'final_sound' AND w.word IN ('casa', 'rosa', 'rato', 'mato')) OR
|
||||||
|
(t.name = 'syllables' AND w.word IN ('borboleta', 'sol', 'cachorro', 'pé'));
|
||||||
Loading…
Reference in New Issue
Block a user