feat(fase-12): section visibility model — feature_flags + section_enabled()

Adds JSONB `feature_flags` columns on public.users and public.collectives
(default '{}') plus two SQL helpers:

  * public.known_sections() — IMMUTABLE, returns the canonical 4 sections
    (lists, tasks, notes, search). Adding a section is a fresh migration.
  * public.section_enabled(section, user, collective) — STABLE, returns
    boolean. Precedence is COLLECTIVE > USER > default TRUE, evaluated as
    a single COALESCE so Fase 13 can prepend a server layer as a one-line
    diff. Unknown section keys default TRUE (forward-compat).

No new RLS policy: writes to feature_flags piggyback on users_update_own
and collectives_update (migration 003). 16 new pgTAP assertions verify
column shape, function signatures, volatility, and precedence semantics.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-18 03:47:52 +02:00
parent c1d0dfaee9
commit 59a32f80f7
3 changed files with 273 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ export interface Database {
avatar_emoji: string | null;
avatar_url: string | null;
theme: ThemeMode;
feature_flags: Json;
created_at: string;
updated_at: string;
};
@@ -45,6 +46,7 @@ export interface Database {
avatar_emoji?: string | null;
avatar_url?: string | null;
theme?: ThemeMode;
feature_flags?: Json;
created_at?: string;
updated_at?: string;
};
@@ -57,6 +59,7 @@ export interface Database {
avatar_emoji?: string | null;
avatar_url?: string | null;
theme?: ThemeMode;
feature_flags?: Json;
created_at?: string;
updated_at?: string;
};
@@ -68,6 +71,7 @@ export interface Database {
name: string;
emoji: string;
created_by: string;
feature_flags: Json;
created_at: string;
};
Insert: {
@@ -75,6 +79,7 @@ export interface Database {
name: string;
emoji?: string;
created_by: string;
feature_flags?: Json;
created_at?: string;
};
Update: {
@@ -82,6 +87,7 @@ export interface Database {
name?: string;
emoji?: string;
created_by?: string;
feature_flags?: Json;
created_at?: string;
};
Relationships: [
@@ -485,6 +491,14 @@ export interface Database {
Args: { p_item_id: string };
Returns: string;
};
known_sections: {
Args: Record<string, never>;
Returns: string[];
};
section_enabled: {
Args: { p_section: string; p_user: string; p_collective: string };
Returns: boolean;
};
};
Enums: {
language_code: LanguageCode;