Automate diary entries and add photo galleries

This commit is contained in:
kai
2026-08-29 11:58:56 +02:00
parent 0b0b19b53a
commit b2af6c6857
7 changed files with 238 additions and 62 deletions
+12 -1
View File
@@ -213,7 +213,7 @@ CREATE TABLE followed_venues (
CREATE TABLE concert_diary (
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
concert_id INTEGER NOT NULL REFERENCES concerts(id) ON DELETE CASCADE,
rating SMALLINT NOT NULL CHECK (rating BETWEEN 1 AND 5),
rating SMALLINT CHECK (rating BETWEEN 1 AND 5),
favorite_song VARCHAR(255),
notes TEXT,
photo_path TEXT,
@@ -222,6 +222,17 @@ CREATE TABLE concert_diary (
PRIMARY KEY (user_id, concert_id)
);
CREATE TABLE concert_diary_photos (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
concert_id INTEGER NOT NULL REFERENCES concerts(id) ON DELETE CASCADE,
path TEXT NOT NULL UNIQUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_concert_diary_photos_entry
ON concert_diary_photos(user_id, concert_id, created_at);
CREATE TABLE concert_bands (
concert_id INTEGER NOT NULL REFERENCES concerts(id) ON DELETE CASCADE,
band_key VARCHAR(255) NOT NULL,
@@ -0,0 +1,10 @@
ALTER TABLE concert_diary
ALTER COLUMN rating DROP NOT NULL;
INSERT INTO concert_diary (user_id, concert_id)
SELECT ca.user_id, ca.concert_id
FROM concert_attendance ca
JOIN concerts c ON c.id = ca.concert_id
WHERE ca.status = 'attending'
AND COALESCE(c.end_datetime, c.start_datetime) < CURRENT_TIMESTAMP
ON CONFLICT (user_id, concert_id) DO NOTHING;
+16
View File
@@ -0,0 +1,16 @@
CREATE TABLE IF NOT EXISTS concert_diary_photos (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
concert_id INTEGER NOT NULL REFERENCES concerts(id) ON DELETE CASCADE,
path TEXT NOT NULL UNIQUE,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_concert_diary_photos_entry
ON concert_diary_photos(user_id, concert_id, created_at);
INSERT INTO concert_diary_photos (user_id, concert_id, path)
SELECT user_id, concert_id, photo_path
FROM concert_diary
WHERE photo_path IS NOT NULL
ON CONFLICT (path) DO NOTHING;