Skip to content

Commit

Permalink
fix bug in non public schema in create_view
Browse files Browse the repository at this point in the history
  • Loading branch information
toluaina committed May 27, 2021
1 parent 2310aed commit 95cca20
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 40 deletions.
11 changes: 9 additions & 2 deletions pgsync/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,10 @@ def create_view(self, schema, tables, user_defined_fkey_tables):
rows[table_name]["foreign_keys"] |= set(columns)

if not rows:
return
rows.setdefault(
None,
{"primary_keys": set([]), "foreign_keys": set([])},
)

statement = sa.select(
Values(
Expand Down Expand Up @@ -612,7 +615,11 @@ def drop_view(self, schema):
# Triggers...
def create_triggers(self, schema, tables=None):
"""Create a database triggers."""
self.execute(CREATE_TRIGGER_TEMPLATE)
self.execute(
CREATE_TRIGGER_TEMPLATE.replace(
MATERIALIZED_VIEW, f"{schema}.{MATERIALIZED_VIEW}"
)
)
views = sa.inspect(self.engine).get_view_names(schema)
queries = []
for table in self.tables(schema):
Expand Down
7 changes: 5 additions & 2 deletions pgsync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def setup(self):

root = self.tree.build(self.nodes)
for node in traverse_breadth_first(root):
if node.schema != schema:
continue
tables |= set(node.relationship.through_tables)
tables |= set([node.table])
# we want to get both the parent and the child keys here
Expand All @@ -186,8 +188,9 @@ def setup(self):
if columns:
user_defined_fkey_tables.setdefault(node.table, set([]))
user_defined_fkey_tables[node.table] |= set(columns)
self.create_triggers(schema, tables=tables)
self.create_view(schema, tables, user_defined_fkey_tables)
if tables:
self.create_triggers(schema, tables=tables)
self.create_view(schema, tables, user_defined_fkey_tables)
self.create_replication_slot(self.__name)

def teardown(self, drop_view=True):
Expand Down
32 changes: 17 additions & 15 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ attrs==21.2.0
# via pytest
black==21.5b1
# via -r requirements/base.in
boto3==1.17.73
boto3==1.17.83
# via -r requirements/base.in
botocore==1.20.73
botocore==1.20.83
# via
# boto3
# s3transfer
Expand All @@ -26,11 +26,11 @@ certifi==2020.12.5
# via
# elasticsearch
# requests
cfgv==3.2.0
cfgv==3.3.0
# via pre-commit
chardet==4.0.0
# via requests
click==8.0.0
click==8.0.1
# via
# -r requirements/base.in
# black
Expand All @@ -43,11 +43,11 @@ distlib==0.3.1
# via virtualenv
elasticsearch-dsl==7.3.0
# via -r requirements/base.in
elasticsearch==7.12.1
elasticsearch==7.13.0
# via elasticsearch-dsl
environs==9.3.2
# via -r requirements/base.in
faker==8.1.4
faker==8.4.0
# via -r requirements/base.in
filelock==3.0.12
# via virtualenv
Expand All @@ -69,12 +69,13 @@ flake8==3.9.2
# flake8-print
greenlet==1.1.0
# via sqlalchemy
identify==2.2.4
identify==2.2.6
# via pre-commit
idna==2.10
# via requests
importlib-metadata==4.0.1
importlib-metadata==4.3.0
# via
# click
# flake8
# pep517
# pluggy
Expand All @@ -94,7 +95,7 @@ mccabe==0.6.1
# via flake8
mock==4.0.3
# via -r requirements/test.in
more-itertools==8.7.0
more-itertools==8.8.0
# via pytest
mypy-extensions==0.4.3
# via black
Expand All @@ -112,7 +113,7 @@ pip-tools==6.1.0
# via -r requirements/dev.in
pluggy==0.13.1
# via pytest
pre-commit==2.12.1
pre-commit==2.13.0
# via -r requirements/dev.in
psycopg2-binary==2.8.6
# via -r requirements/base.in
Expand All @@ -124,7 +125,7 @@ pycodestyle==2.7.0
# flake8-debugger
# flake8-print
# flake8-todo
pydocstyle==6.0.0
pydocstyle==6.1.1
# via flake8-docstrings
pyflakes==2.3.1
# via flake8
Expand All @@ -134,7 +135,7 @@ pytest-cov==2.12.0
# via -r requirements/test.in
pytest-mock==3.6.1
# via -r requirements/test.in
pytest-runner==5.3.0
pytest-runner==5.3.1
# via -r requirements/test.in
pytest-sugar==0.9.4
# via -r requirements/test.in
Expand All @@ -157,7 +158,7 @@ redis==3.5.3
# via -r requirements/base.in
regex==2021.4.4
# via black
requests-aws4auth==1.0.1
requests-aws4auth==1.1.0
# via -r requirements/base.in
requests==2.25.1
# via requests-aws4auth
Expand All @@ -169,6 +170,7 @@ six==1.16.0
# flake8-debugger
# flake8-print
# python-dateutil
# requests-aws4auth
# virtualenv
snowballstemmer==2.1.0
# via pydocstyle
Expand All @@ -194,12 +196,12 @@ typing-extensions==3.10.0.0
# via
# black
# importlib-metadata
urllib3==1.26.4
urllib3==1.26.5
# via
# botocore
# elasticsearch
# requests
virtualenv==20.4.6
virtualenv==20.4.7
# via pre-commit
wcwidth==0.2.5
# via pytest
Expand Down
23 changes: 13 additions & 10 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ appdirs==1.4.4
# via black
black==21.5b1
# via -r requirements/base.in
boto3==1.17.73
boto3==1.17.83
# via -r requirements/base.in
botocore==1.20.73
botocore==1.20.83
# via
# boto3
# s3transfer
Expand All @@ -24,24 +24,26 @@ certifi==2020.12.5
# requests
chardet==4.0.0
# via requests
click==8.0.0
click==8.0.1
# via
# -r requirements/base.in
# black
elasticsearch-dsl==7.3.0
# via -r requirements/base.in
elasticsearch==7.12.1
elasticsearch==7.13.0
# via elasticsearch-dsl
environs==9.3.2
# via -r requirements/base.in
faker==8.1.4
faker==8.4.0
# via -r requirements/base.in
greenlet==1.1.0
# via sqlalchemy
idna==2.10
# via requests
importlib-metadata==4.0.1
# via sqlalchemy
importlib-metadata==4.3.0
# via
# click
# sqlalchemy
jmespath==0.10.0
# via
# boto3
Expand All @@ -50,7 +52,7 @@ marshmallow==3.12.1
# via environs
mypy-extensions==0.4.3
# via black
newrelic==6.2.0.156
newrelic==6.4.0.157
# via -r requirements/prod.in
pathspec==0.8.1
# via black
Expand All @@ -67,7 +69,7 @@ redis==3.5.3
# via -r requirements/base.in
regex==2021.4.4
# via black
requests-aws4auth==1.0.1
requests-aws4auth==1.1.0
# via -r requirements/base.in
requests==2.25.1
# via requests-aws4auth
Expand All @@ -77,6 +79,7 @@ six==1.16.0
# via
# elasticsearch-dsl
# python-dateutil
# requests-aws4auth
sqlalchemy==1.4.15
# via -r requirements/base.in
sqlparse==0.4.1
Expand All @@ -91,7 +94,7 @@ typing-extensions==3.10.0.0
# via
# black
# importlib-metadata
urllib3==1.26.4
urllib3==1.26.5
# via
# botocore
# elasticsearch
Expand Down
24 changes: 13 additions & 11 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ attrs==21.2.0
# via pytest
black==21.5b1
# via -r requirements/base.in
boto3==1.17.73
boto3==1.17.83
# via -r requirements/base.in
botocore==1.20.73
botocore==1.20.83
# via
# boto3
# s3transfer
Expand All @@ -26,19 +26,19 @@ certifi==2020.12.5
# requests
chardet==4.0.0
# via requests
click==8.0.0
click==8.0.1
# via
# -r requirements/base.in
# black
coverage[toml]==5.5
# via pytest-cov
elasticsearch-dsl==7.3.0
# via -r requirements/base.in
elasticsearch==7.12.1
elasticsearch==7.13.0
# via elasticsearch-dsl
environs==9.3.2
# via -r requirements/base.in
faker==8.1.4
faker==8.4.0
# via -r requirements/base.in
flake8-debugger==4.0.0
# via -r requirements/test.in
Expand All @@ -60,8 +60,9 @@ greenlet==1.1.0
# via sqlalchemy
idna==2.10
# via requests
importlib-metadata==4.0.1
importlib-metadata==4.3.0
# via
# click
# flake8
# pluggy
# pytest
Expand All @@ -78,7 +79,7 @@ mccabe==0.6.1
# via flake8
mock==4.0.3
# via -r requirements/test.in
more-itertools==8.7.0
more-itertools==8.8.0
# via pytest
mypy-extensions==0.4.3
# via black
Expand All @@ -100,7 +101,7 @@ pycodestyle==2.7.0
# flake8-debugger
# flake8-print
# flake8-todo
pydocstyle==6.0.0
pydocstyle==6.1.1
# via flake8-docstrings
pyflakes==2.3.1
# via flake8
Expand All @@ -110,7 +111,7 @@ pytest-cov==2.12.0
# via -r requirements/test.in
pytest-mock==3.6.1
# via -r requirements/test.in
pytest-runner==5.3.0
pytest-runner==5.3.1
# via -r requirements/test.in
pytest-sugar==0.9.4
# via -r requirements/test.in
Expand All @@ -131,7 +132,7 @@ redis==3.5.3
# via -r requirements/base.in
regex==2021.4.4
# via black
requests-aws4auth==1.0.1
requests-aws4auth==1.1.0
# via -r requirements/base.in
requests==2.25.1
# via requests-aws4auth
Expand All @@ -143,6 +144,7 @@ six==1.16.0
# flake8-debugger
# flake8-print
# python-dateutil
# requests-aws4auth
snowballstemmer==2.1.0
# via pydocstyle
sqlalchemy==1.4.15
Expand All @@ -165,7 +167,7 @@ typing-extensions==3.10.0.0
# via
# black
# importlib-metadata
urllib3==1.26.4
urllib3==1.26.5
# via
# botocore
# elasticsearch
Expand Down

0 comments on commit 95cca20

Please sign in to comment.