tango-core 0.3.0

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

/// Gives search an exact count, by splitting the matching rules out of the
/// paging.
///
/// `search_content` did its own paging, so a caller had no way to know how many
/// matches there were in total — which is what a pager needs. The obvious fix is
/// a counting function, and the obvious problem is that it is a second copy of
/// the four search branches, free to drift from the first. The reference
/// implementation solved this with a `search_content_count` RPC written
/// alongside its search RPC, which is the same duplication.
///
/// So nothing is copied. The branches move into `search_all_hits`, and both
/// wrappers read from it: one pages, one counts. The total and the page are
/// then the same query by construction rather than by review.
///
/// A composite type, not `RETURNS TABLE`, because `RETURNS TABLE` turns its
/// column names into plpgsql variables — which is what forced the original to
/// route every UNION through a derived table purely to qualify its ORDER BY.
#[derive(DeriveMigrationName)]
pub struct Migration;

const UP: &str = include_str!("sql/0014_search_count.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 0012 - but this migration is what makes
        // that pattern end. The previous definition is
        // `sql/0012_transcript_seek_position.sql`, and inlining it here would
        // be a fourth copy of the same branches, which is the exact problem
        // being fixed.
        //
        // After this, a change to what search matches edits `search_all_hits`
        // and nothing else, so the next migration to need a real reverse is a
        // small one.
        Ok(())
    }
}