fedilogue/tables.sql

47 lines
1.3 KiB
SQL

DROP TABLE IF EXISTS activities CASCADE;
DROP TABLE IF EXISTS actors CASCADE;
DROP TABLE IF EXISTS instances CASCADE;
CREATE TABLE actors (
id SERIAL PRIMARY KEY,
document JSONB,
identifiedat TIMESTAMP with time zone DEFAULT now(),
instance VARCHAR(1000) NOT NULL
);
CREATE UNIQUE INDEX actors_uri ON actors ( (document->'id') );
CREATE TABLE activities (
id SERIAL PRIMARY KEY,
document JSONB,
normalized TEXT,
instance VARCHAR(1000) NOT NULL
);
CREATE UNIQUE INDEX activities_uri ON activities ( (document->'id') );
CREATE TABLE instances (
endpoint VARCHAR(2083) NOT NULL PRIMARY KEY UNIQUE,
autostart BOOLEAN,
state VARCHAR(16),
username VARCHAR(32),
password VARCHAR(32),
software VARCHAR(50)
);
-- ALTER TABLE activities ADD COLUMN normalized_tsvector tsvector;
-- UPDATE activities SET normalized_tsvector = to_tsvector('english', normalized);
ALTER TABLE activities
ADD normalized_tsvector tsvector
GENERATED ALWAYS AS (to_tsvector('english', normalized)) STORED;
CREATE INDEX normalized_idx ON activities USING gin(normalized_tsvector);
CREATE INDEX actors_id_idx ON actors (id);
CREATE INDEX activities_id_idx ON activities (id);
CREATE INDEX actors_uri_idx ON actors ( (document->'id') );
CREATE INDEX activities_uri_idx ON activities ( (document->'id') );