@nextblock-cms/db 0.2.21 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ -- 00000000000042_seed_how_it_works.sql
2
+ -- Populates the English "How NextBlock Works" post with a synthesized technical article.
3
+
4
+ WITH target_posts AS (
5
+ SELECT id, language_id, slug
6
+ FROM public.posts
7
+ WHERE slug IN ('how-nextblock-works', 'comment-nextblock-fonctionne')
8
+ ),
9
+ purged AS (
10
+ DELETE FROM public.blocks
11
+ WHERE post_id IN (SELECT id FROM target_posts)
12
+ )
13
+ INSERT INTO public.blocks (post_id, language_id, block_type, content, "order")
14
+ SELECT
15
+ target_posts.id,
16
+ target_posts.language_id,
17
+ 'text',
18
+ jsonb_build_object(
19
+ 'html_content',
20
+ $$<h2>How NextBlock Works: Architecture for a Visual-First CMS</h2>
21
+ <p>NextBlock is purpose-built to feel like a polished product from day one, and that polish starts with the Nx monorepo. Applications and libraries sit side-by-side so the same code that powers the hosted CMS experience also ships inside the open-source template and CLI. Instead of scattering configuration across projects, TypeScript paths, Tailwind presets, and shared lint rules all originate from the workspace root, which keeps every downstream package aligned.</p>
22
+ <div class='flex flex-col md:flex-row gap-8 items-start my-8'>
23
+ <div class='w-full md:w-3/5 space-y-4'>
24
+ <h3>Monorepo Layout and Dependency Flow</h3>
25
+ <p>The <code>apps/nextblock</code> directory contains the production Next.js interface—both the public site and the authenticated CMS. The <code>apps/create-nextblock</code> CLI mirrors it, syncing files from the main app before publishing a scaffolding tool. Reusable primitives live under <code>libs/</code>. UI components and design tokens are exported from <code>@nextblock-cms/ui</code>, cross-cutting helpers (translations, R2 clients, Supabase environment guards) live in <code>@nextblock-cms/utils</code>, and database code plus migrations are centralized inside <code>@nextblock-cms/db</code>. Future-facing work, like the SDK and e-commerce module, already have dedicated libraries so they can mature without disrupting the core runtime.</p>
26
+ <p>This organization matters because Nx understands project boundaries. When you run <code>nx graph</code> you see exactly how a change in the editor package might ripple into the Next.js app. Path aliases from <code>tsconfig.base.json</code> and the shared <code>tailwind.config.js</code> ensure that every consumer sees the same theme scales and helper utilities, which is crucial for a system that promises design parity between marketing pages, admin screens, and scaffolded customer projects.</p>
27
+ <p>Together, those guardrails mean features can ship quickly without regressions. Schema migrations live in <code>libs/db</code>, UI primitives live in <code>libs/ui</code>, and the CLI simply syncs changes downstream—no copy/paste debt, no drifting configs.</p>
28
+ </div>
29
+ <aside class='md:w-2/5 bg-muted/40 border border-border/40 rounded-2xl p-4 shadow-lg text-center'>
30
+ <img src='/images/nx-graph.webp' alt='Nx project graph preview' class='w-full h-auto object-cover rounded-lg' />
31
+ <p class='text-sm text-muted-foreground mt-3'>Nx keeps every workspace relationship visible.</p>
32
+ </aside>
33
+ </div>
34
+ <h3>Inside the CMS Application</h3>
35
+ <p>Within <code>apps/nextblock/app/cms</code>, each feature area—pages, posts, media, navigation, users, settings—follows a predictable file pattern: a list page, creation and edit routes, server actions, and scoped client components. The root CMS layout enforces authentication, builds the shell (sidebar, responsive header, profile menu), and injects role-aware navigation. That means writers can jump straight into the block editor while admins unlock additional menus such as language management or user provisioning, all without duplicating layout logic.</p>
36
+ <p>Server actions wrap Supabase calls so mutations never leak credentials into the browser. Media uploads coordinate with Cloudflare R2, navigation management includes drag-and-drop ordering, and every table interaction respects the row-level security policies defined in the Supabase migrations—e.g., only admins and writers can mutate pages or posts while anonymous traffic can only read published content.</p>
37
+ <h3>Tech Stack and Runtime</h3>
38
+ <p>The stack highlighted in the project README—Next.js 16, Supabase, Tailwind CSS, and shadcn/ui—was selected to balance developer velocity with runtime performance. Next.js App Router unlocks Server Components, streaming, and incremental static regeneration so marketing experiences remain edge-fast. Supabase covers Postgres, Auth, and Storage, shrinking the operational footprint while still allowing custom SQL migrations. Tailwind plus shadcn/ui provide composable building blocks so the CMS interface, marketing site, and generated client projects all inherit the same visual language.</p>
39
+ <p>Nx tooling ties it together. Common commands such as <code>nx serve nextblock</code>, <code>nx build nextblock</code>, or workspace-wide tasks like <code>nx run-many -t lint --all</code> respect dependency caching, so even large rebuilds feel snappy during the 100-day roadmap.</p>
40
+ <pre><code>nx serve nextblock
41
+ nx run-many -t build --all
42
+ supabase db push
43
+ </code></pre>
44
+ <h3>The Tiptap-Based Block Editor</h3>
45
+ <p>The <code>@nextblock-cms/editor</code> package turns Tiptap v3 into a polished, reusable editing surface. It ships rich-text formatting, tables, task lists, slash commands, floating and bubble menus, character counts, focus mode, and syntax-highlighted code blocks. Under the hood it bundles StarterKit, TextStyleKit, CodeBlockLowlight, Image, TaskList, Table, Link, TextAlign, Highlight, Typography, and more. Because the editor is published as a standalone library, both the CMS and the generated template pull identical behavior, ensuring content parity.</p>
46
+ <p>From an implementation standpoint, the editor exposes granular components—EditorToolbar, BubbleMenu, FloatingMenu—so the CMS can embed one cohesive editing experience while keeping the door open for agencies or plugin developers to compose their own UI. Comprehensive CSS hooks (e.g., <code>.tiptap pre</code> for code blocks) mean that teams can layer in dark-mode friendly themes without forking the core package.</p>
47
+ <h3>Putting It All Together</h3>
48
+ <p>The result is a platform where architecture decisions reinforce each other: the Nx workspace keeps libraries honest, the Next.js app enforces UX consistency, Supabase migrations codify access rules, and the Tiptap editor guarantees that content collaborators see the same tooling regardless of deployment. When a new team runs <code>npm create nextblock</code>, they inherit not just a starter site, but the entire operational philosophy described above—ready to extend with SDKs, premium modules, and marketplace blocks as the ecosystem grows.</p>$$
49
+ ),
50
+ 0
51
+ FROM target_posts
52
+ WHERE target_posts.slug = 'how-nextblock-works'
53
+
54
+ UNION ALL
55
+
56
+ SELECT
57
+ target_posts.id,
58
+ target_posts.language_id,
59
+ 'text',
60
+ jsonb_build_object(
61
+ 'html_content',
62
+ $$<h2>Comment NextBlock fonctionne : architecture pour un CMS axé sur l'expérience visuelle</h2>
63
+ <p>NextBlock est conçu pour fonctionner dès le premier jour avec un socle Nx. Applications et librairies cohabitent pour que le même code propulse l'expérience CMS hébergée et le template open-source. Au lieu d'éparpiller la configuration, les chemins TypeScript, le preset Tailwind et les règles lint sont centralisés à la racine, gardant tous les packages alignés.</p>
64
+ <div class='flex flex-col md:flex-row gap-8 items-start my-8'>
65
+ <div class='w-full md:w-3/5 space-y-4'>
66
+ <h3>Architecture monorepo et flux de dépendances</h3>
67
+ <p>Le dossier <code>apps/nextblock</code> contient l'interface Next.js (site public + CMS). Le CLI <code>apps/create-nextblock</code> la reflète et publie un outil de scaffolding. Les briques réutilisables vivent dans <code>libs/</code> : UI et design tokens via <code>@nextblock-cms/ui</code>, helpers (traductions, R2, règles Supabase) via <code>@nextblock-cms/utils</code>, et la base de données + migrations dans <code>@nextblock-cms/db</code>. Les travaux futurs (SDK, e-commerce) ont déjà leurs librairies dédiées.</p>
68
+ <p>Ce découplage est lisible via <code>nx graph</code> : un changement dans l'éditeur impacte clairement les apps dépendantes. Les alias de <code>tsconfig.base.json</code> et le <code>tailwind.config.js</code> partagé assurent une cohérence de thème et d'outils entre pages marketing, back-office et projets générés.</p>
69
+ <p>En pratique, cela accélère les livraisons sans régressions : migrations dans <code>libs/db</code>, primitives UI dans <code>libs/ui</code>, et le CLI synchronise simplement en aval—pas de dettes de copier/coller ni de configs divergentes.</p>
70
+ </div>
71
+ <aside class='md:w-2/5 bg-muted/40 border border-border/40 rounded-2xl p-4 shadow-lg text-center'>
72
+ <img src='/images/nx-graph.webp' alt='Aperçu du graph Nx' class='w-full h-auto object-cover rounded-lg' />
73
+ <p class='text-sm text-muted-foreground mt-3'>Nx rend visibles toutes les relations du workspace.</p>
74
+ </aside>
75
+ </div>
76
+ <h3>Stack technique et exécution</h3>
77
+ <p>Le stack—Next.js 16, Supabase, Tailwind CSS, shadcn/ui—équilibre vélocité et performance. L'App Router active les Server Components et l'ISR pour un rendu edge rapide. Supabase gère Postgres/Auth/Storage, réduisant l'opérationnel tout en gardant la liberté SQL. Tailwind + shadcn/ui fournissent des blocs réutilisables pour le CMS, le site marketing et les projets générés.</p>
78
+ <pre><code>nx serve nextblock
79
+ nx run-many -t build --all
80
+ supabase db push
81
+ </code></pre>
82
+ <h3>Éditeur basé sur Tiptap</h3>
83
+ <p>Le package <code>@nextblock-cms/editor</code> transforme Tiptap v3 en surface d'édition robuste : mise en forme riche, menus contextuels, compteurs de caractères, blocs de code avec syntax highlighting, tables, listes de tâches, et plus. Éditor et template consomment la même librairie pour garantir la parité de contenu.</p>
84
+ <h3>En résumé</h3>
85
+ <p>Chaque choix architectural se renforce : Nx garde les dépendances lisibles, l'app Next.js impose une UX cohérente, les migrations Supabase codifient l'accès, et l'éditeur Tiptap assure une expérience identique pour tous les contributeurs.</p>$$
86
+ ),
87
+ 0
88
+ FROM target_posts
89
+ WHERE target_posts.slug = 'comment-nextblock-fonctionne';
@@ -0,0 +1,23 @@
1
+ BEGIN;
2
+
3
+ -- Drop the existing restrictive policy
4
+ DROP POLICY IF EXISTS "blocks_authenticated_comprehensive_select" ON public.blocks;
5
+
6
+ -- Create the new inclusive policy
7
+ CREATE POLICY "blocks_authenticated_comprehensive_select" ON public.blocks
8
+ FOR SELECT
9
+ TO authenticated
10
+ USING (
11
+ -- 1. Admin/Writer can see everything
12
+ ((SELECT public.get_current_user_role()) IN ('ADMIN', 'WRITER'))
13
+ OR
14
+ -- 2. Anyone (including USER or no-role) can see published content
15
+ (
16
+ (page_id IS NOT NULL AND EXISTS(SELECT 1 FROM public.pages p WHERE p.id = blocks.page_id AND p.status = 'published')) OR
17
+ (post_id IS NOT NULL AND EXISTS(SELECT 1 FROM public.posts pt WHERE pt.id = blocks.post_id AND pt.status = 'published' AND (pt.published_at IS NULL OR pt.published_at <= now())))
18
+ )
19
+ );
20
+
21
+ COMMENT ON POLICY "blocks_authenticated_comprehensive_select" ON public.blocks IS 'Comprehensive SELECT policy for authenticated users on the blocks table. Admins/Writers see all. Others (including those with missing profiles) see blocks of published parents.';
22
+
23
+ COMMIT;
@@ -0,0 +1,36 @@
1
+ BEGIN;
2
+
3
+ -- ============================================================
4
+ -- 1. Fix Duplicate Policies on public.blocks
5
+ -- ============================================================
6
+
7
+ -- Drop the "extra" policies that were causing duplicates.
8
+ -- These appear to have been introduced in 20250619124100_fix_rls_performance_warnings.sql
9
+ -- but conflict with the standard naming convention used in other migrations.
10
+
11
+ DROP POLICY IF EXISTS "Allow read access to blocks" ON public.blocks;
12
+ DROP POLICY IF EXISTS "Allow insert for admins and writers on blocks" ON public.blocks;
13
+ DROP POLICY IF EXISTS "Allow update for admins and writers on blocks" ON public.blocks;
14
+ DROP POLICY IF EXISTS "Allow delete for admins and writers on blocks" ON public.blocks;
15
+
16
+ -- Ensure the canonical policies are in place (they should be, but good to be safe).
17
+ -- The canonical policies are:
18
+ -- SELECT: "blocks_authenticated_comprehensive_select" (from 20251127110000_fix_blocks_visibility_for_missing_profiles.sql)
19
+ -- INSERT: "blocks_admin_writer_can_insert" (from 20251126133000_fix_blocks_rls.sql)
20
+ -- UPDATE: "blocks_admin_writer_can_update" (from 20251126133000_fix_blocks_rls.sql)
21
+ -- DELETE: "blocks_admin_writer_can_delete" (from 20251126133000_fix_blocks_rls.sql)
22
+
23
+ -- Note: "blocks_anon_can_read_published_blocks" is also a valid policy for anon users.
24
+
25
+
26
+ -- ============================================================
27
+ -- 2. Fix Duplicate Policies on public.media
28
+ -- ============================================================
29
+
30
+ -- Drop the specific "admin/writer" read policy, as "media_public_can_read" covers everyone.
31
+ DROP POLICY IF EXISTS "media_admin_writer_can_read" ON public.media;
32
+
33
+ -- Ensure "media_public_can_read" exists (it should, from 20250526183746_fix_media_select_rls_v12.sql)
34
+ -- If for some reason it's missing, we can recreate it, but usually dropping the duplicate is enough.
35
+
36
+ COMMIT;