This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Hasura prep command in flusher #2395
Open
Benzbeeb
wants to merge
4
commits into
master
Choose a base branch
from
prep-hasura
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,7 +125,7 @@ services: | |
image: bandchain_flusher:latest | ||
networks: | ||
bandchain: | ||
command: sh -c "sleep 30 && python main.py init bandchain test --db postgres:[email protected]:5432/postgres" | ||
command: sh -c "sleep 30 && python main.py init bandchain test --db postgres:[email protected]:5432/postgres && python main.py hasura postgrespassword --db postgres:[email protected]:5432/postgres" | ||
|
||
flusher-daemon: | ||
image: bandchain_flusher:latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import flusher.init | ||
import flusher.sync | ||
import flusher.hasura |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import click | ||
|
||
from .cli import cli | ||
|
||
from sqlalchemy import create_engine | ||
|
||
|
||
@cli.command() | ||
@click.argument("password") | ||
@click.option( | ||
"--db", | ||
help="Database URI connection string.", | ||
default="localhost:5432/postgres", | ||
show_default=True, | ||
) | ||
def hasura(password, db): | ||
engine = create_engine("postgresql+psycopg2://" + db, echo=True) | ||
|
||
engine.execute("""DROP ROLE IF EXISTS hasura;""") | ||
engine.execute(f"""CREATE USER hasura WITH PASSWORD '{password}';""") | ||
engine.execute("""CREATE EXTENSION IF NOT EXISTS pgcrypto;""") | ||
engine.execute("""CREATE SCHEMA IF NOT EXISTS hdb_catalog;""") | ||
engine.execute("""CREATE SCHEMA IF NOT EXISTS hdb_views;""") | ||
|
||
# make the user an owner of system schemas | ||
engine.execute("""ALTER SCHEMA hdb_catalog OWNER TO hasura;""") | ||
engine.execute("""ALTER SCHEMA hdb_views OWNER TO hasura;""") | ||
|
||
# grant select permissions on information_schema and pg_catalog. This is | ||
# required for hasura to query list of available tables | ||
engine.execute("""GRANT SELECT ON ALL TABLES IN SCHEMA information_schema TO hasura;""") | ||
engine.execute("""GRANT SELECT ON ALL TABLES IN SCHEMA pg_catalog TO hasura;""") | ||
|
||
# Below permissions are optional. This is dependent on what access to your | ||
# tables/schemas - you want give to hasura. If you want expose the public | ||
# schema for GraphQL query then give permissions on public schema to the | ||
# hasura user. | ||
# Be careful to use these in your production db. Consult the postgres manual or | ||
# your DBA and give appropriate permissions. | ||
|
||
# grant all privileges on all tables in the public schema. This can be customised: | ||
# For example, if you only want to use GraphQL regular queries and not mutations, | ||
# then you can set: GRANT SELECT ON ALL TABLES... | ||
engine.execute("""GRANT USAGE ON SCHEMA public TO hasura;""") | ||
engine.execute("""GRANT SELECT ON ALL TABLES IN SCHEMA public TO hasura;""") | ||
engine.execute("""GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO hasura;""") | ||
engine.execute("""GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO hasura;""") | ||
|
||
engine.execute( | ||
"""GRANT SELECT ON information_schema.table_constraints, information_schema.key_column_usage, information_schema.columns, information_schema.views, information_schema.schemata, information_schema.routines TO hasura;""" | ||
) | ||
engine.execute( | ||
"""GRANT SELECT ON pg_catalog.pg_constraint, pg_catalog.pg_class, pg_catalog.pg_namespace, pg_catalog.pg_attribute, pg_catalog.pg_proc, pg_catalog.pg_available_extensions, pg_catalog.pg_statio_all_tables, pg_catalog.pg_description TO hasura;""" | ||
) | ||
engine.execute("""ALTER ROLE hasura SET statement_timeout='5s'""") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want docker to use new user, please use the new user on hasura service too.