| 1 | from typing import List |
| 2 | from typing import Optional |
| 3 | |
| 4 | from sqlalchemy import Text |
| 5 | from sqlmodel import Field |
| 6 | from sqlmodel import Relationship |
| 7 | from sqlmodel import SQLModel |
| 8 | |
| 9 | |
| 10 | class AvailableIntegrations(SQLModel, table=True): |
| 11 | __tablename__ = "available_integrations" |
| 12 | id: Optional[int] = Field(default=None, primary_key=True) |
| 13 | integration_name: str = Field(max_length=255, nullable=False) |
| 14 | description: str = Field(max_length=1024) |
| 15 | integration_details: str = Field(sa_column=Text) |
| 16 | # Relationships |
| 17 | auth_keys: List["AvailableIntegrationsAuthKeys"] = Relationship( |
| 18 | back_populates="integration", |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | class AvailableIntegrationsAuthKeys(SQLModel, table=True): |
| 23 | __tablename__ = "available_integrations_auth_keys" |
| 24 | id: Optional[int] = Field(default=None, primary_key=True) |
| 25 | integration_id: int = Field(default=None, foreign_key="available_integrations.id") |
| 26 | integration_name: str = Field(max_length=255, nullable=False) |
| 27 | auth_key_name: str = Field(max_length=255, nullable=False) |
| 28 | # Relationships |
| 29 | integration: "AvailableIntegrations" = Relationship(back_populates="auth_keys") |
| 30 | |
| 31 | |
| 32 | class CustomerIntegrations(SQLModel, table=True): |
| 33 | __tablename__ = "customer_integrations" |
| 34 | id: Optional[int] = Field(default=None, primary_key=True) |
| 35 | customer_code: str = Field(max_length=50, nullable=False) |
| 36 | customer_name: str = Field(max_length=255, nullable=False) |
| 37 | integration_service_id: Optional[int] = Field(default=None, nullable=False) |
| 38 | integration_service_name: str = Field(max_length=255, nullable=False) |
| 39 | deployed: bool = Field(default=False) |
| 40 | # Relationships |
| 41 | integration_subscriptions: List["IntegrationSubscription"] = Relationship( |
| 42 | back_populates="customer_integrations", |
| 43 | ) |
| 44 | |
| 45 | |
| 46 | class IntegrationService(SQLModel, table=True): |
| 47 | __tablename__ = "integration_services" |
| 48 | id: Optional[int] = Field(default=None, primary_key=True) |
| 49 | service_name: str = Field(max_length=255, nullable=False) |
| 50 | auth_type: str = Field(max_length=50) # e.g., OAuth, API Key, etc. |
| 51 | # Relationships |
| 52 | integration_subscriptions: List["IntegrationSubscription"] = Relationship( |
| 53 | back_populates="integration_service", |
| 54 | ) |
| 55 | configs: List["IntegrationConfig"] = Relationship( |
| 56 | back_populates="integration_service", |
| 57 | ) |
| 58 | |
| 59 | |
| 60 | class IntegrationSubscription(SQLModel, table=True): |
| 61 | __tablename__ = "integration_subscriptions" |
| 62 | id: Optional[int] = Field(default=None, primary_key=True) |
| 63 | customer_id: int = Field(default=None, foreign_key="customer_integrations.id") |
| 64 | integration_service_id: int = Field( |
| 65 | default=None, |
| 66 | foreign_key="integration_services.id", |
| 67 | ) |
| 68 | # Relationships |
| 69 | customer_integrations: "CustomerIntegrations" = Relationship( |
| 70 | back_populates="integration_subscriptions", |
| 71 | ) |
| 72 | integration_service: "IntegrationService" = Relationship( |
| 73 | back_populates="integration_subscriptions", |
| 74 | ) |
| 75 | integration_auth_keys: List["IntegrationAuthKeys"] = Relationship( |
| 76 | back_populates="integration_subscription", |
| 77 | ) # Moved here |
| 78 | |
| 79 | |
| 80 | class IntegrationConfig(SQLModel, table=True): |
| 81 | __tablename__ = "integration_configs" |
| 82 | id: Optional[int] = Field(default=None, primary_key=True) |
| 83 | integration_service_id: int = Field( |
| 84 | default=None, |
| 85 | foreign_key="integration_services.id", |
| 86 | ) |
| 87 | config_key: str = Field(max_length=255) # e.g., 'endpoint', 'port', etc. |
| 88 | config_value: str = Field(max_length=1024) # e.g., 'https://api.service.com/v1' |
| 89 | # Relationships |
| 90 | integration_service: "IntegrationService" = Relationship(back_populates="configs") |
| 91 | |
| 92 | |
| 93 | class IntegrationAuthKeys(SQLModel, table=True): |
| 94 | __tablename__ = "integration_auth_keys" |
| 95 | id: Optional[int] = Field(default=None, primary_key=True) |
| 96 | subscription_id: int = Field( |
| 97 | default=None, |
| 98 | foreign_key="integration_subscriptions.id", |
| 99 | ) |
| 100 | auth_key_name: str = Field(max_length=255) # e.g., 'credentials', 'rate_limit' |
| 101 | auth_value: str = Field(max_length=1024) # e.g., JSON/encrypted credentials |
| 102 | # Relationships |
| 103 | integration_subscription: "IntegrationSubscription" = Relationship( |
| 104 | back_populates="integration_auth_keys", |
| 105 | ) # Adjusted relationship |
| 106 | |
| 107 | |
| 108 | class CustomerIntegrationsMeta(SQLModel, table=True): |
| 109 | __tablename__ = "customer_integrations_meta" |
| 110 | id: Optional[int] = Field(default=None, primary_key=True) |
| 111 | customer_code: str = Field(max_length=50, nullable=False) |
| 112 | integration_name: str = Field(max_length=255, nullable=False) |
| 113 | graylog_input_id: Optional[str] = Field(max_length=1024) |
| 114 | graylog_index_id: str = Field(max_length=1024, nullable=False) |
| 115 | graylog_stream_id: str = Field(max_length=1024, nullable=False) |
| 116 | grafana_org_id: str = Field(max_length=1024, nullable=False) |
| 117 | grafana_dashboard_folder_id: str = Field(max_length=1024, nullable=False) |
| 118 | grafana_datasource_uid: Optional[str] = Field( |
| 119 | default=None, |
| 120 | max_length=1024, |
| 121 | ) |