tango-core 0.3.0

The tango schema, entities, migrations, and search contract
Documentation
use sea_orm_migration::prelude::*;

/// Records whether a video has captions at all, which the Data API reports for
/// free in `contentDetails.caption`.
///
/// `subtitle_availability` (0008) says which languages exist, and the v3
/// backend cannot fill it — the track list needs a `captions.list` call per
/// video at 50 quota units each. It could, however, report the yes/no, and was
/// discarding it: the response model captured only `duration` from a section it
/// was already requesting.
///
/// The value is skipping. Without it a transcript workflow spends an ~11s
/// yt-dlp call to learn a video has no captions. With it, `false` is a skip and
/// `NULL` is still "worth attempting", so a planner must not read the unknown
/// state as a no.
///
/// Idempotent, and backfills the boolean for videos already harvested through
/// yt-dlp, where the availability lists make it derivable. Rows with NULL
/// availability are left NULL rather than guessed.
#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = include_str!("sql/0009_captions_available.sql");

#[async_trait::async_trait]
impl MigrationTrait for Migration {
    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        manager.get_connection().execute_unprepared(UP).await?;
        Ok(())
    }

    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
        // Reversible without a guard: unlike the transcript tables, this
        // column is derivable. Dropping it loses only a fact the next harvest
        // re-establishes, and `subtitle_availability` is untouched.
        manager
            .get_connection()
            .execute_unprepared(
                r#"
                ALTER TABLE public.videos DROP COLUMN IF EXISTS captions_available;
                "#,
            )
            .await?;
        Ok(())
    }
}