aboutsummaryrefslogtreecommitdiffstats
path: root/migrations/20230218162011_blossom.sql
blob: 188bbf8abee14f3eadc6b40f00cb30b52df063fe (plain) (blame)
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
PRAGMA foreign_keys = on;

create table post_types (
    name varchar(32) not null primary key
);

insert into post_types (name) values ('article'), ('note');

create table posts (
    id integer not null primary key autoincrement,
    created_at bigint not null default (unixepoch()),
    updated_at bigint,
    post_type varchar(32) not null default ('note'),
    foreign key (post_type) references post_types(name)
);

create table tags (
    name varchar(128) not null primary key
);

create table posts_tags (
    post_id integer not null,
    tag varchar(128) not null,
    foreign key (post_id) references posts(id),
    foreign key (tag) references tags(name),
    primary key (post_id, tag)
);

create table articles (
    post_id integer not null,
    source varchar(128) not null,
    hash varchar(64) not null,
    foreign key (post_id) references posts(id)
);

create table notes (
    post_id integer not null,
    content text,
    foreign key (post_id) references posts(id)
);

create table media_types (
    name varchar(32) not null primary key
);

insert into media_types (name) values ('image'), ('video'), ('audio');

create table media (
    id integer not null primary key autoincrement,
    media_type varchar(32) not null,
    source varchar(128) not null,
    foreign key (media_type) references media_types(name)
);

create table notes_media (
    note_id integer not null, 
    media_id integer not null,
    foreign key (note_id) references notes(note_id),
    foreign key (media_id) references media(id),
    primary key (note_id, media_id)
);