tango-core 0.3.0

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

/// Makes fuzzy title matching match whole words instead of fragments.
///
/// The gate was `word_similarity(query, title) > 0.3`, and 0.3 turned out to be
/// exactly the floor rather than above it: for the query `podracing` every
/// title containing the word "Podcast" scores precisely 0.300, because "pod" is
/// the query's first trigram. On 8,748 harvested videos that admitted 737
/// results — 31 pages of a podcast back catalogue — for a query whose two real
/// answers were rows 1 and 2 of page 1.
///
/// `strict_word_similarity` only considers extents bounded by non-word
/// characters, so the same query drops to 23 hits, and a genuine typo is
/// unaffected: `spder man` against "Blood Pact: Spider-Man (Pt. 1)" scores
/// 0.615 under either scorer, because a typo is a whole-word difference rather
/// than a fragment of one.
///
/// The threshold is left to `pg_trgm.strict_word_similarity_threshold` rather
/// than written into the query, because `<%` is indexable only when the
/// threshold comes from the GUC — which is also what makes the GIN trigram index
/// usable here, something the raw function call never was.
#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = include_str!("sql/0017_strict_fuzzy.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> {
        // A no-op, like 0010 through 0014. Restoring the old gate means inlining
        // a second copy of the search branches, which is the exact duplication
        // 0014 removed; `sql/0014_search_count.sql` stays their single source
        // of truth. A revert leaves search matching strictly, which is worse but
        // not broken, and the next migration to change a function no longer has
        // to copy one to be reversible.
        Ok(())
    }
}