diff --git a/src/music/mod.rs b/src/music/mod.rs index e8323e7..5349a56 100644 --- a/src/music/mod.rs +++ b/src/music/mod.rs @@ -3012,6 +3012,46 @@ pub mod db_migrations { .build()]; } + // -- M0058: local privacy confirmations of shared podcasts ------------- + + // Client-held `privacy_confirmed` of public podcast discovery (MR-W3); + // see `crate::podcasts::discovery`. Never synced. + #[cot::db::migrations::migration_op] + async fn create_podcast_share_confirmation( + ctx: migrations::MigrationContext<'_>, + ) -> cot::db::Result<()> { + for sql in crate::podcasts::schema::CREATE_SHARE_CONFIRMATION { + ctx.db.raw(sql).await?; + } + Ok(()) + } + + #[cot::db::migrations::migration_op] + async fn drop_podcast_share_confirmation( + ctx: migrations::MigrationContext<'_>, + ) -> cot::db::Result<()> { + for sql in crate::podcasts::schema::DROP_SHARE_CONFIRMATION { + ctx.db.raw(sql).await?; + } + Ok(()) + } + + #[derive(Debug, Copy, Clone)] + pub struct M0058CreatePodcastShareConfirmation; + impl migrations::Migration for M0058CreatePodcastShareConfirmation { + const APP_NAME: &'static str = "furumusic"; + const MIGRATION_NAME: &'static str = "m_0058_create_podcast_share_confirmation"; + const DEPENDENCIES: &'static [migrations::MigrationDependency] = + &[migrations::MigrationDependency::migration( + "furumusic", + "m_0057_import_podcast_relay", + )]; + const OPERATIONS: &'static [Operation] = + &[Operation::custom(create_podcast_share_confirmation) + .backwards(drop_podcast_share_confirmation) + .build()]; + } + pub const MIGRATIONS: &[&SyncDynMigration] = &[ &M0006CreateMediaFile, &M0007CreateArtist, @@ -3059,5 +3099,6 @@ pub mod db_migrations { &M0055CreateFedPodcastRelay, &M0056CreatePodcastStore, &M0057ImportPodcastRelay, + &M0058CreatePodcastShareConfirmation, ]; } diff --git a/src/podcasts/schema.rs b/src/podcasts/schema.rs index 9890041..df97c2e 100644 --- a/src/podcasts/schema.rs +++ b/src/podcasts/schema.rs @@ -1,9 +1,10 @@ //! PostgreSQL schema of the podcast store and the import of the relay state. //! //! The migrations themselves are declared in `crate::music::db_migrations` -//! (`m_0056_create_podcast_store`, `m_0057_import_podcast_relay`), next to -//! the rest of the `furumusic` chain; this module holds their SQL so the -//! store and its tests share one definition. +//! (`m_0056_create_podcast_store`, `m_0057_import_podcast_relay`, +//! `m_0058_create_podcast_share_confirmation`), next to the rest of the +//! `furumusic` chain; this module holds their SQL so the store and its tests +//! share one definition. //! //! The tables mirror the SQLite reference store of `furumi-library` //! (`PODCASTS.md`, "SQLite reference store") with a `user_id` column in @@ -174,6 +175,31 @@ pub(crate) const DROP_PODCAST_STORE: &[&str] = &[ "DROP TABLE IF EXISTS furumusic__podcast", ]; +/// Local privacy confirmations of shared podcasts (`m_0058`). +/// +/// `PodcastShareState::privacy_confirmed` is client-held state (frid +/// `PODCASTS.md`, "Publication"): it is never synced and never part of a +/// snapshot. A row records that the account confirmed publishing exactly +/// `feed_url` / `id_feed_url` for exactly the share decision `share_op_id` +/// despite `PodcastCardSpec::privacy_warnings`. A new share decision (on any +/// device) or a feed move to other URLs makes the row stale, so the user is +/// asked again (see `crate::podcasts::discovery`). +pub(crate) const CREATE_SHARE_CONFIRMATION: &[&str] = &[ + "CREATE TABLE IF NOT EXISTS furumusic__podcast_share_confirmation ( + user_id BIGINT NOT NULL, + podcast_id TEXT NOT NULL, + share_op_id TEXT NOT NULL, + feed_url TEXT NOT NULL, + id_feed_url TEXT, + confirmed_at_ms BIGINT NOT NULL, + PRIMARY KEY (user_id, podcast_id) + )", +]; + +/// Backwards operation of [`CREATE_SHARE_CONFIRMATION`]. +pub(crate) const DROP_SHARE_CONFIRMATION: &[&str] = + &["DROP TABLE IF EXISTS furumusic__podcast_share_confirmation"]; + /// Placeholder in [`IMPORT_PODCAST_RELAY`] for the account filter: the /// migration imports every account (`TRUE`), tests narrow it to one. pub(crate) const USER_FILTER: &str = "{user_filter}"; @@ -318,7 +344,12 @@ mod tests { #[test] fn every_store_table_is_dropped_backwards() { - for sql in CREATE_PODCAST_STORE { + let drops: Vec<&str> = DROP_PODCAST_STORE + .iter() + .chain(DROP_SHARE_CONFIRMATION) + .copied() + .collect(); + for sql in CREATE_PODCAST_STORE.iter().chain(CREATE_SHARE_CONFIRMATION) { let Some(rest) = sql .strip_prefix("CREATE TABLE IF NOT EXISTS ") .or_else(|| sql.strip_prefix("CREATE OR REPLACE VIEW ")) @@ -327,9 +358,7 @@ mod tests { }; let name = rest.split_whitespace().next().unwrap(); assert!( - DROP_PODCAST_STORE - .iter() - .any(|drop| drop.ends_with(&format!(" {name}"))), + drops.iter().any(|drop| drop.ends_with(&format!(" {name}"))), "{name}" ); }