2024-06-15 02:46:02 +08:00
|
|
|
import json
|
|
|
|
|
2024-04-29 11:58:17 +08:00
|
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
2024-01-12 12:34:01 +08:00
|
|
|
|
2024-02-06 13:21:13 +08:00
|
|
|
from extensions.ext_database import db
|
2024-09-29 17:00:58 +08:00
|
|
|
from models.base import Base
|
2024-08-13 14:44:10 +08:00
|
|
|
|
|
|
|
from .types import StringUUID
|
2024-02-06 13:21:13 +08:00
|
|
|
|
2023-06-16 21:47:51 +08:00
|
|
|
|
2024-09-29 17:00:58 +08:00
|
|
|
class DataSourceOauthBinding(Base):
|
2024-09-10 17:08:06 +08:00
|
|
|
__tablename__ = "data_source_oauth_bindings"
|
2023-06-16 21:47:51 +08:00
|
|
|
__table_args__ = (
|
2024-09-10 17:08:06 +08:00
|
|
|
db.PrimaryKeyConstraint("id", name="source_binding_pkey"),
|
|
|
|
db.Index("source_binding_tenant_id_idx", "tenant_id"),
|
|
|
|
db.Index("source_info_idx", "source_info", postgresql_using="gin"),
|
2023-06-16 21:47:51 +08:00
|
|
|
)
|
|
|
|
|
2024-09-10 17:08:06 +08:00
|
|
|
id = db.Column(StringUUID, server_default=db.text("uuid_generate_v4()"))
|
2024-04-29 11:58:17 +08:00
|
|
|
tenant_id = db.Column(StringUUID, nullable=False)
|
2023-06-16 21:47:51 +08:00
|
|
|
access_token = db.Column(db.String(255), nullable=False)
|
|
|
|
provider = db.Column(db.String(255), nullable=False)
|
|
|
|
source_info = db.Column(JSONB, nullable=False)
|
2024-09-10 17:08:06 +08:00
|
|
|
created_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)"))
|
|
|
|
updated_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)"))
|
|
|
|
disabled = db.Column(db.Boolean, nullable=True, server_default=db.text("false"))
|
2024-06-15 02:46:02 +08:00
|
|
|
|
|
|
|
|
2024-09-29 17:00:58 +08:00
|
|
|
class DataSourceApiKeyAuthBinding(Base):
|
2024-09-10 17:08:06 +08:00
|
|
|
__tablename__ = "data_source_api_key_auth_bindings"
|
2024-06-15 02:46:02 +08:00
|
|
|
__table_args__ = (
|
2024-09-10 17:08:06 +08:00
|
|
|
db.PrimaryKeyConstraint("id", name="data_source_api_key_auth_binding_pkey"),
|
|
|
|
db.Index("data_source_api_key_auth_binding_tenant_id_idx", "tenant_id"),
|
|
|
|
db.Index("data_source_api_key_auth_binding_provider_idx", "provider"),
|
2024-06-15 02:46:02 +08:00
|
|
|
)
|
|
|
|
|
2024-09-10 17:08:06 +08:00
|
|
|
id = db.Column(StringUUID, server_default=db.text("uuid_generate_v4()"))
|
2024-06-15 02:46:02 +08:00
|
|
|
tenant_id = db.Column(StringUUID, nullable=False)
|
|
|
|
category = db.Column(db.String(255), nullable=False)
|
|
|
|
provider = db.Column(db.String(255), nullable=False)
|
|
|
|
credentials = db.Column(db.Text, nullable=True) # JSON
|
2024-09-10 17:08:06 +08:00
|
|
|
created_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)"))
|
|
|
|
updated_at = db.Column(db.DateTime, nullable=False, server_default=db.text("CURRENT_TIMESTAMP(0)"))
|
|
|
|
disabled = db.Column(db.Boolean, nullable=True, server_default=db.text("false"))
|
2024-06-15 02:46:02 +08:00
|
|
|
|
|
|
|
def to_dict(self):
|
|
|
|
return {
|
2024-09-10 17:08:06 +08:00
|
|
|
"id": self.id,
|
|
|
|
"tenant_id": self.tenant_id,
|
|
|
|
"category": self.category,
|
|
|
|
"provider": self.provider,
|
|
|
|
"credentials": json.loads(self.credentials),
|
|
|
|
"created_at": self.created_at.timestamp(),
|
|
|
|
"updated_at": self.updated_at.timestamp(),
|
|
|
|
"disabled": self.disabled,
|
2024-06-15 02:46:02 +08:00
|
|
|
}
|