Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deploy/bootstrap-powersync.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ WHERE NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'powersync_role')
\gexec
ALTER ROLE powersync_role WITH REPLICATION BYPASSRLS LOGIN PASSWORD :'source_password';
GRANT USAGE ON SCHEMA public TO powersync_role;
GRANT SELECT ON TABLE public.books, public.shelves, public.tags, public.notes, public.annotations, public.bookmarks, public.book_shelves, public.book_tags, public.reading_goals, public.reading_activities, public.goal_periods, public.powersync_demo_items TO powersync_role;
GRANT SELECT ON TABLE public.books, public.shelves, public.tags, public.notes, public.annotations, public.bookmarks, public.book_shelves, public.book_tags, public.reading_timers, public.reading_goals, public.reading_activities, public.goal_periods, public.powersync_demo_items TO powersync_role;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO powersync_role;
SELECT 'CREATE PUBLICATION powersync' WHERE NOT EXISTS (SELECT 1 FROM pg_publication WHERE pubname = 'powersync')
\gexec
ALTER PUBLICATION powersync SET TABLE public.books, public.shelves, public.tags, public.notes, public.annotations, public.bookmarks, public.book_shelves, public.book_tags, public.reading_goals, public.reading_activities, public.goal_periods, public.powersync_demo_items;
ALTER PUBLICATION powersync SET TABLE public.books, public.shelves, public.tags, public.notes, public.annotations, public.bookmarks, public.book_shelves, public.book_tags, public.reading_timers, public.reading_goals, public.reading_activities, public.goal_periods, public.powersync_demo_items;
13 changes: 13 additions & 0 deletions tests/test_powersync_sync_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from pathlib import Path


Expand Down Expand Up @@ -34,3 +35,15 @@ def test_library_streams_filter_owners_and_setup_publishes_tables() -> None:
assert "file_path" not in config
assert "series_id" in config
assert "location::text AS location" in config


def test_production_publishes_and_grants_every_synced_table() -> None:
root = Path(__file__).parents[1]
config = (root / "powersync/sync-config.yaml").read_text()
bootstrap = (root / "deploy/bootstrap-powersync.sql").read_text()
tables = set(re.findall(r"\bFROM\s+(\w+)", config))
grants = bootstrap.split("GRANT SELECT ON TABLE ", 1)[1].split(" TO powersync_role;", 1)[0]
publication = bootstrap.split("ALTER PUBLICATION powersync SET TABLE ", 1)[1].split(";", 1)[0]
assert tables
assert tables <= set(re.findall(r"public\.(\w+)", grants))
assert tables <= set(re.findall(r"public\.(\w+)", publication))
Loading