Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize partitioned tables as objects #72

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project tries to adhere to [Semantic Versioning](http://semver.org/spec
## [Unreleased]
_this space intentionally left blank_

## [0.4.3] - 2022-09-01

### In Code
- fix Q_GET_ALL_RAW_OBJECT_ATTRIBUTES in context.py to also recognize partitioned tables (@FlipEnergy)

## [0.4.2] - 2019-12-13
### In Code
- Fixes for new "except" feature introduced in 0.4.0 ( @jholbrook-sqsp )
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Conrad Dean
Dennis Zhang
John Shiver
Michael Dudley
Zach Marine
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ test27:
--rm \
-e WITHIN_DOCKER_FLAG=true \
-e POSTGRES_PORT=5432 \
-e POSTGRES_VERSION=$(POSTGRES_VERSION) \
-v $(shell pwd):/opt \
--net=$(COMPOSED_NETWORK) \
tester27
Expand All @@ -118,6 +119,7 @@ test36:
--rm \
-e WITHIN_DOCKER_FLAG=true \
-e POSTGRES_PORT=5432 \
-e POSTGRES_VERSION=$(POSTGRES_VERSION) \
-v $(shell pwd):/opt \
--net=$(COMPOSED_NETWORK) \
tester36
Expand Down
2 changes: 1 addition & 1 deletion pgbedrock/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.4.2'
__version__ = '0.4.3'
LOG_FORMAT = '%(levelname)s:%(filename)s:%(funcName)s:%(lineno)s - %(message)s'
2 changes: 2 additions & 0 deletions pgbedrock/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
('v', 'tables'),
('m', 'tables'),
('f', 'tables'),
('p', 'tables'),
('S', 'sequences')
), tables_and_sequences AS (
SELECT
Expand Down Expand Up @@ -143,6 +144,7 @@
('v', 'tables'),
('m', 'tables'),
('f', 'tables'),
('p', 'tables'),
('S', 'sequences')
), tables_and_sequences AS (
SELECT
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pytest==3.1.3
pytest-cov==2.5.1
-r requirements-docs.txt
wheel==0.33.6
psycopg2==2.7.7
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Cerberus==1.1
click==6.7
Jinja2==2.10.1
MarkupSafe==1.0
MarkupSafe==1.1.1
psycopg2==2.7.3
PyYAML==5.2
46 changes: 46 additions & 0 deletions tests/test_context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from os import getenv

import pytest

from conftest import run_setup_sql
Expand Down Expand Up @@ -535,3 +537,47 @@ def test_get_version_info(cursor):
cursor.close()
actual_again = dbcontext.get_version_info()
assert actual_again == actual




@pytest.mark.skipif((int(getenv('POSTGRES_VERSION', '10.4').split('.')[0]) <= 9), reason="Parition not supported until PG10")
@run_setup_sql(
# Create a role
[attributes.Q_CREATE_ROLE.format(ROLES[0])] +
[
# Create schema; Role0 owns the schema but no objects
ownerships.Q_CREATE_SCHEMA.format(SCHEMAS[0], ROLES[0]),
] +
# Let the role create objects in the schema
[privs.Q_GRANT_NONDEFAULT.format('CREATE', 'SCHEMA', SCHEMAS[0], ROLES[0])] +
[
# Create a partitioned table
'SET ROLE {}; CREATE TABLE {}.{} (num int) PARTITION BY RANGE (num); RESET ROLE;'.format(ROLES[0], SCHEMAS[0], TABLES[0]),
])
def test_get_partitioned_table(cursor):
dbcontext = context.DatabaseContext(cursor, verbose=True)
expected = {
'tables': {
SCHEMAS[0]: {
common.ObjectName(SCHEMAS[0], TABLES[0]): {'owner': ROLES[0], 'is_dependent': False},
}
},
'schemas': {
SCHEMAS[0]: {
common.ObjectName(SCHEMAS[0]): {'owner': ROLES[0], 'is_dependent': False},
},
'public': {
'public': {'owner': 'postgres', 'is_dependent': False},
}
}
}

actual = dbcontext.get_all_object_attributes()

# We do this to avoid having to look at / filter out entries from
# information_schema or pg_catalog
for key in expected.keys():
expected_entries = expected[key][SCHEMAS[0]]
actual_entries = actual[key][SCHEMAS[0]]
assert expected_entries == actual_entries