@nextblock-cms/db 0.2.8 → 0.2.10

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.
Files changed (86) hide show
  1. package/lib/supabase/client.d.ts +9 -0
  2. package/lib/supabase/middleware.d.ts +2 -0
  3. package/lib/supabase/server.d.ts +7 -0
  4. package/lib/supabase/ssg-client.d.ts +2 -0
  5. package/lib/supabase/types.d.ts +635 -0
  6. package/package.json +3 -13
  7. package/supabase/config.toml +0 -319
  8. package/supabase/migrations/20250513194738_setup_roles_and_profiles.sql +0 -41
  9. package/supabase/migrations/20250513194910_auto_create_profile_trigger.sql +0 -48
  10. package/supabase/migrations/20250513194916_rls_for_profiles.sql +0 -85
  11. package/supabase/migrations/20250514125634_fix_recursive_rls_policies.sql +0 -51
  12. package/supabase/migrations/20250514143016_setup_languages_table.sql +0 -66
  13. package/supabase/migrations/20250514171549_create_pages_table.sql +0 -73
  14. package/supabase/migrations/20250514171550_create_posts_table.sql +0 -61
  15. package/supabase/migrations/20250514171552_create_media_table.sql +0 -45
  16. package/supabase/migrations/20250514171553_create_blocks_table.sql +0 -54
  17. package/supabase/migrations/20250514171615_create_navigation_table.sql +0 -56
  18. package/supabase/migrations/20250514171627_rls_policies_for_content_tables.sql +0 -70
  19. package/supabase/migrations/20250515194800_add_translation_group_id.sql +0 -39
  20. package/supabase/migrations/20250520171900_add_translation_group_to_nav_items.sql +0 -21
  21. package/supabase/migrations/20250521143933_seed_homepage_and_nav.sql +0 -64
  22. package/supabase/migrations/20250523145833_add_feature_image_to_posts.sql +0 -8
  23. package/supabase/migrations/20250523151737_add_rls_to_media_table.sql +0 -18
  24. package/supabase/migrations/20250526110400_add_image_dimensions_to_media.sql +0 -14
  25. package/supabase/migrations/20250526153321_optimize_rls_policies.sql +0 -188
  26. package/supabase/migrations/20250526172513_resolve_select_policy_overlaps.sql +0 -96
  27. package/supabase/migrations/20250526172853_resolve_remaining_rls_v5.sql +0 -107
  28. package/supabase/migrations/20250526173538_finalize_rls_cleanup_v7.sql +0 -110
  29. package/supabase/migrations/20250526174710_separate_write_policies_v8.sql +0 -147
  30. package/supabase/migrations/20250526175359_fix_languages_select_rls_v9.sql +0 -81
  31. package/supabase/migrations/20250526182940_fix_nav_read_policy_v10.sql +0 -27
  32. package/supabase/migrations/20250526183239_fix_posts_read_rls_v11.sql +0 -59
  33. package/supabase/migrations/20250526183746_fix_media_select_rls_v12.sql +0 -39
  34. package/supabase/migrations/20250526184205_consolidate_content_read_rls_v13.sql +0 -61
  35. package/supabase/migrations/20250526185854_optimize_indexes.sql +0 -47
  36. package/supabase/migrations/20250526190900_debug_blocks_rls.sql +0 -56
  37. package/supabase/migrations/20250526191217_consolidate_blocks_select_rls.sql +0 -79
  38. package/supabase/migrations/20250526192822_fix_handle_languages_update_search_path.sql +0 -32
  39. package/supabase/migrations/20250527150500_fix_blocks_rls_policy.sql +0 -54
  40. package/supabase/migrations/20250602150602_add_blur_data_url_to_media.sql +0 -4
  41. package/supabase/migrations/20250602150959_add_variants_to_media.sql +0 -4
  42. package/supabase/migrations/20250618124000_create_get_my_claim_function.sql +0 -5
  43. package/supabase/migrations/20250618124100_create_logos_table.sql +0 -29
  44. package/supabase/migrations/20250618130000_fix_linter_warnings.sql +0 -58
  45. package/supabase/migrations/20250618151500_revert_storage_rls.sql +0 -6
  46. package/supabase/migrations/20250619084800_reinstate_storage_rls.sql +0 -13
  47. package/supabase/migrations/20250619092430_widen_logo_insert_policy.sql +0 -6
  48. package/supabase/migrations/20250619093122_fix_get_my_claim_volatility.sql +0 -5
  49. package/supabase/migrations/20250619104249_consolidated_logo_rls_fix.sql +0 -56
  50. package/supabase/migrations/20250619110700_fix_logo_rls_again.sql +0 -59
  51. package/supabase/migrations/20250619113200_add_file_path_to_media.sql +0 -4
  52. package/supabase/migrations/20250619124100_fix_rls_performance_warnings.sql +0 -74
  53. package/supabase/migrations/20250619195500_create_site_settings_table.sql +0 -28
  54. package/supabase/migrations/20250619201500_add_anon_read_to_site_settings.sql +0 -7
  55. package/supabase/migrations/20250619202000_add_is_active_to_languages.sql +0 -5
  56. package/supabase/migrations/20250620085700_fix_site_settings_write_rls.sql +0 -27
  57. package/supabase/migrations/20250620095500_fix_profiles_read_rls.sql +0 -11
  58. package/supabase/migrations/20250620100000_use_security_definer_for_rls.sql +0 -39
  59. package/supabase/migrations/20250620130000_add_public_read_to_logos.sql +0 -4
  60. package/supabase/migrations/20250708091700_create_translations_table.sql +0 -55
  61. package/supabase/migrations/20250708093403_seed_translations_table.sql +0 -20
  62. package/supabase/migrations/20250708110600_fix_translations_rls_policies.sql +0 -11
  63. package/supabase/migrations/20250708112300_add_new_translations.sql +0 -9
  64. package/supabase/migrations/20250709120000_create_revisions_tables.sql +0 -109
  65. package/supabase/migrations/20251001113000_add_folder_to_media.sql +0 -14
  66. package/supabase/migrations/20251112113736_fix_search_path_functions.sql +0 -74
  67. package/supabase/migrations/20251112124444_fix_rls_performance.sql +0 -63
  68. package/supabase/migrations/20251112125935_fix_combined_policies.sql +0 -194
  69. package/supabase/migrations/20251112132146_fix_foreign_key_indexes.sql +0 -21
  70. package/supabase/migrations/20251112132525_cleanup_unused_indexes.sql +0 -10
  71. package/supabase/migrations/20251112132822_fix_final_indexes.sql +0 -14
  72. package/supabase/migrations/20251112140000_scaffold_foundational_content.sql +0 -95
  73. package/supabase/migrations/20251112141000_seed_homepage_blocks.sql +0 -656
  74. package/supabase/migrations/20251112142000_seed_how_it_works_post_blocks.sql +0 -100
  75. package/supabase/migrations/20251112143000_seed_additional_translations.sql +0 -102
  76. package/supabase/migrations/20251112145000_grant_public_schema_usage.sql +0 -6
  77. package/supabase/migrations/20251112145500_grant_select_on_public_tables.sql +0 -19
  78. package/supabase/migrations/20251117093000_add_admin_created_flag.sql +0 -21
  79. package/supabase/migrations/20251117103000_relax_profile_username_constraint.sql +0 -6
  80. package/supabase/migrations/20251117110000_relax_profiles_site_settings_rls_for_signup.sql +0 -20
  81. package/supabase/migrations/20251117112000_fix_handle_new_user_role_enum.sql +0 -45
  82. package/supabase/migrations/20251117113000_cleanup_rls_duplicates.sql +0 -20
  83. package/supabase/migrations/20251117200000_media_service_role_insert.sql +0 -14
  84. package/supabase/migrations/20251117201500_media_service_role_select.sql +0 -11
  85. package/supabase/migrations/20251117203000_media_admin_writer_select.sql +0 -11
  86. package/supabase/migrations/20251117204500_fix_media_permissions.sql +0 -43
@@ -1,39 +0,0 @@
1
- -- supabase/migrations/YYYYMMDDHHMMSS_fix_media_select_rls_v12.sql
2
-
3
- BEGIN;
4
-
5
- -- == MEDIA ==
6
-
7
- -- Drop the existing specific SELECT policy for the 'USER' role,
8
- -- as we will replace it with a broader one for all authenticated users.
9
- DROP POLICY IF EXISTS "media_user_role_can_read" ON public.media;
10
- -- Drop any older variations that might exist from previous attempts if their names were different
11
- DROP POLICY IF EXISTS "media_user_can_read" ON public.media;
12
- DROP POLICY IF EXISTS "media_readable_by_anon_and_non_privileged_users" ON public.media;
13
-
14
-
15
- -- Policy for anonymous users to read media (ensure this is in place and correct)
16
- -- This policy allows anyone to read any media record if no other policy restricts them.
17
- -- This is generally desired if your R2 bucket URLs are guessable or if images are meant to be public.
18
- DROP POLICY IF EXISTS "media_anon_can_read" ON public.media; -- From _v6/_v7 logic
19
- DROP POLICY IF EXISTS "media_is_publicly_readable_by_all" ON public.media; -- From _v8 logic
20
- DROP POLICY IF EXISTS "media_is_readable_by_all" ON public.media; -- Older name
21
- DROP POLICY IF EXISTS "media_are_publicly_readable" ON public.media; -- Older name
22
-
23
- CREATE POLICY "media_public_can_read" ON public.media
24
- FOR SELECT
25
- USING (true); -- Allows both 'anon' and 'authenticated' roles to read by default
26
- COMMENT ON POLICY "media_public_can_read" ON public.media IS 'All users (anonymous and authenticated) can read media records. This is the general read access.';
27
-
28
-
29
- -- The admin/writer management policies for INSERT, UPDATE, DELETE remain as they are (write-only).
30
- -- e.g., "media_admin_writer_can_insert", "media_admin_writer_can_update", "media_admin_writer_can_delete"
31
- -- These do NOT provide SELECT access.
32
-
33
- -- With the "media_public_can_read" policy USING (true), all authenticated users (USER, WRITER, ADMIN)
34
- -- will have SELECT access. This should resolve the error when fetching feature_image_id details
35
- -- and allow images to be displayed.
36
- -- This will also mean the linter should not complain about "multiple permissive policies for authenticated SELECT"
37
- -- because the management policies are write-only, and there's now one clear "public read" policy for SELECT.
38
-
39
- COMMIT;
@@ -1,61 +0,0 @@
1
- -- supabase/migrations/YYYYMMDDHHMMSS_consolidate_content_read_rls_v13.sql
2
-
3
- BEGIN;
4
-
5
- -- == POSTS ==
6
-
7
- -- Drop the existing separate SELECT policies for authenticated users on posts
8
- DROP POLICY IF EXISTS "posts_authenticated_can_read_published" ON public.posts;
9
- DROP POLICY IF EXISTS "posts_authors_can_read_own_drafts" ON public.posts;
10
- -- Drop any older variations that might exist
11
- DROP POLICY IF EXISTS "posts_user_role_can_read" ON public.posts;
12
- DROP POLICY IF EXISTS "posts_user_authenticated_access" ON public.posts;
13
- DROP POLICY IF EXISTS "posts_authenticated_access" ON public.posts;
14
-
15
-
16
- -- Create a single, comprehensive SELECT policy for authenticated users on posts
17
- CREATE POLICY "posts_authenticated_comprehensive_read" ON public.posts
18
- FOR SELECT
19
- TO authenticated
20
- USING (
21
- -- Condition 1: Any authenticated user can read PUBLISHED posts
22
- (status = 'published' AND (published_at IS NULL OR published_at <= now())) OR
23
- -- Condition 2: Authenticated authors can read their OWN NON-PUBLISHED posts
24
- (author_id = (SELECT auth.uid()) AND status <> 'published') OR
25
- -- Condition 3: ADMINs and WRITERs can read ALL posts (any status)
26
- (public.get_current_user_role() IN ('ADMIN', 'WRITER'))
27
- );
28
- COMMENT ON POLICY "posts_authenticated_comprehensive_read" ON public.posts IS 'Handles all SELECT scenarios for authenticated users: published for all, own drafts for authors, and all posts for admins/writers.';
29
-
30
- -- "posts_anon_can_read_published" (FOR SELECT TO anon) is assumed to be correct and in place.
31
- -- Admin/Writer management policies (FOR INSERT, UPDATE, DELETE) are assumed to be correct and in place.
32
-
33
-
34
- -- == PAGES ==
35
-
36
- -- Drop the existing separate SELECT policies for authenticated users on pages
37
- DROP POLICY IF EXISTS "pages_authenticated_can_read_published" ON public.pages; -- If created in a previous step
38
- DROP POLICY IF EXISTS "pages_authors_can_read_own_drafts" ON public.pages; -- If created
39
- DROP POLICY IF EXISTS "pages_user_role_can_read" ON public.pages;
40
- DROP POLICY IF EXISTS "pages_user_authenticated_access" ON public.pages;
41
- DROP POLICY IF EXISTS "pages_authenticated_access" ON public.pages;
42
-
43
-
44
- -- Create a single, comprehensive SELECT policy for authenticated users on pages
45
- CREATE POLICY "pages_authenticated_comprehensive_read" ON public.pages
46
- FOR SELECT
47
- TO authenticated
48
- USING (
49
- -- Condition 1: Any authenticated user can read PUBLISHED pages
50
- (status = 'published') OR
51
- -- Condition 2: Authenticated authors can read their OWN NON-PUBLISHED pages
52
- (author_id = (SELECT auth.uid()) AND status <> 'published') OR
53
- -- Condition 3: ADMINs and WRITERs can read ALL pages (any status)
54
- (public.get_current_user_role() IN ('ADMIN', 'WRITER'))
55
- );
56
- COMMENT ON POLICY "pages_authenticated_comprehensive_read" ON public.pages IS 'Handles all SELECT scenarios for authenticated users: published for all, own drafts for authors, and all pages for admins/writers.';
57
-
58
- -- "pages_anon_can_read_published" (FOR SELECT TO anon) is assumed to be correct and in place.
59
- -- Admin/Writer management policies (FOR INSERT, UPDATE, DELETE) are assumed to be correct and in place.
60
-
61
- COMMIT;
@@ -1,47 +0,0 @@
1
- -- supabase/migrations/YYYYMMDDHHMMSS_optimize_indexes.sql
2
- -- (Replace YYYYMMDDHHMMSS with the actual timestamp of this migration file, e.g., 20250526185854)
3
-
4
- BEGIN;
5
-
6
- -- Add indexes for foreign keys in the 'public.blocks' table
7
- CREATE INDEX IF NOT EXISTS idx_blocks_language_id ON public.blocks(language_id);
8
- COMMENT ON INDEX public.idx_blocks_language_id IS 'Index for the foreign key blocks_language_id_fkey on public.blocks.';
9
-
10
- CREATE INDEX IF NOT EXISTS idx_blocks_page_id ON public.blocks(page_id);
11
- COMMENT ON INDEX public.idx_blocks_page_id IS 'Index for the foreign key blocks_page_id_fkey on public.blocks.';
12
-
13
- CREATE INDEX IF NOT EXISTS idx_blocks_post_id ON public.blocks(post_id);
14
- COMMENT ON INDEX public.idx_blocks_post_id IS 'Index for the foreign key blocks_post_id_fkey on public.blocks.';
15
-
16
- -- Add index for foreign key in the 'public.media' table
17
- CREATE INDEX IF NOT EXISTS idx_media_uploader_id ON public.media(uploader_id);
18
- COMMENT ON INDEX public.idx_media_uploader_id IS 'Index for the foreign key media_uploader_id_fkey on public.media.';
19
-
20
- -- Add indexes for foreign keys in the 'public.navigation_items' table
21
- CREATE INDEX IF NOT EXISTS idx_navigation_items_language_id ON public.navigation_items(language_id);
22
- COMMENT ON INDEX public.idx_navigation_items_language_id IS 'Index for the foreign key navigation_items_language_id_fkey on public.navigation_items.';
23
-
24
- CREATE INDEX IF NOT EXISTS idx_navigation_items_page_id ON public.navigation_items(page_id);
25
- COMMENT ON INDEX public.idx_navigation_items_page_id IS 'Index for the foreign key navigation_items_page_id_fkey on public.navigation_items.';
26
-
27
- CREATE INDEX IF NOT EXISTS idx_navigation_items_parent_id ON public.navigation_items(parent_id);
28
- COMMENT ON INDEX public.idx_navigation_items_parent_id IS 'Index for the foreign key navigation_items_parent_id_fkey on public.navigation_items.';
29
-
30
- -- Add index for foreign key in the 'public.pages' table
31
- CREATE INDEX IF NOT EXISTS idx_pages_author_id ON public.pages(author_id);
32
- COMMENT ON INDEX public.idx_pages_author_id IS 'Index for the foreign key pages_author_id_fkey on public.pages.';
33
-
34
- -- Add indexes for foreign keys in the 'public.posts' table
35
- CREATE INDEX IF NOT EXISTS idx_posts_feature_image_id ON public.posts(feature_image_id);
36
- COMMENT ON INDEX public.idx_posts_feature_image_id IS 'Index for the foreign key fk_feature_image on public.posts.';
37
-
38
- CREATE INDEX IF NOT EXISTS idx_posts_author_id ON public.posts(author_id);
39
- COMMENT ON INDEX public.idx_posts_author_id IS 'Index for the foreign key posts_author_id_fkey on public.posts.';
40
-
41
- -- Remove unused index in 'public.navigation_items' table
42
- -- The linter identified 'idx_navigation_items_translation_group_id' as unused.
43
- -- This index was created in migration 20250520171900_add_translation_group_to_nav_items.sql
44
- DROP INDEX IF EXISTS public.idx_navigation_items_translation_group_id;
45
- -- The COMMENT ON for the dropped index has been removed to prevent the error.
46
-
47
- COMMIT;
@@ -1,56 +0,0 @@
1
- -- supabase/migrations/YYYYMMDDHHMMSS_debug_blocks_rls.sql
2
-
3
- BEGIN;
4
-
5
- -- Drop the more specific separated write policies for blocks from v8
6
- DROP POLICY IF EXISTS "blocks_admin_writer_can_insert" ON public.blocks;
7
- DROP POLICY IF EXISTS "blocks_admin_writer_can_update" ON public.blocks;
8
- DROP POLICY IF EXISTS "blocks_admin_writer_can_delete" ON public.blocks;
9
-
10
- -- Reinstate a broad "FOR ALL" policy for ADMINS and WRITERS on blocks
11
- -- This is similar to what was effectively in place before v8 for admin/writer management.
12
- CREATE POLICY "blocks_admin_writer_management_reinstated" ON public.blocks
13
- FOR ALL -- Covers SELECT, INSERT, UPDATE, DELETE
14
- TO authenticated
15
- USING (public.get_current_user_role() IN ('ADMIN', 'WRITER'))
16
- WITH CHECK (public.get_current_user_role() IN ('ADMIN', 'WRITER'));
17
-
18
- COMMENT ON POLICY "blocks_admin_writer_management_reinstated" ON public.blocks IS 'Reinstated FOR ALL policy for ADMIN/WRITER to manage blocks. This may cause linter warnings for SELECT overlaps if other SELECT policies exist but is for debugging block creation.';
19
-
20
- -- Ensure SELECT policies for other roles are still in place and don't conflict in a breaking way.
21
- -- The policies "blocks_anon_can_read_published" and "blocks_user_role_can_read_published_parents" (from v5/v7) handle reads for anon and USERs.
22
- -- "blocks_anon_can_read_published" (FOR SELECT TO anon USING (...))
23
- -- "blocks_user_role_can_read_published_parents" (FOR SELECT TO authenticated USING (public.get_current_user_role() = 'USER' AND ...))
24
-
25
- -- Let's re-assert the anon read policy to be sure it's correct, as it was defined early on.
26
- DROP POLICY IF EXISTS "blocks_are_readable_if_parent_is_published" ON public.blocks; -- Original name from 20250514171553
27
- DROP POLICY IF EXISTS "blocks_anon_can_read_published" ON public.blocks; -- Renamed in 20250526153321
28
-
29
- CREATE POLICY "blocks_anon_can_read_published_content" ON public.blocks
30
- FOR SELECT
31
- TO anon
32
- USING (
33
- (page_id IS NOT NULL AND EXISTS(SELECT 1 FROM public.pages p WHERE p.id = blocks.page_id AND p.status = 'published')) OR
34
- (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())))
35
- );
36
- COMMENT ON POLICY "blocks_anon_can_read_published_content" ON public.blocks IS 'Anonymous users can read blocks of published parent pages/posts.';
37
-
38
-
39
- -- Re-assert the USER role SELECT policy, ensuring it only applies to USER.
40
- DROP POLICY IF EXISTS "blocks_authenticated_user_access" ON public.blocks; -- From v4
41
- DROP POLICY IF EXISTS "blocks_user_role_can_read_published_parents" ON public.blocks; -- From v5/v7
42
-
43
- CREATE POLICY "blocks_auth_users_can_read_published_parents" ON public.blocks
44
- FOR SELECT
45
- TO authenticated
46
- USING (
47
- (public.get_current_user_role() = 'USER') AND -- Crucially, only applies to 'USER' role
48
- (
49
- (page_id IS NOT NULL AND EXISTS(SELECT 1 FROM public.pages p WHERE p.id = blocks.page_id AND p.status = 'published')) OR
50
- (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())))
51
- )
52
- );
53
- COMMENT ON POLICY "blocks_auth_users_can_read_published_parents" ON public.blocks IS 'Authenticated USERS can read blocks of published parents. Admin/Writer SELECT is handled by their management policy.';
54
-
55
-
56
- COMMIT;
@@ -1,79 +0,0 @@
1
- -- supabase/migrations/YYYYMMDDHHMMSS_consolidate_blocks_select_rls.sql
2
- -- (Replace YYYYMMDDHHMMSS with the actual timestamp of this migration file)
3
-
4
- BEGIN;
5
-
6
- -- Drop existing policies for 'public.blocks' that will be replaced or refined.
7
- -- This includes the broad "FOR ALL" policy and the specific "USER" SELECT policy
8
- -- created in the previous debug migration.
9
- DROP POLICY IF EXISTS "blocks_admin_writer_management_reinstated" ON public.blocks;
10
- DROP POLICY IF EXISTS "blocks_auth_users_can_read_published_parents" ON public.blocks;
11
-
12
- -- The "blocks_anon_can_read_published_content" policy can remain as it targets 'anon'
13
- -- and does not conflict with 'authenticated' role policies for the linter's warning.
14
- -- However, if you wish to have a completely clean slate before adding the consolidated one,
15
- -- you can drop and re-add it. For this exercise, we'll assume it's fine and already specific.
16
- -- If it was named "blocks_anon_can_read_published" from 20250526153321_optimize_rls_policies.sql:
17
- -- DROP POLICY IF EXISTS "blocks_anon_can_read_published" ON public.blocks;
18
- -- Or if it was "blocks_are_readable_if_parent_is_published" from 20250514171553_create_blocks_table.sql:
19
- -- DROP POLICY IF EXISTS "blocks_are_readable_if_parent_is_published" ON public.blocks;
20
- -- Re-creating the anon policy for clarity and to ensure it's exactly as needed:
21
- DROP POLICY IF EXISTS "blocks_anon_can_read_published_content" ON public.blocks; -- From debug migration
22
- DROP POLICY IF EXISTS "blocks_anon_can_read_published" ON public.blocks; -- From optimize_rls_policies
23
- DROP POLICY IF EXISTS "blocks_are_readable_if_parent_is_published" ON public.blocks; -- From initial table creation
24
-
25
- CREATE POLICY "blocks_anon_can_read_published_blocks" ON public.blocks
26
- FOR SELECT
27
- TO anon
28
- USING (
29
- (page_id IS NOT NULL AND EXISTS(SELECT 1 FROM public.pages p WHERE p.id = blocks.page_id AND p.status = 'published')) OR
30
- (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())))
31
- );
32
- COMMENT ON POLICY "blocks_anon_can_read_published_blocks" ON public.blocks IS 'Anonymous users can read blocks of published parent content.';
33
-
34
-
35
- -- Create a single, comprehensive SELECT policy for ALL authenticated users on blocks
36
- CREATE POLICY "blocks_authenticated_comprehensive_select" ON public.blocks
37
- FOR SELECT
38
- TO authenticated
39
- USING (
40
- (
41
- -- Condition for ADMIN or WRITER: they can read ALL blocks
42
- (SELECT public.get_current_user_role()) IN ('ADMIN', 'WRITER')
43
- ) OR
44
- (
45
- -- Condition for USER: they can read blocks of published parents
46
- ((SELECT public.get_current_user_role()) = 'USER') AND
47
- (
48
- (page_id IS NOT NULL AND EXISTS(SELECT 1 FROM public.pages p WHERE p.id = blocks.page_id AND p.status = 'published')) OR
49
- (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())))
50
- )
51
- )
52
- );
53
- COMMENT ON POLICY "blocks_authenticated_comprehensive_select" ON public.blocks IS 'Comprehensive SELECT policy for authenticated users on the blocks table, differentiating access by role (ADMIN/WRITER see all, USER sees blocks of published parents).';
54
-
55
-
56
- -- Re-add the specific management policies for INSERT, UPDATE, DELETE for ADMIN/WRITER.
57
- -- These only have WITH CHECK (for INSERT/UPDATE) or USING (for DELETE/UPDATE) based on role.
58
- -- These were the ones created in 20250526174710_separate_write_policies_v8.sql and are fine.
59
-
60
- CREATE POLICY "blocks_admin_writer_can_insert" ON public.blocks
61
- FOR INSERT
62
- TO authenticated
63
- WITH CHECK ((SELECT public.get_current_user_role()) IN ('ADMIN', 'WRITER'));
64
- COMMENT ON POLICY "blocks_admin_writer_can_insert" ON public.blocks IS 'Admins/Writers can insert blocks.';
65
-
66
- CREATE POLICY "blocks_admin_writer_can_update" ON public.blocks
67
- FOR UPDATE
68
- TO authenticated
69
- USING ((SELECT public.get_current_user_role()) IN ('ADMIN', 'WRITER')) -- Who can be targeted by an update
70
- WITH CHECK ((SELECT public.get_current_user_role()) IN ('ADMIN', 'WRITER')); -- What rows can be created/modified by them
71
- COMMENT ON POLICY "blocks_admin_writer_can_update" ON public.blocks IS 'Admins/Writers can update blocks.';
72
-
73
- CREATE POLICY "blocks_admin_writer_can_delete" ON public.blocks
74
- FOR DELETE
75
- TO authenticated
76
- USING ((SELECT public.get_current_user_role()) IN ('ADMIN', 'WRITER'));
77
- COMMENT ON POLICY "blocks_admin_writer_can_delete" ON public.blocks IS 'Admins/Writers can delete blocks.';
78
-
79
- COMMIT;
@@ -1,32 +0,0 @@
1
- -- supabase/migrations/YYYYMMDDHHMMSS_fix_handle_languages_update_search_path.sql
2
- -- (Replace YYYYMMDDHHMMSS with the actual timestamp of this migration file)
3
-
4
- BEGIN;
5
-
6
- -- Step 1: Drop the existing trigger that depends on the function.
7
- DROP TRIGGER IF EXISTS on_languages_update ON public.languages;
8
-
9
- -- Step 2: Now it's safe to drop and recreate the function.
10
- DROP FUNCTION IF EXISTS public.handle_languages_update();
11
-
12
- CREATE OR REPLACE FUNCTION public.handle_languages_update()
13
- RETURNS TRIGGER
14
- LANGUAGE plpgsql
15
- SECURITY DEFINER -- Explicitly set security context
16
- SET search_path = public -- Explicitly set search_path
17
- AS $$
18
- BEGIN
19
- NEW.updated_at = now();
20
- RETURN NEW;
21
- END;
22
- $$;
23
-
24
- COMMENT ON FUNCTION public.handle_languages_update() IS 'Sets updated_at timestamp on language update. Includes explicit search_path and security definer.';
25
-
26
- -- Step 3: Re-create the trigger to use the updated function.
27
- CREATE TRIGGER on_languages_update
28
- BEFORE UPDATE ON public.languages
29
- FOR EACH ROW
30
- EXECUTE PROCEDURE public.handle_languages_update();
31
-
32
- COMMIT;
@@ -1,54 +0,0 @@
1
- -- Fix blocks RLS policy to resolve joined query issues
2
- -- Replace public.get_current_user_role() with direct EXISTS queries
3
-
4
- BEGIN;
5
-
6
- -- Drop the existing comprehensive SELECT policy that uses the problematic function
7
- DROP POLICY IF EXISTS "blocks_authenticated_comprehensive_select" ON public.blocks;
8
-
9
- -- Drop the existing management policies that use the problematic function
10
- DROP POLICY IF EXISTS "blocks_admin_writer_can_insert" ON public.blocks;
11
- DROP POLICY IF EXISTS "blocks_admin_writer_can_update" ON public.blocks;
12
- DROP POLICY IF EXISTS "blocks_admin_writer_can_delete" ON public.blocks;
13
-
14
- -- Create a new comprehensive SELECT policy using direct EXISTS queries
15
- CREATE POLICY "blocks_authenticated_comprehensive_select" ON public.blocks
16
- FOR SELECT
17
- TO authenticated
18
- USING (
19
- (
20
- -- Condition for ADMIN or WRITER: they can read ALL blocks
21
- EXISTS (SELECT 1 FROM public.profiles WHERE id = auth.uid() AND role IN ('ADMIN', 'WRITER'))
22
- ) OR
23
- (
24
- -- Condition for USER: they can read blocks of published parents
25
- EXISTS (SELECT 1 FROM public.profiles WHERE id = auth.uid() AND role = 'USER') AND
26
- (
27
- (page_id IS NOT NULL AND EXISTS(SELECT 1 FROM public.pages p WHERE p.id = blocks.page_id AND p.status = 'published')) OR
28
- (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())))
29
- )
30
- )
31
- );
32
- COMMENT ON POLICY "blocks_authenticated_comprehensive_select" ON public.blocks IS 'Comprehensive SELECT policy for authenticated users on the blocks table, differentiating access by role (ADMIN/WRITER see all, USER sees blocks of published parents). Uses direct EXISTS queries to avoid function call issues in joined queries.';
33
-
34
- -- Re-create the management policies using direct EXISTS queries
35
- CREATE POLICY "blocks_admin_writer_can_insert" ON public.blocks
36
- FOR INSERT
37
- TO authenticated
38
- WITH CHECK (EXISTS (SELECT 1 FROM public.profiles WHERE id = auth.uid() AND role IN ('ADMIN', 'WRITER')));
39
- COMMENT ON POLICY "blocks_admin_writer_can_insert" ON public.blocks IS 'Admins/Writers can insert blocks.';
40
-
41
- CREATE POLICY "blocks_admin_writer_can_update" ON public.blocks
42
- FOR UPDATE
43
- TO authenticated
44
- USING (EXISTS (SELECT 1 FROM public.profiles WHERE id = auth.uid() AND role IN ('ADMIN', 'WRITER'))) -- Who can be targeted by an update
45
- WITH CHECK (EXISTS (SELECT 1 FROM public.profiles WHERE id = auth.uid() AND role IN ('ADMIN', 'WRITER'))); -- What rows can be created/modified by them
46
- COMMENT ON POLICY "blocks_admin_writer_can_update" ON public.blocks IS 'Admins/Writers can update blocks.';
47
-
48
- CREATE POLICY "blocks_admin_writer_can_delete" ON public.blocks
49
- FOR DELETE
50
- TO authenticated
51
- USING (EXISTS (SELECT 1 FROM public.profiles WHERE id = auth.uid() AND role IN ('ADMIN', 'WRITER')));
52
- COMMENT ON POLICY "blocks_admin_writer_can_delete" ON public.blocks IS 'Admins/Writers can delete blocks.';
53
-
54
- COMMIT;
@@ -1,4 +0,0 @@
1
- ALTER TABLE public.media
2
- ADD COLUMN blur_data_url TEXT NULL;
3
-
4
- COMMENT ON COLUMN public.media.blur_data_url IS 'Stores the base64 encoded string for image blur placeholders.';
@@ -1,4 +0,0 @@
1
- ALTER TABLE public.media
2
- ADD COLUMN variants JSONB NULL;
3
-
4
- COMMENT ON COLUMN public.media.variants IS 'Stores an array of image variant objects, including different sizes and formats.';
@@ -1,5 +0,0 @@
1
- CREATE OR REPLACE FUNCTION get_my_claim(claim TEXT)
2
- RETURNS JSONB AS $$
3
- SET search_path = '';
4
- SELECT COALESCE(current_setting('request.jwt.claims', true)::JSONB ->> claim, NULL)::JSONB
5
- $$ LANGUAGE SQL STABLE;
@@ -1,29 +0,0 @@
1
- CREATE TABLE public.logos (
2
- id uuid NOT NULL DEFAULT gen_random_uuid(),
3
- created_at timestamp with time zone NOT NULL DEFAULT now(),
4
- name text NOT NULL,
5
- media_id uuid,
6
- CONSTRAINT logos_pkey PRIMARY KEY (id),
7
- CONSTRAINT logos_media_id_fkey FOREIGN KEY (media_id) REFERENCES public.media(id) ON DELETE SET NULL
8
- );
9
-
10
- COMMENT ON TABLE public.logos IS 'Stores company and brand logos.';
11
- COMMENT ON COLUMN public.logos.name IS 'The name of the brand or company for the logo.';
12
- COMMENT ON COLUMN public.logos.media_id IS 'Foreign key to the media table for the logo image.';
13
-
14
- GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.logos TO authenticated;
15
-
16
- ALTER TABLE public.logos ENABLE ROW LEVEL SECURITY;
17
-
18
- CREATE POLICY "Allow read access for authenticated users on logos"
19
- ON public.logos
20
- FOR SELECT
21
- TO authenticated
22
- USING (true);
23
-
24
- CREATE POLICY "Allow admin users to manage logos"
25
- ON public.logos
26
- FOR ALL
27
- TO authenticated
28
- USING (((SELECT get_my_claim('user_role'::text)) = '"admin"'::jsonb))
29
- WITH CHECK (((SELECT get_my_claim('user_role'::text)) = '"admin"'::jsonb));
@@ -1,58 +0,0 @@
1
- -- Fix multiple permissive policies on logos table
2
- DROP POLICY IF EXISTS "Allow admin users to manage logos" ON public.logos;
3
- DROP POLICY IF EXISTS "Allow read access for authenticated users on logos" ON public.logos;
4
-
5
- CREATE POLICY "Allow read access for authenticated users on logos"
6
- ON public.logos
7
- FOR SELECT
8
- TO authenticated
9
- USING (true);
10
-
11
- CREATE POLICY "Allow admin users to insert logos"
12
- ON public.logos
13
- FOR INSERT TO authenticated
14
- WITH CHECK ((get_my_claim('user_role'::text) = '"admin"'::jsonb));
15
-
16
- CREATE POLICY "Allow admin users to update logos"
17
- ON public.logos
18
- FOR UPDATE TO authenticated
19
- USING ((get_my_claim('user_role'::text) = '"admin"'::jsonb))
20
- WITH CHECK ((get_my_claim('user_role'::text) = '"admin"'::jsonb));
21
-
22
- CREATE POLICY "Allow admin users to delete logos"
23
- ON public.logos
24
- FOR DELETE TO authenticated
25
- USING ((get_my_claim('user_role'::text) = '"admin"'::jsonb));
26
-
27
- -- Fix mutable search path for get_my_claim
28
- CREATE OR REPLACE FUNCTION get_my_claim(claim TEXT)
29
- RETURNS JSONB AS $$
30
- SET search_path = '';
31
- SELECT COALESCE(current_setting('request.jwt.claims', true)::JSONB ->> claim, NULL)::JSONB
32
- $$ LANGUAGE SQL STABLE;
33
-
34
- -- Optimize RLS policies on blocks table
35
- DROP POLICY IF EXISTS "blocks_are_readable_if_parent_is_published" ON public.blocks;
36
- DROP POLICY IF EXISTS "admins_and_writers_can_manage_blocks" ON public.blocks;
37
-
38
- CREATE POLICY "blocks_are_readable_if_parent_is_published"
39
- ON public.blocks FOR SELECT
40
- TO anon, authenticated
41
- USING (
42
- (page_id IS NOT NULL AND EXISTS (
43
- SELECT 1
44
- FROM public.pages p
45
- WHERE p.id = blocks.page_id AND p.status = 'published'
46
- )) OR
47
- (post_id IS NOT NULL AND EXISTS (
48
- SELECT 1
49
- FROM public.posts pt
50
- WHERE pt.id = blocks.post_id AND pt.status = 'published' AND (pt.published_at IS NULL OR pt.published_at <= now())
51
- ))
52
- );
53
-
54
- CREATE POLICY "admins_and_writers_can_manage_blocks"
55
- ON public.blocks FOR ALL
56
- TO authenticated
57
- USING ((SELECT get_my_claim('user_role'::text)) IN ('"admin"', '"writer"'))
58
- WITH CHECK ((SELECT get_my_claim('user_role'::text)) IN ('"admin"', '"writer"'));
@@ -1,6 +0,0 @@
1
- -- Reverts the RLS policies on storage.objects that caused the upload failure.
2
-
3
- DROP POLICY IF EXISTS "allow_authenticated_uploads" ON storage.objects;
4
- DROP POLICY IF EXISTS "allow_authenticated_select" ON storage.objects;
5
- DROP POLICY IF EXISTS "allow_authenticated_updates" ON storage.objects;
6
- DROP POLICY IF EXISTS "allow_authenticated_deletes" ON storage.objects;
@@ -1,13 +0,0 @@
1
- -- Re-enables RLS policies for storage.objects to allow authenticated uploads.
2
-
3
- -- Adds a policy allowing authenticated users to upload files
4
- CREATE POLICY "allow_authenticated_uploads" ON storage.objects FOR INSERT TO authenticated WITH CHECK (bucket_id = 'public' AND owner = auth.uid());
5
-
6
- -- Allow authenticated users to SELECT files
7
- CREATE POLICY "allow_authenticated_select" ON storage.objects FOR SELECT TO authenticated USING (bucket_id = 'public');
8
-
9
- -- Allow authenticated users to UPDATE their own files
10
- CREATE POLICY "allow_authenticated_updates" ON storage.objects FOR UPDATE TO authenticated USING (bucket_id = 'public' AND owner = auth.uid());
11
-
12
- -- Allow authenticated users to DELETE their own files
13
- CREATE POLICY "allow_authenticated_deletes" ON storage.objects FOR DELETE TO authenticated USING (bucket_id = 'public' AND owner = auth.uid());
@@ -1,6 +0,0 @@
1
- DROP POLICY IF EXISTS "Allow admins to manage logos" ON public.logos;
2
-
3
- CREATE POLICY "Allow admin and writer users to insert logos"
4
- ON public.logos
5
- FOR INSERT TO authenticated
6
- WITH CHECK ((get_my_claim('user_role'::text) IN ('"admin"'::jsonb, '"writer"'::jsonb)));
@@ -1,5 +0,0 @@
1
- CREATE OR REPLACE FUNCTION get_my_claim(claim TEXT)
2
- RETURNS JSONB AS $$
3
- SET search_path = '';
4
- SELECT COALESCE(current_setting('request.jwt.claims', true)::JSONB ->> claim, NULL)::JSONB
5
- $$ LANGUAGE SQL VOLATILE;
@@ -1,56 +0,0 @@
1
- -- Step 1: Drop all dependent policies first.
2
- DROP POLICY IF EXISTS "Allow admins to manage logos" ON public.logos;
3
- DROP POLICY IF EXISTS "Allow users to insert logos" ON public.logos;
4
- DROP POLICY IF EXISTS "Allow logo insert for writers and admins" ON public.logos;
5
- DROP POLICY IF EXISTS "Allow logo update for admins" ON public.logos;
6
- DROP POLICY IF EXISTS "Allow logo delete for admins" ON public.logos;
7
-
8
- -- Step 2: Drop the old function to avoid return type conflicts.
9
- -- Note: It's critical to drop policies before the function they depend on.
10
- DROP FUNCTION IF EXISTS get_my_claim(text) CASCADE;
11
-
12
- -- Step 3: Redefine the get_my_claim function to be more robust and return TEXT.
13
- -- This avoids JSON casting errors and type mismatches in policies.
14
- CREATE OR REPLACE FUNCTION get_my_claim(claim TEXT)
15
- RETURNS TEXT AS $$
16
- DECLARE
17
- claims jsonb;
18
- claim_value text;
19
- BEGIN
20
- -- Safely get claims, defaulting to NULL if not present or invalid JSON
21
- BEGIN
22
- claims := current_setting('request.jwt.claims', true)::jsonb;
23
- EXCEPTION
24
- WHEN invalid_text_representation THEN
25
- claims := NULL;
26
- END;
27
-
28
- -- If claims are NULL, return NULL
29
- IF claims IS NULL THEN
30
- RETURN NULL;
31
- END IF;
32
-
33
- -- Safely extract the claim value as text, removing quotes
34
- claim_value := claims ->> claim;
35
-
36
- RETURN claim_value;
37
- END;
38
- $$ LANGUAGE plpgsql VOLATILE;
39
-
40
-
41
- -- Create the new, correct policies using the updated function
42
- CREATE POLICY "Allow logo insert for authenticated users"
43
- ON public.logos
44
- FOR INSERT
45
- WITH CHECK (auth.role() = 'authenticated');
46
-
47
- CREATE POLICY "Allow logo update for authenticated users"
48
- ON public.logos
49
- FOR UPDATE
50
- USING (auth.role() = 'authenticated')
51
- WITH CHECK (auth.role() = 'authenticated');
52
-
53
- CREATE POLICY "Allow logo delete for authenticated users"
54
- ON public.logos
55
- FOR DELETE
56
- USING (auth.role() = 'authenticated');
@@ -1,59 +0,0 @@
1
- -- Step 1: Drop all dependent policies first.
2
- DROP POLICY IF EXISTS "Allow admins to manage logos" ON public.logos;
3
- DROP POLICY IF EXISTS "Allow users to insert logos" ON public.logos;
4
- DROP POLICY IF EXISTS "Allow logo insert for writers and admins" ON public.logos;
5
- DROP POLICY IF EXISTS "Allow logo update for admins" ON public.logos;
6
- DROP POLICY IF EXISTS "Allow logo delete for admins" ON public.logos;
7
- DROP POLICY IF EXISTS "Allow logo insert for authenticated users" ON public.logos;
8
- DROP POLICY IF EXISTS "Allow logo update for authenticated users" ON public.logos;
9
- DROP POLICY IF EXISTS "Allow logo delete for authenticated users" ON public.logos;
10
-
11
- -- Step 2: Drop the old function to avoid return type conflicts.
12
- -- Note: It's critical to drop policies before the function they depend on.
13
- DROP FUNCTION IF EXISTS get_my_claim(text) CASCADE;
14
-
15
- -- Step 3: Redefine the get_my_claim function to be more robust and return TEXT.
16
- -- This avoids JSON casting errors and type mismatches in policies.
17
- CREATE OR REPLACE FUNCTION get_my_claim(claim TEXT)
18
- RETURNS TEXT AS $$
19
- DECLARE
20
- claims jsonb;
21
- claim_value text;
22
- BEGIN
23
- -- Safely get claims, defaulting to NULL if not present or invalid JSON
24
- BEGIN
25
- claims := current_setting('request.jwt.claims', true)::jsonb;
26
- EXCEPTION
27
- WHEN invalid_text_representation THEN
28
- claims := NULL;
29
- END;
30
-
31
- -- If claims are NULL, return NULL
32
- IF claims IS NULL THEN
33
- RETURN NULL;
34
- END IF;
35
-
36
- -- Safely extract the claim value as text, removing quotes
37
- claim_value := claims ->> claim;
38
-
39
- RETURN claim_value;
40
- END;
41
- $$ LANGUAGE plpgsql VOLATILE;
42
-
43
-
44
- -- Create the new, correct policies using the updated function
45
- CREATE POLICY "Allow logo insert for authenticated users"
46
- ON public.logos
47
- FOR INSERT
48
- WITH CHECK (auth.role() = 'authenticated');
49
-
50
- CREATE POLICY "Allow logo update for authenticated users"
51
- ON public.logos
52
- FOR UPDATE
53
- USING (auth.role() = 'authenticated')
54
- WITH CHECK (auth.role() = 'authenticated');
55
-
56
- CREATE POLICY "Allow logo delete for authenticated users"
57
- ON public.logos
58
- FOR DELETE
59
- USING (auth.role() = 'authenticated');
@@ -1,4 +0,0 @@
1
- ALTER TABLE public.media
2
- ADD COLUMN file_path TEXT;
3
-
4
- COMMENT ON COLUMN public.media.file_path IS 'The full path to the file in the storage bucket.';