diff --git a/db_schema/migrations/12_apple_aggregated_data.sql b/db_schema/migrations/12_apple_aggregated_data.sql new file mode 100644 index 00000000..46078c57 --- /dev/null +++ b/db_schema/migrations/12_apple_aggregated_data.sql @@ -0,0 +1,28 @@ +INSERT INTO migrations (migration_id, migration_name) VALUES (12, 'apple aggregated data'); + +-- aggreagated values per episode coming from the apple trends api +CREATE TABLE IF NOT EXISTS appleTrendsEpisodeListenersAggregated ( + account_id INTEGER NOT NULL, + episode_id BIGINT NOT NULL, + date_start DATE NOT NULL, + date_end DATE NOT NULL, + atl_playscount INTEGER NOT NULL, + atl_totaltimelistened BIGINT NOT NULL, + atl_uniqueengagedlistenerscount INTEGER NOT NULL, + atl_uniquelistenerscount INTEGER NOT NULL, + updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + PRIMARY KEY (account_id, episode_id, date_start, date_end) +); + +-- aggreagated values per podcast coming from the apple trends api +CREATE TABLE IF NOT EXISTS appleTrendsPodcastListenersAggregated ( + account_id INTEGER NOT NULL, + date_start DATE NOT NULL, + date_end DATE NOT NULL, + atl_playscount INTEGER NOT NULL, + atl_totaltimelistened BIGINT NOT NULL, + atl_uniqueengagedlistenerscount INTEGER NOT NULL, + atl_uniquelistenerscount INTEGER NOT NULL, + updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + PRIMARY KEY (account_id, date_start, date_end) +); diff --git a/db_schema/schema.sql b/db_schema/schema.sql index 5f8f64b5..bec7be0e 100644 --- a/db_schema/schema.sql +++ b/db_schema/schema.sql @@ -17,7 +17,7 @@ CREATE TABLE IF NOT EXISTS migrations ( -- ----------------------------------------- -- IMPORTANT: this is the schema version -- ID has to be incremented for each change -INSERT INTO migrations (migration_id, migration_name) VALUES (11, 'anchor episodesPage'); +INSERT INTO migrations (migration_id, migration_name) VALUES (12, 'apple aggregated data'); -- ----------------------------------------- CREATE TABLE IF NOT EXISTS events ( @@ -197,6 +197,20 @@ CREATE TABLE IF NOT EXISTS appleTrendsEpisodeListeners ( PRIMARY KEY (account_id, episode_id, atl_date) ); +-- aggreagated values per episode coming from the apple trends api +CREATE TABLE IF NOT EXISTS appleTrendsEpisodeListenersAggregated ( + account_id INTEGER NOT NULL, + episode_id BIGINT NOT NULL, + date_start DATE NOT NULL, + date_end DATE NOT NULL, + atl_playscount INTEGER NOT NULL, + atl_totaltimelistened BIGINT NOT NULL, + atl_uniqueengagedlistenerscount INTEGER NOT NULL, + atl_uniquelistenerscount INTEGER NOT NULL, + updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + PRIMARY KEY (account_id, episode_id, date_start, date_end) +); + -- listeners values per day and per podcast coming from the apple trends api CREATE TABLE IF NOT EXISTS appleTrendsPodcastListeners ( account_id INTEGER NOT NULL, @@ -208,6 +222,19 @@ CREATE TABLE IF NOT EXISTS appleTrendsPodcastListeners ( PRIMARY KEY (account_id, atl_date) ); +-- aggreagated values per podcast coming from the apple trends api +CREATE TABLE IF NOT EXISTS appleTrendsPodcastListenersAggregated ( + account_id INTEGER NOT NULL, + date_start DATE NOT NULL, + date_end DATE NOT NULL, + atl_playscount INTEGER NOT NULL, + atl_totaltimelistened BIGINT NOT NULL, + atl_uniqueengagedlistenerscount INTEGER NOT NULL, + atl_uniquelistenerscount INTEGER NOT NULL, + updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + PRIMARY KEY (account_id, date_start, date_end) +); + -- store totallistened time for followers and nonfollowers CREATE TABLE IF NOT EXISTS appleTrendsPodcastListeningTimeFollowerState ( account_id INTEGER NOT NULL,