Files
Levyraati26_go/migrations/001_init.sql
T
Esa Kataja 400b5d3833 Release 2026.08.01-1
Lyrics, versioning, and the song page's fact line.

- Lyrics are suggested at submission and never imposed: the worker makes one
  LRCLIB lookup, and Hae sanoitukset re-queries with whatever title and artist
  are typed. Neither overwrites what the submitter wrote. They live on the
  submission, travel to the song at publish, and stay editable after the song
  locks — the lock freezes what a song claims to be, and nobody reviewed the
  lyrics
- The review strip reads and writes side by side: lyrics left, review right.
  Synced LRC highlights the playing line and seeks on click; plain text scrolls
  continuously with a nudge knob. Following can be turned off
- CalVer YYYY.MM.DD-N, injected from the git tag with -ldflags, shown in the
  footer, the startup log and /healthz
- The song page's metadata became four labelled cells instead of one flat run
  of five different kinds of fact

Fixes: publishing wiped lyrics the worker had just fetched (a request that
omitted a field cleared it), lyric auto-scroll landed in the wrong place, and
the fader shifted the deck sideways at score 100.
2026-08-01 00:45:55 +03:00

92 lines
3.1 KiB
SQL

create table users (
id bigserial primary key,
name text not null,
email text not null unique,
password_hash text not null,
avatar text,
banned boolean not null default false,
created_at timestamptz not null default now()
);
create table sessions (
token text primary key,
user_id bigint not null references users (id) on delete cascade,
idle_ttl interval not null,
expires_at timestamptz not null,
created_at timestamptz not null default now()
);
create index on sessions (user_id);
create table invites (
id bigserial primary key,
code text not null unique,
is_valid boolean not null default true,
created_at timestamptz not null default now()
);
create table songs (
id bigserial primary key,
title text not null,
artist text not null,
genre text not null,
description text,
-- LRC or plain text, told apart by whether the first line starts with '['. Not covered by the
-- lock: nobody reviewed the lyrics.
lyrics text,
audio_file text not null,
duration_seconds integer not null,
source_url text,
submitted_by bigint not null references users (id),
created_at timestamptz not null default now()
);
create index on songs (created_at desc);
create table submissions (
id bigserial primary key,
user_id bigint not null references users (id) on delete cascade,
status text not null default 'queued',
status_msg text,
source_url text,
tmp_path text,
title text,
artist text,
genre text,
description text,
lyrics text,
created_at timestamptz not null default now(),
constraint submissions_status check (
status in ('queued', 'downloading', 'converting', 'ready', 'failed')
)
);
-- The submission quota (5 per rolling 24h, failures excluded) reads this.
create index on submissions (user_id, created_at desc);
create table reviews (
id bigserial primary key,
song_id bigint not null references songs (id) on delete cascade,
reviewer_id bigint not null references users (id),
score integer not null check (score between 1 and 100),
text text not null,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now(),
unique (song_id, reviewer_id)
);
create index on reviews (song_id);
-- The queue asks "songs this member has not reviewed" — that lookup is by reviewer.
create index on reviews (reviewer_id, song_id);
create table reports (
id bigserial primary key,
user_id bigint not null references users (id) on delete cascade,
body text not null,
page text,
user_agent text,
resolved_at timestamptz,
created_at timestamptz not null default now()
);