Skip to content

Commit

Permalink
docuemnt comment table update
Browse files Browse the repository at this point in the history
  • Loading branch information
jiisanda committed Dec 14, 2024
1 parent 48f7324 commit 7d6c748
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/db/tables/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
29 changes: 28 additions & 1 deletion app/db/tables/documents/documents_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")

3 changes: 3 additions & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions migrations/versions/2a02384ab925_initial_almebic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,17 +27,17 @@ 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
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
Expand Down

0 comments on commit 7d6c748

Please sign in to comment.