diff --git a/alembic/versions/2023_03_19_1509-caf39c6e55fc_in_out_models.py b/alembic/versions/2023_03_19_1509-caf39c6e55fc_in_out_models.py index 86a0cd1..fc759e4 100644 --- a/alembic/versions/2023_03_19_1509-caf39c6e55fc_in_out_models.py +++ b/alembic/versions/2023_03_19_1509-caf39c6e55fc_in_out_models.py @@ -31,6 +31,7 @@ def upgrade() -> None: sa.Column('ap_context', sa.String(), nullable=True), sa.Column('ap_published_at', sa.DateTime(timezone=True), nullable=False), sa.Column('ap_object', sa.JSON(), nullable=False), + sa.Column('activity_object_ap_id', sa.String(), nullable=True), sa.Column('visibility', sa.Enum('PUBLIC', 'UNLISTED', 'FOLLOWERS_ONLY', 'DIRECT', name='visibilityenum'), nullable=False), sa.Column('relates_to_inbox_object_id', sa.Integer(), nullable=True), sa.Column('relates_to_outbox_object_id', sa.Integer(), nullable=True), @@ -41,6 +42,7 @@ def upgrade() -> None: ) op.create_index(op.f('ix_inbox_ap_id'), 'inbox', ['ap_id'], unique=True) op.create_index(op.f('ix_inbox_ap_type'), 'inbox', ['ap_type'], unique=False) + op.create_index(op.f('ix_inbox_activity_object_ap_id'), 'inbox', ['activity_object_ap_id'], unique=False) op.create_index(op.f('ix_inbox_id'), 'inbox', ['id'], unique=False) op.create_table('outbox', sa.Column('id', sa.Integer(), nullable=False), diff --git a/app/models.py b/app/models.py index 29ee1bb..3b8029f 100644 --- a/app/models.py +++ b/app/models.py @@ -61,6 +61,7 @@ class InboxObject(Base): ap_context = Column(String, nullable=True) ap_published_at = Column(DateTime(timezone=True), nullable=False) ap_object: Mapped[dict[str, Any]] = Column(JSON, nullable=False) # type: ignore + activity_object_ap_id = Column(String, nullable=True, index=True) visibility = Column(Enum(ap.VisibilityEnum), nullable=False) @@ -71,7 +72,7 @@ class InboxObject(Base): ) relates_to_inbox_object: Mapped[Optional["InboxObject"]] = relationship( "InboxObject", - foreign_keys=relates_to_inbox_object_id, + foreign_keys=[relates_to_inbox_object_id], remote_side=id, uselist=False, ) @@ -82,8 +83,7 @@ class InboxObject(Base): ) relates_to_outbox_object: Mapped[Optional["OutboxObject"]] = relationship( "OutboxObject", - foreign_keys=[relates_to_outbox_object_id], - remote_side=id, + foreign_keys=relates_to_outbox_object_id, uselist=False, ) @@ -117,7 +117,7 @@ class OutboxObject(Base): ) relates_to_inbox_object: Mapped[Optional["InboxObject"]] = relationship( "InboxObject", - foreign_keys=[relates_to_inbox_object_id], + foreign_keys=relates_to_inbox_object_id, uselist=False, ) relates_to_outbox_object_id = Column(