diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-10-25 15:01:55 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-10-25 15:02:46 -0400 |
commit | 8d318dee6cdccd0751ad8b0832774398a45f9cdb (patch) | |
tree | ef6aa26e84bb56cc069db9b37eb345e220a72fb1 /test/dialect/postgresql/test_reflection.py | |
parent | f34b180ca9059a74c3bf1db1b79e187c3f4b81c9 (diff) | |
download | sqlalchemy-8d318dee6cdccd0751ad8b0832774398a45f9cdb.tar.gz |
Test for EXCLUDE constraint duplicated index
An EXCLUDE constraint makes an index just like a UNIQUE does;
get_indexes() will receive this. Test that this works out the
same way as it does for a UNIQUE.
Change-Id: I02ac7cbbb1ca0d1fcdcdbe9a8b8bd1ffee3e496c
Fixes: #4122
Diffstat (limited to 'test/dialect/postgresql/test_reflection.py')
-rw-r--r-- | test/dialect/postgresql/test_reflection.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index a1942ab30..5c52195d1 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -13,7 +13,8 @@ from sqlalchemy import Table, Column, MetaData, Integer, String, \ from sqlalchemy import exc import sqlalchemy as sa from sqlalchemy.dialects.postgresql import base as postgresql -from sqlalchemy.dialects.postgresql import ARRAY, INTERVAL +from sqlalchemy.dialects.postgresql import ARRAY, INTERVAL, TSRANGE +from sqlalchemy.dialects.postgresql import ExcludeConstraint import re @@ -971,6 +972,36 @@ class ReflectionTest(fixtures.TestBase): self.assert_('uc_a' not in indexes) self.assert_('uc_a' in constraints) + @testing.requires.btree_gist + @testing.provide_metadata + def test_reflection_with_exclude_constraint(self): + m = self.metadata + Table( + 't', m, + Column('id', Integer, primary_key=True), + Column('period', TSRANGE), + ExcludeConstraint(('period', '&&'), name='quarters_period_excl') + ) + + m.create_all() + + insp = inspect(testing.db) + + # PostgreSQL will create an implicit index for an exclude constraint. + # we don't reflect the EXCLUDE yet. + eq_( + insp.get_indexes('t'), + [{'unique': False, 'name': 'quarters_period_excl', + 'duplicates_constraint': 'quarters_period_excl', + 'dialect_options': {'postgresql_using': 'gist'}, + 'column_names': ['period']}] + ) + + # reflection corrects for the dupe + reflected = Table('t', MetaData(testing.db), autoload=True) + + eq_(set(reflected.indexes), set()) + @testing.provide_metadata def test_reflect_unique_index(self): insp = inspect(testing.db) @@ -1026,6 +1057,7 @@ class ReflectionTest(fixtures.TestBase): }) + class CustomTypeReflectionTest(fixtures.TestBase): class CustomType(object): |