aboutsummaryrefslogtreecommitdiffstats
path: root/migrations/20230218162011_blossom.sql
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@blos.sm>2023-02-19 02:11:17 +0000
committerLibravatar cel 🌸 <cel@blos.sm>2023-02-19 02:11:17 +0000
commitc6378ca77f08a8aaf30fa25c4c02d151bf69edfa (patch)
treef3d21a7d15f2543c4ccd2eba505a91774833529c /migrations/20230218162011_blossom.sql
parent0b6d17e87106bb514a62d79d13e8465fd3bffc3a (diff)
downloadblossom-c6378ca77f08a8aaf30fa25c4c02d151bf69edfa.tar.gz
blossom-c6378ca77f08a8aaf30fa25c4c02d151bf69edfa.tar.bz2
blossom-c6378ca77f08a8aaf30fa25c4c02d151bf69edfa.zip
create initial database migration
Diffstat (limited to '')
-rw-r--r--migrations/20230218162011_blossom.sql61
1 files changed, 61 insertions, 0 deletions
diff --git a/migrations/20230218162011_blossom.sql b/migrations/20230218162011_blossom.sql
new file mode 100644
index 0000000..188bbf8
--- /dev/null
+++ b/migrations/20230218162011_blossom.sql
@@ -0,0 +1,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)
+); \ No newline at end of file