Base : ménage, descriptions de chaque table et fonction, plan dans docs/database.md
deploy / deploy (push) Successful in 50s
deploy / deploy (push) Successful in 50s
- Correctif : azuu_before_write (aussi utilisé par settings, sans colonne « deleted ») refusait toute modification des réglages depuis 20261129180000. Comparaison faite sur la ligne entière. Aucun envoi de réglages n'a eu lieu entre-temps (journaux vérifiés). - Ancienne fonction de quota supprimée (remplacée par azuu_quota_stmt). - 19 tables et 85 fonctions décrites en français (visibles dans le tableau de bord Supabase). - docs/database.md : carte de la base, règles pour la modifier. - Table des fiches compactée en ligne (7 Mo → 456 Ko, anciennes affiches intégrées). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
4 files changed
+242
-1
No files matched your search
@@ -0,0 +1,30 @@
|
||||
-- Correctif de 20261129180000_write_path_perf : azuu_before_write sert aussi à la table settings, qui n'a pas
|
||||
-- de colonne « deleted ». La comparaison « fiche identique » se fait désormais sur la ligne entière
|
||||
-- (sauf la date serveur), quelle que soit la table. Idempotent.
|
||||
create or replace function public.azuu_before_write()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
set search_path = ''
|
||||
as $$
|
||||
begin
|
||||
-- Un appareil resté hors-ligne ne peut pas écraser une version plus récente
|
||||
if tg_op = 'UPDATE' and new.updated_at < old.updated_at then
|
||||
return null;
|
||||
end if;
|
||||
-- Personne ne peut déplacer une ligne vers un autre compte
|
||||
if tg_op = 'UPDATE' and new.user_id <> old.user_id then
|
||||
raise exception 'user_id is immutable';
|
||||
end if;
|
||||
-- Exactement la même version : rien à écrire (la date serveur ne bouge pas, les autres appareils ne la relisent pas)
|
||||
if tg_op = 'UPDATE' and new.updated_at = old.updated_at
|
||||
and (to_jsonb(new) - 'server_updated_at') = (to_jsonb(old) - 'server_updated_at') then
|
||||
return null;
|
||||
end if;
|
||||
-- Date venant du client bornée (pas de date dans le futur lointain qui bloquerait les mises à jour)
|
||||
if new.updated_at > now() + interval '1 day' then
|
||||
new.updated_at := now();
|
||||
end if;
|
||||
new.server_updated_at := clock_timestamp();
|
||||
return new;
|
||||
end;
|
||||
$$;
|
||||
@@ -0,0 +1,120 @@
|
||||
-- Ménage et descriptions (29/11/2026). Chaque table et chaque fonction a désormais une phrase qui dit à quoi
|
||||
-- elle sert : visible dans le tableau de bord Supabase (Table Editor, Database → Functions). Idempotent.
|
||||
|
||||
-- ─── Ménage ───
|
||||
-- Ancien contrôle du quota ligne par ligne, remplacé par azuu_quota_stmt (20261129180000)
|
||||
drop function if exists public.azuu_quota();
|
||||
|
||||
-- ─── Tables ───
|
||||
comment on table public.items is 'Fiches de la bibliothèque : une ligne par titre et par compte. data = la fiche complète (JSON), deleted = supprimée (data vidée, trace gardée pour la synchro), updated_at = date de l''appareil, server_updated_at = date serveur (curseur de la synchro).';
|
||||
comment on table public.lists is 'Listes perso d''un compte (synchronisées comme les fiches). Privées : jamais montrées aux autres.';
|
||||
comment on table public.settings is 'Réglages de l''app d''un compte (une ligne par compte), synchronisés entre appareils.';
|
||||
comment on table public.profiles is 'Profil public : pseudo, nom affiché, photo, bannière, bio, compte privé, compte suspendu. Créé à l''inscription (azuu_new_user).';
|
||||
comment on table public.follows is 'Abonnements : follower_id suit following_id. status = pending (demande à un compte privé) ou accepted.';
|
||||
comment on table public.blocks is 'Blocages : blocker_id bloque blocked_id. Lus et écrits seulement par les fonctions (block_user, my_blocks…).';
|
||||
comment on table public.activity is 'Fil d''activité (titre fini, revu, noté…), écrit par le trigger items_activity. Lu par get_feed.';
|
||||
comment on table public.notifications is 'Notifications dans l''app (abonnements, réactions, commentaires, activité des comptes suivis). Au plus ~200 par personne.';
|
||||
comment on table public.review_reactions is 'Réactions emoji sur un avis (author_id + item_id = l''avis, user_id = qui réagit).';
|
||||
comment on table public.review_comments is 'Commentaires sur un avis (author_id + item_id = l''avis, user_id = qui commente).';
|
||||
comment on table public.shared_lists is 'Listes partagées entre amis (owner_id = créateur).';
|
||||
comment on table public.shared_list_members is 'Membres d''une liste partagée (invités ou acceptés).';
|
||||
comment on table public.shared_list_items is 'Titres d''une liste partagée (copie légère du titre : nom, affiche, type).';
|
||||
comment on table public.reports is 'Signalements (avis, commentaire, profil…) envoyés par les utilisateurs, traités dans l''admin.';
|
||||
comment on table public.moderation_log is 'Journal des actions de modération (suspension, avis effacé, signalement traité…).';
|
||||
comment on table public.admins is 'Comptes administrateurs.';
|
||||
comment on table public.bug_reports is 'Bugs signalés depuis l''app (Réglages → Signaler un bug).';
|
||||
comment on table public.client_errors is 'Erreurs de l''app remontées automatiquement, regroupées par empreinte, sans donnée personnelle (log_client_error).';
|
||||
comment on table public.title_ratings is 'Réserve des notes Trakt (moyenne, votes, répartition) partagée par tous, rafraîchie après 24 h. Remplie par la fonction Edge « ratings ».';
|
||||
|
||||
-- ─── Fonctions appelées par l'app ───
|
||||
comment on function public.get_feed(timestamptz, integer) is 'App : fil des abonnements de l''accueil, par pages.';
|
||||
comment on function public.get_profile(text) is 'App : profil d''un pseudo (infos, compteurs, relation avec moi).';
|
||||
comment on function public.get_profile_items(uuid, text, integer, integer) is 'App : titres d''un profil pour un statut, par pages (champs privés retirés).';
|
||||
comment on function public.get_follow_list(uuid, text, integer) is 'App : abonnés ou abonnements d''un profil.';
|
||||
comment on function public.get_follow_requests() is 'App : demandes d''abonnement reçues (compte privé).';
|
||||
comment on function public.search_profiles(text) is 'App : recherche de profils par pseudo ou nom.';
|
||||
comment on function public.get_notifications() is 'App : mes notifications, avec le titre lié.';
|
||||
comment on function public.unread_notifications() is 'App : nombre de notifications non lues.';
|
||||
comment on function public.mark_notifications_read() is 'App : tout marquer comme lu, et garder les 200 plus récentes.';
|
||||
comment on function public.title_reviews(text, integer) is 'App : avis sur un titre (amis d''abord, puis les autres), par pages.';
|
||||
comment on function public.react_to_review(uuid, text, text) is 'App : réagir (emoji) à un avis.';
|
||||
comment on function public.unreact_review(uuid, text) is 'App : retirer ma réaction à un avis.';
|
||||
comment on function public.add_review_comment(uuid, text, text) is 'App : commenter un avis.';
|
||||
comment on function public.get_review_comments(uuid, text) is 'App : commentaires d''un avis.';
|
||||
comment on function public.delete_review_comment(bigint) is 'App : supprimer mon commentaire (ou un commentaire sous mon avis).';
|
||||
comment on function public.block_user(uuid) is 'App : bloquer un compte.';
|
||||
comment on function public.unblock_user(uuid) is 'App : débloquer un compte.';
|
||||
comment on function public.my_blocks() is 'App : comptes que j''ai bloqués.';
|
||||
comment on function public.report_content(text, text, uuid, text, text) is 'App : signaler un contenu (avis, commentaire, profil…).';
|
||||
comment on function public.submit_bug_report(text, jsonb) is 'App : signaler un bug.';
|
||||
comment on function public.log_client_error(text, text, text, text, text, text) is 'App : remonter une erreur (aussi sans compte), nettoyée et limitée en débit.';
|
||||
comment on function public.create_shared_list(text) is 'App : créer une liste partagée.';
|
||||
comment on function public.rename_shared_list(uuid, text) is 'App : renommer une liste partagée (créateur).';
|
||||
comment on function public.delete_shared_list(uuid) is 'App : supprimer une liste partagée (créateur).';
|
||||
comment on function public.leave_shared_list(uuid) is 'App : quitter une liste partagée.';
|
||||
comment on function public.invite_to_shared_list(uuid, uuid) is 'App : inviter un ami dans une liste partagée.';
|
||||
comment on function public.respond_shared_list_invite(uuid, boolean) is 'App : accepter ou refuser une invitation à une liste partagée.';
|
||||
comment on function public.remove_shared_list_member(uuid, uuid) is 'App : retirer un membre d''une liste partagée (créateur).';
|
||||
comment on function public.add_shared_list_item(uuid, jsonb) is 'App : ajouter un titre à une liste partagée.';
|
||||
comment on function public.remove_shared_list_item(uuid, text) is 'App : retirer un titre d''une liste partagée.';
|
||||
comment on function public.get_shared_list(uuid) is 'App : contenu d''une liste partagée (membres et titres).';
|
||||
comment on function public.get_shared_lists(text) is 'App : mes listes partagées et les invitations reçues.';
|
||||
comment on function public.shared_list_candidates(uuid, text) is 'App : comptes que je peux inviter dans ma liste partagée (recherche).';
|
||||
comment on function public.is_admin() is 'App : suis-je administrateur (double authentification validée si activée) ?';
|
||||
|
||||
-- ─── Administration ───
|
||||
comment on function public.admin_overview() is 'Admin : chiffres généraux (comptes, fiches, avis…).';
|
||||
comment on function public.admin_alerts() is 'Admin : ce qui attend une action (signalements, bugs, erreurs).';
|
||||
comment on function public.admin_users(text, integer) is 'Admin : recherche de comptes.';
|
||||
comment on function public.admin_suspended_users(integer) is 'Admin : comptes suspendus.';
|
||||
comment on function public.admin_set_suspended(uuid, boolean) is 'Admin : suspendre ou réactiver un compte.';
|
||||
comment on function public.admin_recent_reviews(integer) is 'Admin : derniers avis publiés.';
|
||||
comment on function public.admin_clear_review(uuid, text) is 'Admin : effacer un avis.';
|
||||
comment on function public.admin_reports(text, integer) is 'Admin : signalements.';
|
||||
comment on function public.admin_report_action(text, text, uuid, text) is 'Admin : traiter un signalement (supprimer, suspendre, ignorer, résoudre…).';
|
||||
comment on function public.admin_bug_reports(text, integer) is 'Admin : bugs signalés.';
|
||||
comment on function public.admin_set_bug_status(bigint, text) is 'Admin : changer le statut d''un bug.';
|
||||
comment on function public.admin_client_errors(text, integer) is 'Admin : erreurs de l''app.';
|
||||
comment on function public.admin_set_error_status(text, text) is 'Admin : changer le statut d''une erreur.';
|
||||
comment on function public.azuu_admin_card(uuid) is 'Interne (admin) : carte d''un compte (pseudo, photo, suspendu, admin).';
|
||||
|
||||
-- ─── Aides internes (non appelables par l'app) ───
|
||||
comment on function public.azuu_mfa_ok() is 'Règle : vrai si le compte n''a pas de double authentification, ou si le code a été validé (aal2). Utilisée par les règles « mfa required ».';
|
||||
comment on function public.azuu_me_active() is 'Règle : mon compte n''est pas suspendu et la double authentification est validée.';
|
||||
comment on function public.azuu_media_count() is 'Règle de stockage : nombre de photos de profil que j''ai envoyées (limite).';
|
||||
comment on function public.can_view(uuid) is 'Règle : puis-je voir le contenu de ce compte (moi, compte public ou abonné accepté, sans blocage ni suspension) ?';
|
||||
comment on function public.azuu_review_visible(uuid, text) is 'Règle : cet avis m''est-il visible ?';
|
||||
comment on function public.azuu_can_notify(uuid, uuid) is 'Règle : peut-on notifier ce compte (pas soi-même, pas de blocage, compte actif) ?';
|
||||
comment on function public.azuu_sl_owner(uuid) is 'Règle : suis-je le créateur de cette liste partagée ?';
|
||||
comment on function public.azuu_sl_member(uuid) is 'Règle : suis-je membre (accepté) de cette liste partagée ?';
|
||||
comment on function public.azuu_sl_name(text) is 'Nettoie le nom d''une liste partagée (espaces, caractères de contrôle).';
|
||||
comment on function public.profile_card(public.profiles) is 'Carte de profil (pseudo, nom, photo) avec ma relation (abonné, demande…).';
|
||||
comment on function public.azuu_mini_card(public.profiles) is 'Carte de profil minimale : pseudo, nom, photo.';
|
||||
comment on function public.public_item(jsonb) is 'Fiche sans ses champs privés (listes perso, tags, journal des épisodes…), pour les profils et le fil.';
|
||||
comment on function public.azuu_notify_followers(uuid, text, text) is 'Notifie tous les abonnés d''un compte en une requête (rafales regroupées sur 3 h).';
|
||||
comment on function public.azuu_notif_prune(uuid) is 'Garde les 200 notifications les plus récentes d''une personne.';
|
||||
comment on function public.azuu_log(uuid, text, text) is 'Ajoute une ligne au fil d''activité (pas deux fois la même dans la journée).';
|
||||
comment on function public.azuu_day(text) is 'Texte AAAA-MM-JJ → date (null si invalide).';
|
||||
comment on function public.azuu_random_username() is 'Pseudo de départ libre : « cinephile_xxxxxx ».';
|
||||
comment on function public.azuu_scrub(text, integer) is 'Nettoie un texte d''erreur avant enregistrement (e-mails, jetons, caractères de contrôle retirés).';
|
||||
|
||||
-- ─── Triggers ───
|
||||
comment on function public.azuu_before_write() is 'Trigger (items, lists, settings) : refuse une version plus ancienne, pose la date serveur, ignore une ligne renvoyée à l''identique.';
|
||||
comment on function public.azuu_tombstone() is 'Trigger (items, lists) : ligne supprimée → contenu vidé (seule la trace reste, pour la synchro).';
|
||||
comment on function public.azuu_quota_stmt() is 'Trigger (items, lists) : au plus 20 000 fiches et 300 listes par compte, vérifié une fois par envoi.';
|
||||
comment on function public.azuu_item_activity() is 'Trigger (items) : ajoute au fil d''activité (fini, revu, noté).';
|
||||
comment on function public.azuu_item_notify() is 'Trigger (items) : notifie les abonnés (nouvel avis, série commencée, ajout à voir).';
|
||||
comment on function public.azuu_review_cleanup() is 'Trigger (items) : avis effacé ou fiche supprimée → réactions et commentaires supprimés.';
|
||||
comment on function public.azuu_new_user() is 'Trigger (auth.users) : crée le profil d''un nouveau compte.';
|
||||
comment on function public.azuu_profile_guard() is 'Trigger (profiles) : id non modifiable, pseudo / nom / bio nettoyés.';
|
||||
comment on function public.azuu_profile_media_guard() is 'Trigger (profiles) : photo et bannière seulement depuis notre stockage.';
|
||||
comment on function public.azuu_profile_public() is 'Trigger (profiles) : compte repassé public → demandes d''abonnement en attente acceptées.';
|
||||
comment on function public.azuu_suspended_guard() is 'Trigger (profiles) : seul un admin peut suspendre ou réactiver.';
|
||||
comment on function public.azuu_suspended_log() is 'Trigger (profiles) : suspension / réactivation inscrite au journal de modération.';
|
||||
comment on function public.azuu_follow_guard() is 'Trigger (follows) : abonnement en son propre nom, en demande si le compte est privé.';
|
||||
comment on function public.azuu_follow_block_guard() is 'Trigger (follows) : pas d''abonnement entre comptes bloqués.';
|
||||
comment on function public.azuu_follow_notify() is 'Trigger (follows) : notifications d''abonnement (nouvel abonné, demande, acceptée, désabonnement).';
|
||||
comment on function public.azuu_actor_active_guard() is 'Trigger (follows, review_reactions) : refuse l''action d''un compte suspendu.';
|
||||
comment on function public.azuu_reaction_block_guard() is 'Trigger (review_reactions, review_comments) : refuse si l''auteur de l''avis a bloqué la personne.';
|
||||
comment on function public.azuu_reaction_notify() is 'Trigger (review_reactions) : notification « réaction à ton avis ».';
|
||||
comment on function public.azuu_comment_notify() is 'Trigger (review_comments) : notification « commentaire sur ton avis ».';
|
||||
Reference in new issue
Block a user