tango-core 0.3.0

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

/// Extends `search_content` to cover transcripts, and gives every hit a
/// `start_ms` to seek to.
///
/// One function rather than a second entry point, so ranking and paging stay
/// in SQL. Paging two result sets and merging them in the application would
/// give wrong totals and wrong pages.
///
/// Two decisions worth stating:
///
///   - Transcripts get their own `match_tier` (0, below the existing 1 and 2)
///     rather than a lower `score`. A title match says the video is *about* X;
///     a transcript match says X was said somewhere in ninety minutes. Merging
///     them onto one numeric scale would let a lucky phrase in a long
///     transcript outrank a precise title match.
///
///   - `include_transcripts` is a separate parameter from `include_fuzzy`.
///     Fuzzy matching is trigram similarity over titles and has a noise floor;
///     transcript matching is real full-text and is precise. `--no-fuzzy` is a
///     request for precision and should not discard the precise tier with it.
///
/// The previous definition is not inlined into `down`. It is 200 lines of
/// function body, and a second copy of it would silently drift from
/// `sql/0005_search.sql`; the file remains the single source of truth.
#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = include_str!("sql/0011_search_transcripts.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> {
        // Deliberately a no-op, like 0006.
        //
        // Restoring the previous definition would mean inlining 200 lines of
        // function body, and that copy would drift from `sql/0005_search.sql`
        // - which stays the single source of truth for it. The function is
        // untouched by the revert, so search still works; it simply does not go
        // back to covering only titles and descriptions.
        Ok(())
    }
}