From 7d6c748045b394262847199c03bb80cc221be1b2 Mon Sep 17 00:00:00 2001 From: jiisanda Date: Sun, 15 Dec 2024 01:37:54 +0530 Subject: [PATCH] docuemnt comment table update --- README.md | 2 +- app/db/tables/auth/auth.py | 1 + app/db/tables/documents/documents_metadata.py | 29 ++++++++++++++++++- migrations/env.py | 3 ++ .../versions/2a02384ab925_initial_almebic.py | 14 ++++----- requirements.txt | 16 +++++----- 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b277b8c..eeb2ee6 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ DocFlow is a powerful Document Management API designed to streamline document ha ## 😎 Upcoming Updates -- 🟨 Document Interactions - Adding Comments and Tags +- 🟨 Document Interactions - Adding Comments - 🟨 Import documents from unread emails - 🟨 Video Preview - 🟨 Adding custom metadata fields to document diff --git a/app/db/tables/auth/auth.py b/app/db/tables/auth/auth.py index 625f2d9..b4b2adf 100644 --- a/app/db/tables/auth/auth.py +++ b/app/db/tables/auth/auth.py @@ -17,3 +17,4 @@ class User(Base): nullable=False, server_default=text('now()')) owner_of = relationship("DocumentMetadata", back_populates="owner") + comments = relationship("DocumentComment", back_populates="author") diff --git a/app/db/tables/documents/documents_metadata.py b/app/db/tables/documents/documents_metadata.py index b9b484b..0726a98 100644 --- a/app/db/tables/documents/documents_metadata.py +++ b/app/db/tables/documents/documents_metadata.py @@ -2,7 +2,7 @@ from uuid import uuid4 from typing import List, Optional -from sqlalchemy import Column, String, Integer, ARRAY, text, DateTime, Enum, ForeignKey, Table, UniqueConstraint +from sqlalchemy import Column, String, Integer, ARRAY, text, DateTime, Enum, ForeignKey, Table, UniqueConstraint, Text from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import Mapped, relationship @@ -42,3 +42,30 @@ class DocumentMetadata(Base): update_access = relationship("User", secondary=doc_user_access, passive_deletes=True) owner = relationship("User", back_populates="owner_of") + comments = relationship("DocumentComment", back_populates="document", cascade="all, delete-orphan") + + +class DocumentComment(Base): + __tablename__ = "document_comments" + + id: UUID = Column(UUID(as_uuid=True), default=uuid4, primary_key=True, index=True, nullable=False) + doc_id: UUID = Column(UUID(as_uuid=True), ForeignKey("document_metadata.id", ondelete="CASCADE")) + author_id: str = Column(String, ForeignKey("users.id"), nullable=False) + comment: str = Column(Text, nullable=False) + created_at = Column( + DateTime(timezone=True), + default=datetime.now(timezone.utc), + nullable=False, + server_default=text("NOW()") + ) + updated_at = Column( + DateTime(timezone=True), + default=datetime.now(timezone.utc), + onupdate=datetime.now(timezone.utc), + nullable=False, + server_default=text("NOW()") + ) + + document = relationship("DocumentMetadata", back_populates="comments") + author = relationship("User", back_populates="comments") + diff --git a/migrations/env.py b/migrations/env.py index 21f3484..cb182bb 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -21,7 +21,10 @@ # add your model's MetaData object here # for 'autogenerate' support +from app.db.tables.documents.documents_metadata import DocumentMetadata, DocumentComment +from app.db.tables.auth.auth import User from app.db.tables.documents.document_sharing import DocumentSharing +from app.db.tables.documents.notify import Notify target_metadata = Base.metadata diff --git a/migrations/versions/2a02384ab925_initial_almebic.py b/migrations/versions/2a02384ab925_initial_almebic.py index 58f1595..a07d278 100644 --- a/migrations/versions/2a02384ab925_initial_almebic.py +++ b/migrations/versions/2a02384ab925_initial_almebic.py @@ -21,14 +21,14 @@ def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.create_table('notify', - sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('receiver_id', sa.String(), nullable=False), - sa.Column('message', sa.Text(), nullable=False), - sa.Column('status', sa.Enum('read', 'unread', name='notifyenum'), nullable=True), - sa.Column('notified_at', sa.DateTime(timezone=True), server_default=sa.text('NOW()'), nullable=False), - sa.PrimaryKeyConstraint('id') + sa.Column('id', sa.UUID(), autoincrement=False, nullable=False), + sa.Column('receiver_id', sa.VARCHAR(), autoincrement=False, nullable=False), + sa.Column('message', sa.TEXT(), autoincrement=False, nullable=False), + sa.Column('status', postgresql.ENUM('read', 'unread', name='notifyenum'), autoincrement=False, nullable=True), + sa.Column('notified_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('now()'), autoincrement=False, nullable=False), + sa.PrimaryKeyConstraint('id', name='notify_pkey') ) - op.create_index(op.f('ix_notify_id'), 'notify', ['id'], unique=False) + op.create_index('ix_notify_id', 'notify', ['id'], unique=False) op.create_table('users', sa.Column('id', sa.String(length=26), nullable=False), sa.Column('username', sa.String(), nullable=False), diff --git a/requirements.txt b/requirements.txt index 82fcbbe..05cea07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,19 +1,19 @@ -alembic~=1.12.1 +alembic>=1.12.1 annotated-types==0.6.0 anyio==4.2.0 asyncpg==0.29.0 -boto3~=1.34.34 -botocore~=1.34.34 +boto3>=1.34.34 +botocore>=1.34.34 certifi==2024.7.4 click==8.1.7 colorama==0.4.6 dnspython>=2.6.1 email-validator==2.1.0.post1 -fastapi~=0.109.2 +fastapi>=0.109.2 greenlet==3.0.3 h11==0.14.0 httpcore==0.17.3 -httpx~=0.24.1 +httpx>=0.24.1 idna>=3.7 iniconfig==2.0.0 jmespath==1.0.1 @@ -27,9 +27,9 @@ pyasn1==0.5.1 pydantic~=2.5.3 pydantic-settings==2.1.0 pydantic_core==2.14.6 -pytest~=7.4.4 +pytest>=7.4.4 python-dateutil==2.8.2 -python-dotenv~=1.0.0 +python-dotenv>=1.0.0 python-jose==3.3.0 python-multipart>=0.0.18 python-ulid==2.2.0 @@ -37,7 +37,7 @@ rsa==4.9 s3transfer==0.10.0 six==1.16.0 sniffio==1.3.0 -SQLAlchemy~=1.4.51 +SQLAlchemy>=1.4.51 starlette>=0.40.0 typing_extensions==4.9.0 urllib3>=2.2.2