You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

source.py 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import json
  2. from sqlalchemy import func
  3. from sqlalchemy.dialects.postgresql import JSONB
  4. from sqlalchemy.orm import mapped_column
  5. from models.base import Base
  6. from .engine import db
  7. from .types import StringUUID
  8. class DataSourceOauthBinding(Base):
  9. __tablename__ = "data_source_oauth_bindings"
  10. __table_args__ = (
  11. db.PrimaryKeyConstraint("id", name="source_binding_pkey"),
  12. db.Index("source_binding_tenant_id_idx", "tenant_id"),
  13. db.Index("source_info_idx", "source_info", postgresql_using="gin"),
  14. )
  15. id = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()"))
  16. tenant_id = mapped_column(StringUUID, nullable=False)
  17. access_token = mapped_column(db.String(255), nullable=False)
  18. provider = mapped_column(db.String(255), nullable=False)
  19. source_info = mapped_column(JSONB, nullable=False)
  20. created_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp())
  21. updated_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp())
  22. disabled = mapped_column(db.Boolean, nullable=True, server_default=db.text("false"))
  23. class DataSourceApiKeyAuthBinding(Base):
  24. __tablename__ = "data_source_api_key_auth_bindings"
  25. __table_args__ = (
  26. db.PrimaryKeyConstraint("id", name="data_source_api_key_auth_binding_pkey"),
  27. db.Index("data_source_api_key_auth_binding_tenant_id_idx", "tenant_id"),
  28. db.Index("data_source_api_key_auth_binding_provider_idx", "provider"),
  29. )
  30. id = mapped_column(StringUUID, server_default=db.text("uuid_generate_v4()"))
  31. tenant_id = mapped_column(StringUUID, nullable=False)
  32. category = mapped_column(db.String(255), nullable=False)
  33. provider = mapped_column(db.String(255), nullable=False)
  34. credentials = mapped_column(db.Text, nullable=True) # JSON
  35. created_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp())
  36. updated_at = mapped_column(db.DateTime, nullable=False, server_default=func.current_timestamp())
  37. disabled = mapped_column(db.Boolean, nullable=True, server_default=db.text("false"))
  38. def to_dict(self):
  39. return {
  40. "id": self.id,
  41. "tenant_id": self.tenant_id,
  42. "category": self.category,
  43. "provider": self.provider,
  44. "credentials": json.loads(self.credentials),
  45. "created_at": self.created_at.timestamp(),
  46. "updated_at": self.updated_at.timestamp(),
  47. "disabled": self.disabled,
  48. }