1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2025-02-04 11:04:42 +00:00
ibis/migrations/2023-11-28-150402_ibis_setup/up.sql

81 lines
2.3 KiB
MySQL
Raw Normal View History

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,
2023-12-08 21:21:31 +00:00
private_key text,
last_refreshed_at timestamptz NOT NULL DEFAULT now(),
local bool NOT NULL
2023-12-08 21:21:31 +00:00
);
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
2023-12-08 21:21:31 +00:00
);
2023-12-05 14:50:10 +00:00
CREATE TABLE instance_follow (
id serial PRIMARY KEY,
2023-12-04 14:10:07 +00:00
instance_id int REFERENCES instance ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
2023-12-14 16:06:44 +00:00
follower_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
pending boolean NOT NULL,
UNIQUE (instance_id, follower_id)
);
2023-12-04 14:10:07 +00:00
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
2023-11-29 15:41:29 +00:00
);
CREATE TABLE edit (
id serial PRIMARY KEY,
2023-12-18 15:40:27 +00:00
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,
2023-11-29 15:41:29 +00:00
article_id int REFERENCES article ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
previous_version_id uuid NOT NULL,
created timestamptz NOT NULL
2023-12-05 00:17:02 +00:00
);
CREATE TABLE CONFLICT (
id serial PRIMARY KEY,
hash uuid NOT NULL,
diff text NOT NULL,
summary text NOT NULL,
2023-12-19 14:32:14 +00:00
creator_id int REFERENCES local_user ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
2023-12-05 00:17:02 +00:00
article_id int REFERENCES article ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
previous_version_id uuid NOT NULL
2023-12-19 15:15:43 +00:00
);
-- 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;