···11-CREATE TABLE migrations (
22- id INTEGER PRIMARY KEY,
33- name TEXT NOT NULL UNIQUE,
44- applied_at DATE
11+create table migrations (
22+ id integer primary key,
33+ name text not null unique,
44+ applied_at date
55);
6677-CREATE TABLE album (
88- id TEXT PRIMARY KEY,
99- title TEXT NOT NULL UNIQUE,
1010- mb_id TEXT UNIQUE,
1111- mb_rg_id TEXT UNIQUE
77+create table album (
88+ id text primary key,
99+ title text not null unique,
1010+ mb_id text unique,
1111+ mb_rg_id text unique
1212);
13131414-CREATE TABLE artist (
1515- id TEXT PRIMARY KEY,
1616- name TEXT NOT NULL UNIQUE,
1717- mb_id TEXT UNIQUE,
1818- acoust_id TEXT UNIQUE
1414+create table artist (
1515+ id text primary key,
1616+ name text not null unique,
1717+ mb_id text unique,
1818+ acoust_id text unique
1919);
20202121-CREATE TABLE track (
2222- id TEXT PRIMARY KEY,
2323- title TEXT NOT NULL,
2424- track_number INTEGER NOT NULL DEFAULT 0,
2525- mb_id TEXT,
2626- album_id TEXT NOT NULL,
2121+create table track (
2222+ id text primary key,
2323+ title text not null,
2424+ track_number integer not null default 0,
2525+ mb_id text,
2626+ album_id text not null,
27272828- UNIQUE(title, track_number, album_id)
2929- FOREIGN KEY(album_id) REFERENCES album(id) ON DELETE CASCADE
2828+ unique(title, track_number, album_id)
2929+ foreign key(album_id) references album(id) on delete cascade
3030);
31313232-CREATE INDEX track_album_idx ON track(album_id);
3232+create table file (
3333+ id text primary key,
3434+ path text not null unique,
3535+ track_id text not null unique,
33363434-CREATE TABLE artist_track (
3535- artist_id TEXT NOT NULL,
3636- track_id TEXT NOT NULL,
3737+ foreign key (track_id) references track(id)
3838+);
37393838- PRIMARY KEY(artist_id, track_id),
3939- FOREIGN KEY(artist_id) REFERENCES artist(id),
4040- FOREIGN KEY(track_id) REFERENCES track(id)
4040+create index track_album_idx on track(album_id);
4141+4242+create table artist_track (
4343+ artist_id text not null,
4444+ track_id text not null,
4545+4646+ primary key(artist_id, track_id),
4747+ foreign key(artist_id) references artist(id),
4848+ foreign key(track_id) references track(id)
4149);
42504343-CREATE TABLE artist_album (
4444- artist_id TEXT NOT NULL,
4545- album_id TEXT NOT NULL,
5151+create table artist_album (
5252+ artist_id text not null,
5353+ album_id text not null,
46544747- PRIMARY KEY(artist_id, album_id),
4848- FOREIGN KEY(artist_id) REFERENCES artist(id),
4949- FOREIGN KEY(album_id) REFERENCES album(id)
5555+ primary key(artist_id, album_id),
5656+ foreign key(artist_id) references artist(id),
5757+ foreign key(album_id) references album(id)
5058);
51595252-INSERT INTO migrations (name, applied_at) VALUES ("01-init", CURRENT_TIMESTAMP);
6060+insert into migrations (name, applied_at) values ("01-init", current_timestamp);