feat: initial commit

This commit is contained in:
Cory Dransfeldt 2025-03-27 16:46:02 -07:00
commit e214116e40
No known key found for this signature in database
253 changed files with 17406 additions and 0 deletions

View file

@ -0,0 +1,20 @@
BEGIN
UPDATE artists
SET total_plays = total_plays - 1
WHERE name_string = OLD.artist_name;
UPDATE albums
SET total_plays = total_plays - 1
WHERE name = OLD.album_name
AND artist_name = OLD.artist_name;
UPDATE genres
SET total_plays = total_plays - 1
WHERE id = (
SELECT genres
FROM artists
WHERE name_string = OLD.artist_name
);
RETURN OLD;
END;

View file

@ -0,0 +1,4 @@
CREATE TRIGGER mark_scheduled_as_watched
AFTER INSERT ON episodes
FOR EACH ROW
EXECUTE FUNCTION update_scheduled_on_watch();

View file

@ -0,0 +1,5 @@
CREATE TRIGGER trigger_update_days_read
AFTER UPDATE OF progress ON books
FOR EACH ROW
WHEN (OLD.progress IS DISTINCT FROM NEW.progress AND (NEW.read_status = 'started' OR NEW.read_status = 'finished'))
EXECUTE FUNCTION update_days_read();

View file

@ -0,0 +1,10 @@
CREATE OR REPLACE FUNCTION update_scheduled_episode_status()
RETURNS TRIGGER AS $$
BEGIN
IF NEW.air_date < CURRENT_DATE AND NEW.status = 'upcoming' THEN
NEW.status := 'aired';
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

View file

@ -0,0 +1,20 @@
BEGIN
UPDATE artists
SET total_plays = total_plays + 1
WHERE name_string = NEW.artist_name;
UPDATE albums
SET total_plays = total_plays + 1
WHERE key = NEW.album_key
AND artist_name = NEW.artist_name;
UPDATE genres
SET total_plays = total_plays + 1
WHERE id = (
SELECT genres
FROM artists
WHERE name_string = NEW.artist_name
);
RETURN NEW;
END;