chore(*.sql): use sql-formatter for sql formatting

This commit is contained in:
Cory Dransfeldt 2025-06-14 17:10:41 -07:00
parent 753f3433ce
commit a650f1d3e8
No known key found for this signature in database
63 changed files with 4432 additions and 2358 deletions

View file

@ -1,17 +1,30 @@
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
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;
RETURN OLD;
END;

View file

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

View file

@ -1,5 +1,10 @@
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();
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

@ -1,5 +1,4 @@
CREATE OR REPLACE FUNCTION update_scheduled_episode_status()
RETURNS TRIGGER AS $$
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';

View file

@ -1,17 +1,30 @@
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
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;
RETURN NEW;
END;