Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(enterprise): migrate Slack models to SQLAlchemy 2.0 [8/13] (#13854)

Rohit Malhotra270d9b1ccebd
diff --git a/enterprise/storage/slack_conversation.py b/enterprise/storage/slack_conversation.py
index ce2134f519..79b37ce8f0 100644
--- a/enterprise/storage/slack_conversation.py
+++ b/enterprise/storage/slack_conversation.py
@@ -1,18 +1,26 @@
-from sqlalchemy import Boolean, Column, ForeignKey, Identity, Integer, String
-from sqlalchemy.dialects.postgresql import UUID
-from sqlalchemy.orm import relationship
+from typing import TYPE_CHECKING
+from uuid import UUID
+
+from sqlalchemy import ForeignKey, Identity, String
+from sqlalchemy.orm import Mapped, mapped_column, relationship
from storage.base import Base
+if TYPE_CHECKING:
+ from storage.org import Org
+
-class SlackConversation(Base): # type: ignore
+class SlackConversation(Base):
__tablename__ = 'slack_conversation'
- id = Column(Integer, Identity(), primary_key=True)
- conversation_id = Column(String, nullable=False, index=True)
- channel_id = Column(String, nullable=False)
- keycloak_user_id = Column(String, nullable=False)
- org_id = Column(UUID(as_uuid=True), ForeignKey('org.id'), nullable=True)
- parent_id = Column(String, nullable=True, index=True)
- v1_enabled = Column(Boolean, nullable=True)
+
+ id: Mapped[int] = mapped_column(Identity(), primary_key=True)
+ conversation_id: Mapped[str] = mapped_column(String, nullable=False, index=True)
+ channel_id: Mapped[str] = mapped_column(String, nullable=False)
+ keycloak_user_id: Mapped[str] = mapped_column(String, nullable=False)
+ org_id: Mapped[UUID | None] = mapped_column(ForeignKey('org.id'), nullable=True)
+ parent_id: Mapped[str | None] = mapped_column(String, nullable=True, index=True)
+ v1_enabled: Mapped[bool | None] = mapped_column(nullable=True)
# Relationships
- org = relationship('Org', back_populates='slack_conversations')
+ org: Mapped['Org | None'] = relationship(
+ 'Org', back_populates='slack_conversations'
+ )
diff --git a/enterprise/storage/slack_team.py b/enterprise/storage/slack_team.py
index c344e3bab5..b197e3b845 100644
--- a/enterprise/storage/slack_team.py
+++ b/enterprise/storage/slack_team.py
@@ -1,13 +1,19 @@
-from sqlalchemy import Column, DateTime, Identity, Integer, String, text
+from datetime import datetime
+
+from sqlalchemy import DateTime, Identity, String, text
+from sqlalchemy.orm import Mapped, mapped_column
from storage.base import Base
-class SlackTeam(Base): # type: ignore
+class SlackTeam(Base):
__tablename__ = 'slack_teams'
- id = Column(Integer, Identity(), primary_key=True)
- team_id = Column(String, nullable=False, index=True, unique=True)
- bot_access_token = Column(String, nullable=False)
- created_at = Column(
+
+ id: Mapped[int] = mapped_column(Identity(), primary_key=True)
+ team_id: Mapped[str] = mapped_column(
+ String, nullable=False, index=True, unique=True
+ )
+ bot_access_token: Mapped[str] = mapped_column(String, nullable=False)
+ created_at: Mapped[datetime] = mapped_column(
DateTime,
server_default=text('CURRENT_TIMESTAMP'),
nullable=False,
diff --git a/enterprise/storage/slack_user.py b/enterprise/storage/slack_user.py
index 90846f99e8..ba9b0ad626 100644
--- a/enterprise/storage/slack_user.py
+++ b/enterprise/storage/slack_user.py
@@ -1,21 +1,28 @@
-from sqlalchemy import Column, DateTime, ForeignKey, Identity, Integer, String, text
-from sqlalchemy.dialects.postgresql import UUID
-from sqlalchemy.orm import relationship
+from datetime import datetime
+from typing import TYPE_CHECKING
+from uuid import UUID
+
+from sqlalchemy import DateTime, ForeignKey, Identity, String, text
+from sqlalchemy.orm import Mapped, mapped_column, relationship
from storage.base import Base
+if TYPE_CHECKING:
+ from storage.org import Org
+
-class SlackUser(Base): # type: ignore
+class SlackUser(Base):
__tablename__ = 'slack_users'
- id = Column(Integer, Identity(), primary_key=True)
- keycloak_user_id = Column(String, nullable=False, index=True)
- org_id = Column(UUID(as_uuid=True), ForeignKey('org.id'), nullable=True)
- slack_user_id = Column(String, nullable=False, index=True)
- slack_display_name = Column(String, nullable=False)
- created_at = Column(
+
+ id: Mapped[int] = mapped_column(Identity(), primary_key=True)
+ keycloak_user_id: Mapped[str] = mapped_column(String, nullable=False, index=True)
+ org_id: Mapped[UUID | None] = mapped_column(ForeignKey('org.id'), nullable=True)
+ slack_user_id: Mapped[str] = mapped_column(String, nullable=False, index=True)
+ slack_display_name: Mapped[str] = mapped_column(String, nullable=False)
+ created_at: Mapped[datetime] = mapped_column(
DateTime,
server_default=text('CURRENT_TIMESTAMP'),
nullable=False,
)
# Relationships
- org = relationship('Org', back_populates='slack_users')
+ org: Mapped['Org | None'] = relationship('Org', back_populates='slack_users')