Skip to content

Commit

Permalink
fix: hasura role creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Nov 26, 2024
1 parent 623364c commit 5f0ee97
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ferry/database/sync_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,18 @@ def sync_db(tables: dict[str, pd.DataFrame], database_connect_string: str):
# TODO: we should set up some mechanism to automatically grant
# privileges... The default on the schema is not enough.
print("\nGranting privileges to hasura...")
db_session.execute(text("CREATE ROLE IF NOT EXISTS hasura;"))
db_session.execute(text("GRANT SELECT ON ALL TABLES IN SCHEMA public TO hasura;"))
db_session.execute(text("GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO hasura;"))
db_session.execute(text("""
DO
$do$
BEGIN
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'hasura') THEN
CREATE USER hasura;
END IF;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO hasura;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO hasura;
END
$do$;
"""))
print("\033[F", end="")
print("Granting privileges to hasura... ✔")

Expand Down

0 comments on commit 5f0ee97

Please sign in to comment.