-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #747 from podverse/develop
Release v4.16.14
- Loading branch information
Showing
22 changed files
with
628 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-- Create the function to set timestamps with triggers | ||
|
||
CREATE FUNCTION set_timestamps() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
NEW."updatedAt" := NOW(); | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
-- Timeframe enum | ||
CREATE TYPE timeframe_enum AS ENUM ('daily', 'weekly', 'monthly', 'yearly', 'all_time'); | ||
|
||
-- Podcasts Stats | ||
CREATE TABLE IF NOT EXISTS stats_podcast ( | ||
id SERIAL PRIMARY KEY, | ||
play_count INTEGER DEFAULT 0, | ||
timeframe timeframe_enum NOT NULL, | ||
podcast_id VARCHAR NOT NULL REFERENCES podcasts(id) ON DELETE CASCADE, | ||
CONSTRAINT unique_timeframe_podcast UNIQUE (timeframe, podcast_id), | ||
"createdAt" timestamp without time zone DEFAULT now() NOT NULL, | ||
"updatedAt" timestamp without time zone DEFAULT now() NOT NULL | ||
); | ||
|
||
CREATE INDEX "stats_podcast_play_count_idx" ON stats_podcast (play_count); | ||
CREATE INDEX "stats_podcast_timeframe_idx" ON stats_podcast (timeframe); | ||
CREATE INDEX "stats_podcast_podcast_id_idx" ON stats_podcast (podcast_id); | ||
CREATE INDEX "stats_podcast_updated_at" on stats_podcast ("updatedAt"); | ||
|
||
CREATE TRIGGER set_timestamps_before_insert | ||
BEFORE INSERT ON stats_podcast | ||
FOR EACH ROW | ||
EXECUTE FUNCTION set_timestamps(); | ||
|
||
CREATE TRIGGER set_timestamps_before_update | ||
BEFORE UPDATE ON stats_podcast | ||
FOR EACH ROW | ||
EXECUTE FUNCTION set_timestamps(); | ||
|
||
-- Episodes Stats | ||
CREATE TABLE IF NOT EXISTS stats_episode ( | ||
id SERIAL PRIMARY KEY, | ||
play_count INTEGER DEFAULT 0, | ||
timeframe timeframe_enum NOT NULL, | ||
episode_id VARCHAR NOT NULL REFERENCES episodes(id) ON DELETE CASCADE, | ||
CONSTRAINT unique_timeframe_episode UNIQUE (timeframe, episode_id), | ||
"createdAt" timestamp without time zone DEFAULT now() NOT NULL, | ||
"updatedAt" timestamp without time zone DEFAULT now() NOT NULL | ||
); | ||
|
||
CREATE INDEX "stats_episode_play_count_idx" ON stats_episode (play_count); | ||
CREATE INDEX "stats_episode_timeframe_idx" ON stats_episode (timeframe); | ||
CREATE INDEX "stats_episode_episode_id_idx" ON stats_episode (episode_id); | ||
CREATE INDEX "stats_episode_updated_at" on stats_episode ("updatedAt"); | ||
|
||
CREATE TRIGGER set_timestamps_before_insert | ||
BEFORE INSERT ON stats_episode | ||
FOR EACH ROW | ||
EXECUTE FUNCTION set_timestamps(); | ||
|
||
CREATE TRIGGER set_timestamps_before_update | ||
BEFORE UPDATE ON stats_episode | ||
FOR EACH ROW | ||
EXECUTE FUNCTION set_timestamps(); | ||
|
||
-- MediaRef Stats | ||
CREATE TABLE IF NOT EXISTS stats_media_ref ( | ||
id SERIAL PRIMARY KEY, | ||
play_count INTEGER DEFAULT 0, | ||
timeframe timeframe_enum NOT NULL, | ||
media_ref_id VARCHAR NOT NULL REFERENCES "mediaRefs"(id) ON DELETE CASCADE, | ||
CONSTRAINT unique_timeframe_media_ref UNIQUE (timeframe, media_ref_id), | ||
"createdAt" timestamp without time zone DEFAULT now() NOT NULL, | ||
"updatedAt" timestamp without time zone DEFAULT now() NOT NULL | ||
); | ||
|
||
CREATE INDEX "stats_media_ref_play_count_idx" ON stats_media_ref (play_count); | ||
CREATE INDEX "stats_media_ref_timeframe_idx" ON stats_media_ref (timeframe); | ||
CREATE INDEX "stats_media_ref_media_ref_id_idx" ON stats_media_ref (media_ref_id); | ||
CREATE INDEX "stats_media_ref_updated_at" on stats_media_ref ("updatedAt"); | ||
|
||
CREATE TRIGGER set_timestamps_before_insert | ||
BEFORE INSERT ON stats_media_ref | ||
FOR EACH ROW | ||
EXECUTE FUNCTION set_timestamps(); | ||
|
||
CREATE TRIGGER set_timestamps_before_update | ||
BEFORE UPDATE ON stats_media_ref | ||
FOR EACH ROW | ||
EXECUTE FUNCTION set_timestamps(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
-- | ||
-- NOTE: THIS MUST ONLY BE RUN AFTER THE NEW API IS DEPLOYED. | ||
-- | ||
|
||
-- Drop the podcasts stats indexes | ||
|
||
DO $$ | ||
DECLARE | ||
index_name TEXT; | ||
BEGIN | ||
FOR index_name IN | ||
SELECT indexname | ||
FROM pg_indexes | ||
WHERE tablename = 'podcasts' | ||
AND ( | ||
indexdef ILIKE '%pastHourTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastDayTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastWeekTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastMonthTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastYearTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastAllTimeTotalUniquePageviews%' | ||
) | ||
LOOP | ||
EXECUTE format('DROP INDEX IF EXISTS %I;', index_name); | ||
END LOOP; | ||
END $$; | ||
|
||
-- Drop the episodes stats indexes | ||
|
||
DO $$ | ||
DECLARE | ||
index_name TEXT; | ||
BEGIN | ||
FOR index_name IN | ||
SELECT indexname | ||
FROM pg_indexes | ||
WHERE tablename = 'episodes' | ||
AND ( | ||
indexdef ILIKE '%pastHourTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastDayTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastWeekTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastMonthTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastYearTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastAllTimeTotalUniquePageviews%' | ||
) | ||
LOOP | ||
EXECUTE format('DROP INDEX IF EXISTS %I;', index_name); | ||
END LOOP; | ||
END $$; | ||
|
||
-- Drop the mediaRefs stats indexes | ||
|
||
DO $$ | ||
DECLARE | ||
index_name TEXT; | ||
BEGIN | ||
FOR index_name IN | ||
SELECT indexname | ||
FROM pg_indexes | ||
WHERE tablename = 'mediaRefs' | ||
AND ( | ||
indexdef ILIKE '%pastHourTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastDayTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastWeekTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastMonthTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastYearTotalUniquePageviews%' | ||
OR indexdef ILIKE '%pastAllTimeTotalUniquePageviews%' | ||
) | ||
LOOP | ||
EXECUTE format('DROP INDEX IF EXISTS %I;', index_name); | ||
END LOOP; | ||
END $$; | ||
|
||
-- Drop old podcast stats columns | ||
|
||
ALTER TABLE podcasts | ||
DROP COLUMN "pastHourTotalUniquePageviews"; | ||
|
||
ALTER TABLE podcasts | ||
DROP COLUMN "pastDayTotalUniquePageviews"; | ||
|
||
ALTER TABLE podcasts | ||
DROP COLUMN "pastWeekTotalUniquePageviews"; | ||
|
||
ALTER TABLE podcasts | ||
DROP COLUMN "pastMonthTotalUniquePageviews"; | ||
|
||
ALTER TABLE podcasts | ||
DROP COLUMN "pastYearTotalUniquePageviews"; | ||
|
||
ALTER TABLE podcasts | ||
DROP COLUMN "pastAllTimeTotalUniquePageviews"; | ||
|
||
-- Drop old episode stats columns | ||
-- First drop the dependent materialized view | ||
|
||
DROP MATERIALIZED VIEW "episodes_most_recent"; | ||
|
||
ALTER TABLE episodes | ||
DROP COLUMN "pastHourTotalUniquePageviews"; | ||
|
||
ALTER TABLE episodes | ||
DROP COLUMN "pastDayTotalUniquePageviews"; | ||
|
||
ALTER TABLE episodes | ||
DROP COLUMN "pastWeekTotalUniquePageviews"; | ||
|
||
ALTER TABLE episodes | ||
DROP COLUMN "pastMonthTotalUniquePageviews"; | ||
|
||
ALTER TABLE episodes | ||
DROP COLUMN "pastYearTotalUniquePageviews"; | ||
|
||
ALTER TABLE episodes | ||
DROP COLUMN "pastAllTimeTotalUniquePageviews"; | ||
|
||
-- Drop old mediaRefs stats columns | ||
|
||
DROP MATERIALIZED VIEW "mediaRefs_videos"; | ||
|
||
ALTER TABLE "mediaRefs" | ||
DROP COLUMN "pastHourTotalUniquePageviews"; | ||
|
||
ALTER TABLE "mediaRefs" | ||
DROP COLUMN "pastDayTotalUniquePageviews"; | ||
|
||
ALTER TABLE "mediaRefs" | ||
DROP COLUMN "pastWeekTotalUniquePageviews"; | ||
|
||
ALTER TABLE "mediaRefs" | ||
DROP COLUMN "pastMonthTotalUniquePageviews"; | ||
|
||
ALTER TABLE "mediaRefs" | ||
DROP COLUMN "pastYearTotalUniquePageviews"; | ||
|
||
ALTER TABLE "mediaRefs" | ||
DROP COLUMN "pastAllTimeTotalUniquePageviews"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- Optionally could be done CONCURRENTLY | ||
|
||
-- drop episodes.mediaUrl index | ||
DROP INDEX "IDX_da6fc438d37c65927437b3107f"; | ||
|
||
-- drop episodes.title index | ||
DROP INDEX "IDX_acd3fd6c4dff47ee1cd00ac582"; | ||
|
||
-- drop podcasts.title index | ||
DROP INDEX "IDX_a65598c2450c4f601ecb341994"; | ||
|
||
-- drop podcasts.shrunkImageLastUpdated index | ||
DROP INDEX "IDX_30403fff476188bfb18fd38f10"; | ||
|
||
--drop podcasts.feedLastUpdated index | ||
DROP INDEX "IDX_09ae4505e3b4b2ddb27486187a"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.