feat: datenmodell für clips
- Tabelle clips mit Art (text/code), Titel, Inhalt, Sprache, angeheftet, version - feste Sprachliste passend zu highlight.js (Migration 0003) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
66fe8feea4
commit
f1bfa27ba3
4 files changed
+123
-1
No files matched your search
@@ -0,0 +1,33 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Enum, ForeignKey, Index, String, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, UTCDateTime, utcnow
|
||||
|
||||
|
||||
class ClipKind(enum.StrEnum):
|
||||
TEXT = "text"
|
||||
CODE = "code"
|
||||
|
||||
|
||||
class Clip(Base):
|
||||
__tablename__ = "clips"
|
||||
__table_args__ = (Index("ix_clips_user_order", "user_id", "pinned", "updated_at"),)
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
kind: Mapped[ClipKind] = mapped_column(
|
||||
Enum(ClipKind, native_enum=False, length=16, values_callable=lambda e: [m.value for m in e])
|
||||
)
|
||||
title: Mapped[str | None] = mapped_column(String(200))
|
||||
content: Mapped[str] = mapped_column(Text)
|
||||
language: Mapped[str | None] = mapped_column(String(32))
|
||||
pinned: Mapped[bool] = mapped_column(default=False)
|
||||
# Incremented on every change; clients send it back to detect concurrent edits
|
||||
version: Mapped[int] = mapped_column(default=1)
|
||||
created_at: Mapped[datetime] = mapped_column(UTCDateTime, default=utcnow)
|
||||
updated_at: Mapped[datetime] = mapped_column(UTCDateTime, default=utcnow)
|
||||
Reference in new issue
Block a user