forked from microsoft/github-copilot-vibe-coding-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
39 lines (27 loc) · 1.51 KB
/
Copy pathmodels.py
File metadata and controls
39 lines (27 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey, func
from sqlalchemy.orm import relationship
from database import Base
class Post(Base):
__tablename__ = "posts"
id = Column(String, primary_key=True, index=True)
username = Column(String, nullable=False)
content = Column(String, nullable=False)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
comments = relationship("Comment", back_populates="post", cascade="all, delete-orphan")
likes = relationship("Like", back_populates="post", cascade="all, delete-orphan")
class Comment(Base):
__tablename__ = "comments"
id = Column(String, primary_key=True, index=True)
post_id = Column(String, ForeignKey("posts.id", ondelete="CASCADE"), nullable=False)
username = Column(String, nullable=False)
content = Column(String, nullable=False)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
post = relationship("Post", back_populates="comments")
class Like(Base):
__tablename__ = "likes"
post_id = Column(String, ForeignKey("posts.id", ondelete="CASCADE"), primary_key=True)
username = Column(String, primary_key=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
post = relationship("Post", back_populates="likes")