Buckets:

download
raw
2.65 kB
# [CREATE] backend/db/models/datastore.py
import uuid
from sqlalchemy import (
Column, Integer, String,
ForeignKey,
DateTime, Index, JSON, UniqueConstraint, CheckConstraint
)
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship, Mapped, mapped_column
from typing import Optional, Dict, Any
from datetime import datetime
from backend.db.base import Base
class DataStore(Base):
__tablename__ = "datastores"
id: Mapped[str] = mapped_column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
name: Mapped[str] = mapped_column(String, nullable=False)
description: Mapped[Optional[str]] = mapped_column(String, nullable=True)
owner_user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
vectorizer_name: Mapped[str] = mapped_column(String, nullable=False, index=True)
vectorizer_config: Mapped[Dict[str, Any]] = mapped_column(JSON, default=lambda: {})
chunk_size: Mapped[int] = mapped_column(Integer, default=2048)
chunk_overlap: Mapped[int] = mapped_column(Integer, default=256)
chunking_strategy: Mapped[str] = mapped_column(String, default="recursive")
chunking_kwargs: Mapped[Dict[str, Any]] = mapped_column(JSON, default=lambda: {})
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
updated_at: Mapped[Optional[datetime]] = mapped_column(DateTime(timezone=True), onupdate=func.now())
owner: Mapped["User"] = relationship("User", back_populates="owned_datastores")
__table_args__ = (UniqueConstraint('owner_user_id', 'name', name='uq_user_datastore_name'),)
class SharedDataStoreLink(Base):
__tablename__ = "shared_datastore_links"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True, autoincrement=True)
datastore_id: Mapped[str] = mapped_column(String, ForeignKey("datastores.id", ondelete="CASCADE"), nullable=False, index=True)
shared_with_user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
permission_level: Mapped[str] = mapped_column(String, nullable=False, default="read_query")
datastore: Mapped["DataStore"] = relationship("DataStore")
shared_with_user: Mapped["User"] = relationship("User", foreign_keys=[shared_with_user_id])
__table_args__ = (
UniqueConstraint('datastore_id', 'shared_with_user_id', name='uq_datastore_shared_user'),
CheckConstraint(permission_level.in_(['read_query', 'read_write', 'revectorize']), name='ck_datastore_permission_level_valid')
)

Xet Storage Details

Size:
2.65 kB
·
Xet hash:
e89be7462a4273491f3184f7eeda4347ec507a171b91be5a12dce075c3f159bd

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.