use sea_orm_migration::prelude::*;
/// Adds `public.video_chapters` and `videos.chapters_status`.
///
/// Chapters are a yt-dlp-only fetch: the Data API cannot see them, so they are
/// stored separately from the video row and written either by the yt-dlp
/// harvest (which already has them in its payload) or by `tango-rs chapters`.
/// The status column mirrors `transcript_status`, including its deliberate lack
/// of a CHECK constraint: the vocabulary is settled by use, not by a migration.
#[derive(DeriveMigrationName)]
pub struct Migration;
const UP: &str = include_str!("sql/0027_video_chapters.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 TABLE IF EXISTS public.video_chapters;
ALTER TABLE public.videos DROP COLUMN IF EXISTS chapters_status;
"#,
)
.await?;
Ok(())
}
}