def test_composite_fk_with_index(self):
        Base = declarative_base()

        class User(Base):
            __tablename__ = 'user'
            first_name = sa.Column(sa.Unicode(255), primary_key=True)
            last_name = sa.Column(sa.Unicode(255), primary_key=True)

        class Article(Base):
            __tablename__ = 'article'
            id = sa.Column(sa.Integer, primary_key=True)
            author_first_name = sa.Column(sa.Unicode(255))
            author_last_name = sa.Column(sa.Unicode(255))
            __table_args__ = (
                sa.ForeignKeyConstraint(
                    [author_first_name, author_last_name],
                    [User.first_name, User.last_name]
                ),
                sa.Index(
                    'my_index',
                    author_first_name,
                    author_last_name,
                    unique=True
                )
            )

        table = Article.__table__
        constraint = get_fk_constraint_for_columns(
            table,
            table.c.author_first_name,
            table.c.author_last_name
        )
        assert has_unique_index(constraint)
Ejemplo n.º 2
0
 def test_compound_column_unique_index(self):
     assert not has_unique_index(self.article_translations.c.is_published)
     assert not has_unique_index(self.article_translations.c.is_archived)
Ejemplo n.º 3
0
 def test_single_column_index(self):
     assert not has_unique_index(self.article_translations.c.is_published)
Ejemplo n.º 4
0
 def test_compound_primary_key(self):
     assert not has_unique_index(self.article_translations.c.id)
     assert not has_unique_index(self.article_translations.c.locale)
Ejemplo n.º 5
0
 def test_unique_index(self):
     assert has_unique_index(self.article_translations.c.is_deleted)
Ejemplo n.º 6
0
 def test_column_of_aliased_table(self):
     alias = sa.orm.aliased(self.articles)
     with raises(TypeError):
         assert has_unique_index(alias.c.id)
Ejemplo n.º 7
0
 def test_primary_key(self):
     assert has_unique_index(self.articles.c.id)
 def test_compound_column_unique_index(self):
     assert not has_unique_index(self.article_translations.c.is_published)
     assert not has_unique_index(self.article_translations.c.is_archived)
 def test_single_column_index(self):
     assert not has_unique_index(self.article_translations.c.is_published)
 def test_compound_primary_key(self):
     assert not has_unique_index(self.article_translations.c.id)
     assert not has_unique_index(self.article_translations.c.locale)
 def test_unique_index(self):
     assert has_unique_index(self.article_translations.c.is_deleted)
 def test_column_of_aliased_table(self):
     alias = sa.orm.aliased(self.articles)
     with raises(TypeError):
         assert has_unique_index(alias.c.id)
 def test_primary_key(self):
     assert has_unique_index(self.articles.c.id)