Update support for unique user IDs (#2921)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import enum
|
||||
import uuid
|
||||
import datetime
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import (
|
||||
Column, String, Boolean, ForeignKey, Enum, Table,
|
||||
DateTime, JSON, Integer, UUID, Index, event
|
||||
@@ -43,7 +44,7 @@ class App(Base):
|
||||
__tablename__ = "apps"
|
||||
id = Column(UUID, primary_key=True, default=lambda: uuid.uuid4())
|
||||
owner_id = Column(UUID, ForeignKey("users.id"), nullable=False, index=True)
|
||||
name = Column(String, unique=True, nullable=False, index=True)
|
||||
name = Column(String, nullable=False, index=True)
|
||||
description = Column(String)
|
||||
metadata_ = Column('metadata', JSON, default=dict)
|
||||
is_active = Column(Boolean, default=True, index=True)
|
||||
@@ -55,6 +56,10 @@ class App(Base):
|
||||
owner = relationship("User", back_populates="apps")
|
||||
memories = relationship("Memory", back_populates="app")
|
||||
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('owner_id', 'name', name='idx_app_owner_name'),
|
||||
)
|
||||
|
||||
|
||||
class Config(Base):
|
||||
__tablename__ = "configs"
|
||||
|
||||
@@ -212,7 +212,8 @@ async def create_memory(
|
||||
if not user:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
# Get or create app
|
||||
app_obj = db.query(App).filter(App.name == request.app).first()
|
||||
app_obj = db.query(App).filter(App.name == request.app,
|
||||
App.owner_id == user.id).first()
|
||||
if not app_obj:
|
||||
app_obj = App(name=request.app, owner_id=user.id)
|
||||
db.add(app_obj)
|
||||
|
||||
Reference in New Issue
Block a user