π OpenHands: AI-Driven Development
fix(enterprise): migrate Git provider models to SQLAlchemy 2.0 [11/13] (#13857)
Rohit Malhotracd24b5838b88
diff --git a/enterprise/storage/github_app_installation.py b/enterprise/storage/github_app_installation.pyindex 8432f2a5fc..1c502efdef 100644--- a/enterprise/storage/github_app_installation.py+++ b/enterprise/storage/github_app_installation.py@@ -1,20 +1,24 @@-from sqlalchemy import Column, DateTime, Integer, String, text+from datetime import datetime++from sqlalchemy import DateTime, String, text+from sqlalchemy.orm import Mapped, mapped_columnfrom storage.base import Base-class GithubAppInstallation(Base): # type: ignore+class GithubAppInstallation(Base):"""Represents a Github App Installation with associated token."""__tablename__ = 'github_app_installations'- id = Column(Integer, primary_key=True, autoincrement=True)- installation_id = Column(String, nullable=False)- encrypted_token = Column(String, nullable=False)- created_at = Column(++ id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)+ installation_id: Mapped[str] = mapped_column(String, nullable=False)+ encrypted_token: Mapped[str] = mapped_column(String, nullable=False)+ created_at: Mapped[datetime] = mapped_column(DateTime, server_default=text('CURRENT_TIMESTAMP'), nullable=False)- updated_at = Column(+ updated_at: Mapped[datetime] = mapped_column(DateTime,server_default=text('CURRENT_TIMESTAMP'),onupdate=text('CURRENT_TIMESTAMP'),diff --git a/enterprise/storage/gitlab_webhook.py b/enterprise/storage/gitlab_webhook.pyindex aede651fb6..a3f2f7c268 100644--- a/enterprise/storage/gitlab_webhook.py+++ b/enterprise/storage/gitlab_webhook.py@@ -1,16 +1,16 @@import sys+from datetime import datetimefrom enum import IntEnum+from typing import Anyfrom sqlalchemy import (ARRAY,- Boolean,- Column,DateTime,- Integer,String,Text,text,)+from sqlalchemy.orm import Mapped, mapped_columnfrom storage.base import Base@@ -21,23 +21,26 @@ class WebhookStatus(IntEnum):INVALID = 3 # Unexpected error occur when checking (keycloak connection, etc)-class GitlabWebhook(Base): # type: ignore+class GitlabWebhook(Base):"""Represents a Gitlab webhook configuration for a repository or group."""__tablename__ = 'gitlab_webhook'- id = Column(Integer, primary_key=True, autoincrement=True)- group_id = Column(String, nullable=True)- project_id = Column(String, nullable=True)- user_id = Column(String, nullable=False)- webhook_exists = Column(Boolean, nullable=False)- webhook_url = Column(String, nullable=True)- webhook_secret = Column(String, nullable=True)- webhook_uuid = Column(String, nullable=True)++ id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)+ group_id: Mapped[str | None] = mapped_column(String, nullable=True)+ project_id: Mapped[str | None] = mapped_column(String, nullable=True)+ user_id: Mapped[str] = mapped_column(String, nullable=False)+ webhook_exists: Mapped[bool] = mapped_column(nullable=False)+ webhook_url: Mapped[str | None] = mapped_column(String, nullable=True)+ webhook_secret: Mapped[str | None] = mapped_column(String, nullable=True)+ webhook_uuid: Mapped[str | None] = mapped_column(String, nullable=True)# Use Text for tests (SQLite compatibility) and ARRAY for production (PostgreSQL)- scopes = Column(Text if 'pytest' in sys.modules else ARRAY(Text), nullable=True)- last_synced = Column(+ scopes: Mapped[Any] = mapped_column(+ Text if 'pytest' in sys.modules else ARRAY(Text), nullable=True+ )+ last_synced: Mapped[datetime | None] = mapped_column(DateTime,server_default=text('CURRENT_TIMESTAMP'),onupdate=text('CURRENT_TIMESTAMP'),