2025-06-10 20:07:11 +00:00
-- =====================================================
-- SAMPLE DATA FOR TABLOS SYSTEM
-- =====================================================
-- Sample tablos data
INSERT INTO tablos ( id , name , description , color , owner_id , is_public ) VALUES
2025-07-05 13:16:42 +00:00
( ' A1B2C3D4E5F6G7H8I9J0K1L2 ' , ' Projet Alpha ' , ' Développement de la nouvelle application mobile ' , ' bg-blue-500 ' , auth . uid ( ) , false ) ,
( ' M3N4O5P6Q7R8S9T0U1V2W3X4 ' , ' Marketing Q4 ' , ' Campagnes marketing pour le quatrième trimestre 2024 ' , ' bg-green-500 ' , auth . uid ( ) , true ) ,
( ' Y5Z6A7B8C9D0E1F2G3H4I5J6 ' , ' Équipe Dev ' , ' Coordination et suivi de l '' équipe de développement ' , ' bg-purple-500 ' , auth . uid ( ) , false ) ,
( ' K7L8M9N0O1P2Q3R4S5T6U7V8 ' , ' Budget 2024 ' , ' Planification et suivi budgétaire pour l '' année 2024 ' , ' bg-red-500 ' , auth . uid ( ) , false ) ,
( ' W9X0Y1Z2A3B4C5D6E7F8G9H0 ' , ' Roadmap Produit ' , ' Feuille de route et évolution du produit ' , ' bg-yellow-500 ' , auth . uid ( ) , true ) ,
( ' I1J2K3L4M5N6O7P8Q9R0S1T2 ' , ' Support Client ' , ' Gestion et suivi du support client ' , ' bg-indigo-500 ' , auth . uid ( ) , false ) ;
2025-06-10 20:07:11 +00:00
-- Sample boards for each tablo
INSERT INTO tablo_boards ( tablo_id , name , type , description , position , created_by ) VALUES
-- Projet Alpha boards
2025-07-05 13:16:42 +00:00
( ' A1B2C3D4E5F6G7H8I9J0K1L2 ' , ' Développement ' , ' kanban ' , ' Suivi des tâches de développement ' , 0 , auth . uid ( ) ) ,
( ' A1B2C3D4E5F6G7H8I9J0K1L2 ' , ' Planning ' , ' calendar ' , ' Calendrier du projet ' , 1 , auth . uid ( ) ) ,
( ' A1B2C3D4E5F6G7H8I9J0K1L2 ' , ' Discussion ' , ' chat ' , ' Chat de l '' équipe projet ' , 2 , auth . uid ( ) ) ,
2025-06-10 20:07:11 +00:00
-- Marketing Q4 boards
2025-07-05 13:16:42 +00:00
( ' M3N4O5P6Q7R8S9T0U1V2W3X4 ' , ' Campagnes ' , ' kanban ' , ' Suivi des campagnes marketing ' , 0 , auth . uid ( ) ) ,
( ' M3N4O5P6Q7R8S9T0U1V2W3X4 ' , ' Calendrier Editorial ' , ' calendar ' , ' Planning des publications ' , 1 , auth . uid ( ) ) ,
2025-06-10 20:07:11 +00:00
-- Équipe Dev boards
2025-07-05 13:16:42 +00:00
( ' Y5Z6A7B8C9D0E1F2G3H4I5J6 ' , ' Sprint Board ' , ' kanban ' , ' Tableau de bord du sprint actuel ' , 0 , auth . uid ( ) ) ,
( ' Y5Z6A7B8C9D0E1F2G3H4I5J6 ' , ' Backlog ' , ' table ' , ' Backlog produit ' , 1 , auth . uid ( ) ) ;
2025-06-10 20:07:11 +00:00
-- Sample lists for Kanban boards
INSERT INTO tablo_lists ( board_id , name , position , color ) VALUES
-- For Projet Alpha - Développement board
2025-07-05 13:16:42 +00:00
( ( SELECT id FROM tablo_boards WHERE name = ' Développement ' AND tablo_id = ' A1B2C3D4E5F6G7H8I9J0K1L2 ' ) , ' À faire ' , 0 , ' bg-gray-200 ' ) ,
( ( SELECT id FROM tablo_boards WHERE name = ' Développement ' AND tablo_id = ' A1B2C3D4E5F6G7H8I9J0K1L2 ' ) , ' En cours ' , 1 , ' bg-blue-200 ' ) ,
( ( SELECT id FROM tablo_boards WHERE name = ' Développement ' AND tablo_id = ' A1B2C3D4E5F6G7H8I9J0K1L2 ' ) , ' En test ' , 2 , ' bg-yellow-200 ' ) ,
( ( SELECT id FROM tablo_boards WHERE name = ' Développement ' AND tablo_id = ' A1B2C3D4E5F6G7H8I9J0K1L2 ' ) , ' Terminé ' , 3 , ' bg-green-200 ' ) ,
2025-06-10 20:07:11 +00:00
-- For Marketing Q4 - Campagnes board
2025-07-05 13:16:42 +00:00
( ( SELECT id FROM tablo_boards WHERE name = ' Campagnes ' AND tablo_id = ' M3N4O5P6Q7R8S9T0U1V2W3X4 ' ) , ' Idées ' , 0 , ' bg-purple-200 ' ) ,
( ( SELECT id FROM tablo_boards WHERE name = ' Campagnes ' AND tablo_id = ' M3N4O5P6Q7R8S9T0U1V2W3X4 ' ) , ' En préparation ' , 1 , ' bg-orange-200 ' ) ,
( ( SELECT id FROM tablo_boards WHERE name = ' Campagnes ' AND tablo_id = ' M3N4O5P6Q7R8S9T0U1V2W3X4 ' ) , ' En cours ' , 2 , ' bg-blue-200 ' ) ,
( ( SELECT id FROM tablo_boards WHERE name = ' Campagnes ' AND tablo_id = ' M3N4O5P6Q7R8S9T0U1V2W3X4 ' ) , ' Terminées ' , 3 , ' bg-green-200 ' ) ;
2025-06-10 20:07:11 +00:00
-- Sample cards
INSERT INTO tablo_cards ( list_id , title , description , position , priority , due_date , created_by ) VALUES
-- Cards for "À faire" list
( ( SELECT id FROM tablo_lists WHERE name = ' À faire ' LIMIT 1 ) , ' Créer l '' interface utilisateur ' , ' Développer les écrans principaux de l '' application mobile ' , 0 , ' high ' , NOW ( ) + INTERVAL ' 1 week ' , auth . uid ( ) ) ,
( ( SELECT id FROM tablo_lists WHERE name = ' À faire ' LIMIT 1 ) , ' Intégration API backend ' , ' Connecter l '' application aux services backend ' , 1 , ' medium ' , NOW ( ) + INTERVAL ' 2 weeks ' , auth . uid ( ) ) ,
( ( SELECT id FROM tablo_lists WHERE name = ' À faire ' LIMIT 1 ) , ' Tests unitaires ' , ' Écrire les tests pour les composants critiques ' , 2 , ' medium ' , NOW ( ) + INTERVAL ' 3 weeks ' , auth . uid ( ) ) ,
-- Cards for "En cours" list
( ( SELECT id FROM tablo_lists WHERE name = ' En cours ' LIMIT 1 ) , ' Configuration base de données ' , ' Mise en place de la structure de données ' , 0 , ' high ' , NOW ( ) + INTERVAL ' 3 days ' , auth . uid ( ) ) ,
( ( SELECT id FROM tablo_lists WHERE name = ' En cours ' LIMIT 1 ) , ' Authentification utilisateur ' , ' Système de login/logout ' , 1 , ' high ' , NOW ( ) + INTERVAL ' 5 days ' , auth . uid ( ) ) ;
-- Sample chat channels
INSERT INTO tablo_chat_channels ( tablo_id , name , type , description , created_by ) VALUES
2025-07-05 13:16:42 +00:00
( ' A1B2C3D4E5F6G7H8I9J0K1L2 ' , ' général ' , ' public ' , ' Discussion générale du projet Alpha ' , auth . uid ( ) ) ,
( ' A1B2C3D4E5F6G7H8I9J0K1L2 ' , ' dev-team ' , ' private ' , ' Canal privé pour l '' équipe de développement ' , auth . uid ( ) ) ,
( ' M3N4O5P6Q7R8S9T0U1V2W3X4 ' , ' marketing-general ' , ' public ' , ' Discussion générale marketing ' , auth . uid ( ) ) ,
( ' Y5Z6A7B8C9D0E1F2G3H4I5J6 ' , ' daily-standup ' , ' public ' , ' Daily standup de l '' équipe dev ' , auth . uid ( ) ) ;
2025-06-10 20:07:11 +00:00
-- Sample chat messages
INSERT INTO tablo_chat_messages ( channel_id , user_id , content , message_type ) VALUES
( ( SELECT id FROM tablo_chat_channels WHERE name = ' général ' LIMIT 1 ) , auth . uid ( ) , ' Bonjour l '' équipe ! Prêts pour le sprint ? ' , ' text ' ) ,
( ( SELECT id FROM tablo_chat_channels WHERE name = ' général ' LIMIT 1 ) , auth . uid ( ) , ' Oui, j '' ai terminé la configuration de l '' environnement ' , ' text ' ) ,
( ( SELECT id FROM tablo_chat_channels WHERE name = ' dev-team ' LIMIT 1 ) , auth . uid ( ) , ' Le build est cassé sur la branche develop ' , ' text ' ) ,
( ( SELECT id FROM tablo_chat_channels WHERE name = ' marketing-general ' LIMIT 1 ) , auth . uid ( ) , ' Nouvelle campagne lancée ce matin ! ' , ' text ' ) ;
-- =====================================================
-- USEFUL QUERIES FOR TABLOS SYSTEM
-- =====================================================
-- 1. Get all tablos for a user (owned or member of)
/*
SELECT DISTINCT t . * , tm . role , tm . permissions
FROM tablos t
LEFT JOIN tablo_members tm ON t . id = tm . tablo_id AND tm . user_id = auth . uid ( )
WHERE t . owner_id = auth . uid ( )
OR tm . user_id = auth . uid ( )
OR t . is_public = true
ORDER BY t . updated_at DESC ;
* /
-- 2. Get tablo with all its boards and lists
/*
SELECT
t . name as tablo_name ,
t . description as tablo_description ,
b . name as board_name ,
b . type as board_type ,
l . name as list_name ,
l . position as list_position
FROM tablos t
LEFT JOIN tablo_boards b ON t . id = b . tablo_id
LEFT JOIN tablo_lists l ON b . id = l . board_id
WHERE t . id = ' your-tablo-id '
ORDER BY b . position , l . position ;
* /
-- 3. Get cards with assignees for a specific board
/*
SELECT
c . title ,
c . description ,
c . priority ,
c . due_date ,
l . name as list_name ,
c . assignees ,
c . labels
FROM tablo_cards c
JOIN tablo_lists l ON c . list_id = l . id
JOIN tablo_boards b ON l . board_id = b . id
WHERE b . id = ' your-board-id '
ORDER BY l . position , c . position ;
* /
-- 4. Get recent activity for a tablo
/*
SELECT
ta . action ,
ta . entity_type ,
ta . details ,
ta . created_at ,
p . full_name as user_name
FROM tablo_activities ta
JOIN profiles p ON ta . user_id = p . id
WHERE ta . tablo_id = ' your-tablo-id '
ORDER BY ta . created_at DESC
LIMIT 20 ;
* /
-- 5. Get chat messages for a channel with user info
/*
SELECT
tcm . content ,
tcm . message_type ,
tcm . created_at ,
p . full_name as sender_name ,
p . avatar_url
FROM tablo_chat_messages tcm
JOIN profiles p ON tcm . user_id = p . id
WHERE tcm . channel_id = ' your-channel-id '
ORDER BY tcm . created_at ASC ;
* /
-- 6. Get overdue cards across all user's tablos
/*
SELECT
c . title ,
c . due_date ,
c . priority ,
t . name as tablo_name ,
b . name as board_name ,
l . name as list_name
FROM tablo_cards c
JOIN tablo_lists l ON c . list_id = l . id
JOIN tablo_boards b ON l . board_id = b . id
JOIN tablos t ON b . tablo_id = t . id
LEFT JOIN tablo_members tm ON t . id = tm . tablo_id
WHERE ( t . owner_id = auth . uid ( ) OR tm . user_id = auth . uid ( ) )
AND c . due_date < NOW ( )
AND c . due_date IS NOT NULL
ORDER BY c . due_date ASC ;
* /
-- 7. Get member statistics for a tablo
/*
SELECT
COUNT ( * ) as total_members ,
COUNT ( CASE WHEN tm . role = ' owner ' THEN 1 END ) as owners ,
COUNT ( CASE WHEN tm . role = ' admin ' THEN 1 END ) as admins ,
COUNT ( CASE WHEN tm . role = ' member ' THEN 1 END ) as members ,
COUNT ( CASE WHEN tm . role = ' viewer ' THEN 1 END ) as viewers
FROM tablo_members tm
WHERE tm . tablo_id = ' your-tablo-id ' ;
* /
-- 8. Search cards by content
/*
SELECT
c . title ,
c . description ,
t . name as tablo_name ,
b . name as board_name ,
l . name as list_name ,
ts_rank ( to_tsvector ( ' french ' , c . title | | ' ' | | COALESCE ( c . description , ' ' ) ) ,
plainto_tsquery ( ' french ' , ' search-term ' ) ) as rank
FROM tablo_cards c
JOIN tablo_lists l ON c . list_id = l . id
JOIN tablo_boards b ON l . board_id = b . id
JOIN tablos t ON b . tablo_id = t . id
LEFT JOIN tablo_members tm ON t . id = tm . tablo_id
WHERE ( t . owner_id = auth . uid ( ) OR tm . user_id = auth . uid ( ) )
AND to_tsvector ( ' french ' , c . title | | ' ' | | COALESCE ( c . description , ' ' ) )
@ @ plainto_tsquery ( ' french ' , ' search-term ' )
ORDER BY rank DESC ;
* /
-- =====================================================
-- VIEWS FOR COMMON QUERIES
-- =====================================================
-- View for user's tablos with member info
CREATE VIEW user_tablos AS
SELECT DISTINCT
t . * ,
COALESCE ( tm . role , ' owner ' ) as user_role ,
COALESCE ( tm . permissions , ' {"read": true, "write": true, "admin": true} ' : : jsonb ) as user_permissions ,
( SELECT COUNT ( * ) FROM tablo_members WHERE tablo_id = t . id ) as member_count
FROM tablos t
LEFT JOIN tablo_members tm ON t . id = tm . tablo_id AND tm . user_id = auth . uid ( )
WHERE t . owner_id = auth . uid ( )
OR tm . user_id = auth . uid ( )
OR t . is_public = true ;
-- View for tablo structure (boards, lists, cards count)
CREATE VIEW tablo_structure AS
SELECT
t . id as tablo_id ,
t . name as tablo_name ,
COUNT ( DISTINCT b . id ) as boards_count ,
COUNT ( DISTINCT l . id ) as lists_count ,
COUNT ( DISTINCT c . id ) as cards_count
FROM tablos t
LEFT JOIN tablo_boards b ON t . id = b . tablo_id
LEFT JOIN tablo_lists l ON b . id = l . board_id
LEFT JOIN tablo_cards c ON l . id = c . list_id
GROUP BY t . id , t . name ;
-- View for recent activities across all user tablos
CREATE VIEW user_recent_activities AS
SELECT
ta . * ,
t . name as tablo_name ,
p . full_name as user_name
FROM tablo_activities ta
JOIN tablos t ON ta . tablo_id = t . id
JOIN profiles p ON ta . user_id = p . id
LEFT JOIN tablo_members tm ON t . id = tm . tablo_id AND tm . user_id = auth . uid ( )
WHERE t . owner_id = auth . uid ( ) OR tm . user_id = auth . uid ( )
ORDER BY ta . created_at DESC ;