tango-core 0.3.0

The tango schema, entities, migrations, and search contract
Documentation
//! Schema migrations.
//!
//! Each migration embeds its SQL from `sql/` at compile time, so there is one
//! copy of every statement and the migrations are the only source of truth for
//! the schema. `docs/initial_schema.sql` was that file; it is gone now that
//! `tango-rs migrate` applies a real, versioned sequence.
//!
//! On PostgreSQL each migration runs inside its own transaction, so a failure
//! part-way through leaves the database as it was rather than half migrated.
//!
//! Migrations are historical. `m20260101_000001_create_schema` deliberately does
//! not contain the columns added by 0002 and 0003, so that replaying the
//! sequence against an existing database reproduces the real order of change.
//!
//! Released migrations are frozen. `migrations.lock` records a SHA-256 of every
//! SQL file at release time, and `tests/migration_lock.rs` fails when one
//! changes: the ledger records a migration's *name*, never its content, so an
//! edit to a released migration is invisible at runtime - every deployed
//! database keeps the old behaviour while a fresh replay produces something
//! else. A migration that is not in the lock yet is unreleased and may still
//! change.

use sea_orm_migration::prelude::*;

pub struct Migrator;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
    fn migrations() -> Vec<Box<dyn MigrationTrait>> {
        vec![
            Box::new(m20260101_000001_create_schema::Migration),
            Box::new(m20260101_000002_channel_metadata_and_source_tab::Migration),
            Box::new(m20260101_000003_duration_seconds::Migration),
            Box::new(m20260101_000004_resumable_harvests::Migration),
            Box::new(m20260101_000005_search::Migration),
            Box::new(m20260101_000006_drop_stale_search_overloads::Migration),
            Box::new(m20260101_000007_transcript_schema_reconciliation::Migration),
            Box::new(m20260101_000008_subtitle_availability_and_transcript_source::Migration),
            Box::new(m20260101_000009_captions_available::Migration),
            Box::new(m20260101_0010_availability_track_urls::Migration),
            Box::new(m20260101_0011_search_transcripts::Migration),
            Box::new(m20260101_0012_transcript_seek_position::Migration),
            Box::new(m20260101_0013_backfill_captions_available::Migration),
            Box::new(m20260101_0014_search_count::Migration),
            Box::new(m20260101_0015_captions_available_meaning::Migration),
            Box::new(m20260101_0016_harvest_filter_identity::Migration),
            Box::new(m20260101_0017_strict_fuzzy::Migration),
            Box::new(m20260101_0018_search_fields::Migration),
            Box::new(m20260101_0019_search_sort::Migration),
            Box::new(m20260101_0020_search_metadata_only::Migration),
            Box::new(m20260101_0021_transcript_search_perf::Migration),
            Box::new(m20260101_0022_transcript_search_relevance::Migration),
            Box::new(m20260101_0023_discussion_density::Migration),
            Box::new(m20260101_0024_contract_version::Migration),
            Box::new(m20260101_0025_drop_stray_search_transcripts_old::Migration),
            Box::new(m20260101_0026_channels_product_columns::Migration),
            Box::new(m20260101_0027_video_chapters::Migration),
        ]
    }
}

/// Applies every pending migration.
pub async fn up(db: &sea_orm::DatabaseConnection) -> Result<(), DbErr> {
    <Migrator as MigratorTrait>::up(db, None).await
}

/// Reverts the most recent `steps` migrations.
///
/// Exists so `down` can be tested rather than assumed. Every migration here
/// has a real reverse, which is the property that makes a bad migration
/// recoverable instead of requiring a dropped database.
pub async fn down(db: &sea_orm::DatabaseConnection, steps: u32) -> Result<(), DbErr> {
    <Migrator as MigratorTrait>::down(db, Some(steps)).await
}

/// Everything this binary knows how to apply, oldest first.
pub fn all() -> Vec<String> {
    Migrator::migrations()
        .iter()
        .map(|m| m.name().to_string())
        .collect()
}

/// Migrations defined here that have not been applied.
pub async fn pending(db: &sea_orm::DatabaseConnection) -> Result<Vec<String>, DbErr> {
    Ok(Migrator::get_pending_migrations(db)
        .await?
        .into_iter()
        .map(|m| m.name().to_string())
        .collect())
}

pub mod m20260101_000001_create_schema;
pub mod m20260101_000002_channel_metadata_and_source_tab;
pub mod m20260101_000003_duration_seconds;
pub mod m20260101_000004_resumable_harvests;
pub mod m20260101_000005_search;
pub mod m20260101_000006_drop_stale_search_overloads;
pub mod m20260101_000007_transcript_schema_reconciliation;
pub mod m20260101_000008_subtitle_availability_and_transcript_source;
pub mod m20260101_000009_captions_available;
pub mod m20260101_0010_availability_track_urls;
pub mod m20260101_0011_search_transcripts;
pub mod m20260101_0012_transcript_seek_position;
pub mod m20260101_0013_backfill_captions_available;
pub mod m20260101_0014_search_count;
pub mod m20260101_0015_captions_available_meaning;
pub mod m20260101_0016_harvest_filter_identity;
pub mod m20260101_0017_strict_fuzzy;
pub mod m20260101_0018_search_fields;
pub mod m20260101_0019_search_sort;
pub mod m20260101_0020_search_metadata_only;
pub mod m20260101_0021_transcript_search_perf;
pub mod m20260101_0022_transcript_search_relevance;
pub mod m20260101_0023_discussion_density;
pub mod m20260101_0024_contract_version;
pub mod m20260101_0025_drop_stray_search_transcripts_old;
pub mod m20260101_0026_channels_product_columns;
pub mod m20260101_0027_video_chapters;