Skip to content

Commit

Permalink
WCM-285: add index to table definition
Browse files Browse the repository at this point in the history
rename development table definitions
  • Loading branch information
stollero committed Sep 12, 2024
1 parent 47826c1 commit 0e6a462
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions core/src/zeit/connector/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ class Base(sqlalchemy.orm.DeclarativeBase):


class CommonMetadata:
access = mapped_column(Unicode, index=True, info={'namespace': 'document', 'name': 'access'})
@staticmethod
def table_args(tablename):
return (
Index(f'ix_{tablename}_channels', 'channels', postgresql_using='gin'),
Index(f'ix_{tablename}_subchannels', 'subchannels', postgresql_using='gin'),
)

channels = mapped_column(ARRAY(Unicode), nullable=True)
subchannels = mapped_column(ARRAY(Unicode), nullable=True)


class ZeitWeb:
class DevelopmentCommonMetadata:
access = mapped_column(Unicode, index=True, info={'namespace': 'document', 'name': 'access'})


class DevelopmentZeitWeb:
overscrolling_enabled = mapped_column(
Boolean, info={'namespace': 'document', 'name': 'overscrolling'}
)
Expand All @@ -62,8 +72,6 @@ def __table_args__(cls):
postgresql_using='gin',
postgresql_ops={'unsorted': 'jsonb_path_ops'},
),
Index(f'ix_{cls.__tablename__}_channels', 'channels', postgresql_using='gin'),
Index(f'ix_{cls.__tablename__}_subchannels', 'subchannels', postgresql_using='gin'),
)

id = mapped_column(Uuid(as_uuid=False), primary_key=True)
Expand Down Expand Up @@ -223,19 +231,26 @@ def status(self):
return LockStatus.FOREIGN


class Content(Base, ContentBase):
class Content(Base, ContentBase, CommonMetadata):
lock_class = 'Lock'

@declared_attr.directive
def __table_args__(cls):
"""every new inheritance level needs to re-apply the table_args"""
return super().__table_args__ + CommonMetadata.table_args(cls.__tablename__)


class Lock(Base, LockBase):
content_class = 'Content'


class DevelopmentBase(sqlalchemy.orm.DeclarativeBase):
pass
"""Experimental development features, not ready for any deployment or migration!"""


class ContentWithMetadataColumns(DevelopmentBase, ContentBase, CommonMetadata, ZeitWeb):
class ContentWithMetadataColumns(
DevelopmentBase, ContentBase, CommonMetadata, DevelopmentCommonMetadata, DevelopmentZeitWeb
):
lock_class = 'LockWithMetadataColumns'


Expand Down

0 comments on commit 0e6a462

Please sign in to comment.