postgres_schema.sql
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
create extension if not exists pg_trgm;
create table if not exists lyrics (
id bigserial primary key,
record_id text not null unique,
source_path text not null,
title text,
artist text,
raw_text text not null,
normalized_text text not null,
primary_text text not null,
translation_text text,
exact_hash text not null,
split_confidence text,
split_reason text,
line_count integer not null,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now(),
deleted_at timestamptz
);
create index if not exists lyrics_exact_hash_idx
on lyrics (exact_hash)
where deleted_at is null;
create index if not exists lyrics_primary_text_trgm_idx
on lyrics using gin (primary_text gin_trgm_ops);
create table if not exists lyric_lines (
lyric_id bigint not null references lyrics(id) on delete cascade,
role text not null,
line_no integer not null,
normalized_line text not null,
line_hash text not null,
primary key (lyric_id, role, line_no)
);
create index if not exists lyric_lines_hash_idx
on lyric_lines (line_hash);
create index if not exists lyric_lines_lyric_id_idx
on lyric_lines (lyric_id);
create extension if not exists vector;
create table if not exists composition_feature (
id bigserial primary key,
song_id bigint not null unique,
feature_vector vector(1536) not null,
created_at timestamptz not null default now()
);
create index if not exists composition_feature_hnsw_idx
on composition_feature
using hnsw (feature_vector vector_cosine_ops)
with (m = 16, ef_construction = 64);
create table if not exists dejavu_fingerprints (
id bigserial primary key,
song_id bigint not null references composition_feature(song_id) on delete cascade,
hash bytea not null,
"offset" int not null
);
create index if not exists idx_fingerprints_hash
on dejavu_fingerprints (hash);
create index if not exists idx_fingerprints_hash_song_offset
on dejavu_fingerprints (hash, song_id, "offset");
create index if not exists idx_fingerprints_song_id
on dejavu_fingerprints (song_id);