-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.py
More file actions
30 lines (23 loc) · 1.32 KB
/
note.py
File metadata and controls
30 lines (23 loc) · 1.32 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
from sqlalchemy import Column, Integer, String, Text, Boolean, ForeignKey, TIMESTAMP, text
from sqlalchemy.orm import relationship
from .base import Base
class Note(Base):
__tablename__ = "note"
id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer, ForeignKey("user.u_id", ondelete="CASCADE"), nullable=False)
folder_id = Column(Integer, ForeignKey("folder.id", ondelete="SET NULL"), nullable=True)
title = Column(String(255), nullable=False)
content = Column(Text)
is_favorite = Column(Boolean, nullable=False, server_default=text("FALSE"))
last_accessed = Column(TIMESTAMP, nullable=True)
created_at = Column(TIMESTAMP, nullable=False, server_default=text("CURRENT_TIMESTAMP"))
updated_at = Column(TIMESTAMP, nullable=False,
server_default=text('CURRENT_TIMESTAMP'),
onupdate=text('CURRENT_TIMESTAMP'))
# ✅ 관계
server_default=text("CURRENT_TIMESTAMP"),
onupdate=text("CURRENT_TIMESTAMP"))
# relations
user = relationship("User", back_populates="notes")
folder = relationship("Folder", back_populates="notes")
files = relationship("File", back_populates="note", cascade="all, delete")