tango-core 0.3.0

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

/// Names the public RPC contract, so a caller can assert which revision of it a
/// database implements.
///
/// The functions in this schema are a public interface, not an implementation
/// detail of `tango-api`: a database plus the harvester is a supported install,
/// and someone building their own HTTP layer around `search_transcripts` is the
/// case the split into functions was for. Nothing in the interface told them
/// which revision they had.
///
/// `require_all` is the argument for versioning by hand rather than inferring it
/// from the migration list. 0023 redefined it - every term in one cue became
/// every term anywhere in the video - and moved the `context_matches` window
/// from +-30 s to +-300 s. A caller's compiled-in signature was unaffected and
/// their results changed anyway. `seaql_migrations` records that something was
/// applied; it cannot say whether it was allowed to change what a caller sees.
///
/// So the number is a promise maintained by hand: a migration that changes a
/// public signature, its semantics, or a documented result column updates this
/// function in the same migration. `docs/rpc.md` carries the same rule and the
/// table of what each version means.
#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = include_str!("sql/0024_contract_version.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 real reverse, unlike 0010 onwards. Reverting a widened window needs
        // the previous definition of a 200-line function, which is why those are
        // no-ops; reverting this is one drop, and a reverted schema should not
        // keep advertising a contract it no longer implements.
        manager
            .get_connection()
            .execute_unprepared("DROP FUNCTION IF EXISTS public.tango_contract_version();")
            .await?;
        Ok(())
    }
}