tango-core 0.3.0

The tango schema, entities, migrations, and search contract
Documentation
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "videos")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: String,
    pub channel_id: String,
    pub title: String,
    #[sea_orm(column_type = "Text")]
    pub description: String,
    pub published_at: DateTimeWithTimeZone,
    pub thumbnail_url: String,
    #[sea_orm(column_type = "JsonBinary", nullable)]
    pub thumbnails: Option<serde_json::Value>,
    /// Whole seconds. Both backends report duration differently on the wire;
    /// the harvester normalizes them before writing.
    pub duration_seconds: Option<i32>,
    #[sea_orm(column_type = "JsonBinary", nullable)]
    pub tags: Option<serde_json::Value>,
    pub category_id: Option<String>,
    pub view_count: Option<i64>,
    pub like_count: Option<i64>,
    pub comment_count: Option<i64>,
    pub default_language: Option<String>,
    pub live_broadcast_content: Option<String>,
    /// Which channel tab this video was harvested from. See ChannelAbout for
    /// why the remaining channel statistics are nullable.
    pub source_tab: Option<String>,
    pub stats_refreshed_at: Option<DateTimeWithTimeZone>,
    /// Caption tracks the yt-dlp backend reported, as `{"manual": [...],
    /// "auto": [...]}`.
    ///
    /// `None` means *unknown*, not *none*. The v3 backend cannot see caption
    /// tracks - it would need a separate quota-costing `captions.list` call per
    /// video - so a v3-only harvest leaves this NULL. A source policy reading
    /// NULL as "this video has no captions" would skip videos that have them,
    /// which is why this is nullable and never defaulted to an empty object.
    #[sea_orm(column_type = "JsonBinary", nullable)]
    pub subtitle_availability: Option<serde_json::Value>,
    /// Whether the video has captions at all, as a yes/no both backends can
    /// answer.
    ///
    /// `Some(false)` is the only value that lets a transcript fetch be skipped.
    /// `None` is unknown - the v3 backend has not asked - and a planner reading
    /// it as "no captions" would skip videos that have them.
    pub captions_available: Option<bool>,
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
    pub transcript_status: String,
    /// Outcome of a chapter fetch: `pending`, `fetched`, `no_chapters`, or
    /// `failed`. Free text with no CHECK, exactly like `transcript_status`.
    ///
    /// `pending` is the insert default and means *unknown*; the v3 backend
    /// cannot see chapters, so a v3-only harvest leaves this pending until
    /// `tango-rs chapters` (or a later yt-dlp harvest) fills it.
    pub chapters_status: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::channel::Entity",
        from = "Column::ChannelId",
        to = "super::channel::Column::Id"
    )]
    Channel,
}

impl Related<super::channel::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Channel.def() // Changed from .into_ref() to .def()
    }
}

impl ActiveModelBehavior for ActiveModel {}