tango-core 0.3.0

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

/// Unified search over videos and playlists.
///
/// Two tiers: full-text matches always rank above fuzzy title matches, because
/// `ts_rank` and `similarity` are not on the same scale and mixing them in one
/// ORDER BY put fuzzy hits first.
#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = include_str!("sql/0005_search.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> {
        manager
            .get_connection()
            .execute_unprepared(
                r#"
                DROP FUNCTION IF EXISTS public.search_content(text, int, int, boolean, text, regconfig, boolean);
                DROP INDEX IF EXISTS public.videos_title_trgm_idx;
                DROP INDEX IF EXISTS public.playlists_title_trgm_idx;
                "#,
            )
            .await?;
        Ok(())
    }
}