1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2025-01-29 06:01:34 +00:00
ibis/migrations/2023-11-28-150402_ibis_setup/up.sql
Nutomic 54c65e7474
Implement comments for articles (fixes #10) (#112)
* Move files into subfolders

* Implement comments for articles (fixes #10)

* wip

* backend mostly done

* tests wip

* test working

* wip federation

* partial federation

* comment federation working!

* federation and tests working with delete

* wip frontend

* basic comment rendering

* various

* wip comment tree rendering

* all working

* update rust

* comment markdown

* only one comment editor at a time

* display comment creation time

* fedilink

* live handling of delete/restore

* comment editing
2025-01-21 11:39:10 +00:00

80 lines
2.3 KiB
SQL

CREATE TABLE instance (
id serial PRIMARY KEY,
domain text NOT NULL UNIQUE,
ap_id varchar(255) NOT NULL UNIQUE,
description text,
articles_url varchar(255) NOT NULL UNIQUE,
inbox_url varchar(255) NOT NULL,
public_key text NOT NULL,
private_key text,
last_refreshed_at timestamptz NOT NULL DEFAULT now(),
local bool NOT NULL
);
CREATE TABLE person (
id serial PRIMARY KEY,
username text NOT NULL,
ap_id varchar(255) NOT NULL UNIQUE,
inbox_url varchar(255) NOT NULL,
public_key text NOT NULL,
private_key text,
last_refreshed_at timestamptz NOT NULL DEFAULT now(),
local bool NOT NULL
);
CREATE TABLE local_user (
id serial PRIMARY KEY,
password_encrypted text NOT NULL,
person_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
admin bool NOT NULL
);
CREATE TABLE instance_follow (
id serial PRIMARY KEY,
instance_id int REFERENCES instance ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
follower_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
pending boolean NOT NULL,
UNIQUE (instance_id, follower_id)
);
CREATE TABLE article (
id serial PRIMARY KEY,
title text NOT NULL,
text text NOT NULL,
ap_id varchar(255) NOT NULL UNIQUE,
instance_id int REFERENCES instance ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
local bool NOT NULL,
protected bool NOT NULL
);
CREATE TABLE edit (
id serial PRIMARY KEY,
creator_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
hash uuid NOT NULL,
ap_id varchar(255) NOT NULL UNIQUE,
diff text NOT NULL,
summary text NOT NULL,
article_id int REFERENCES article ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
previous_version_id uuid NOT NULL,
created timestamptz NOT NULL
);
CREATE TABLE CONFLICT (
id serial PRIMARY KEY,
hash uuid NOT NULL,
diff text NOT NULL,
summary text NOT NULL,
creator_id int REFERENCES local_user ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
article_id int REFERENCES article ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
previous_version_id uuid NOT NULL
);
-- generate a jwt secret
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE jwt_secret (
id serial PRIMARY KEY,
secret varchar NOT NULL DEFAULT gen_random_uuid ()
);
INSERT INTO jwt_secret DEFAULT VALUES;