hostas2/database.ddl

90 lines
3.0 KiB
SQL

CREATE TABLE IF NOT EXISTS actor (
objectId TEXT, -- UUIDv4 of the corresponding object
preferredUsername TEXT,
FOREIGN KEY (objectId) REFERENCES object(id),
PRIMARY KEY (objectId)
);
CREATE TABLE IF NOT EXISTS object (
id TEXT, -- Dereferenceable link to the object
type TEXT, -- Object type, see <https://www.w3.org/TR/activitystreams-vocabulary/#object-types>
name TEXT, -- Title of the object
attributedTo TEXT, -- object ID of the actor to whom the object is attributed
summary TEXT, -- Natural language summary of the object
content TEXT, -- Text content or representation
url TEXT, -- A URL that represents the object
mediaType TEXT, -- MIME type of `content`
icon TEXT, -- URL of a 1:1 image that represents the object
-- These four columns are unix timestamps. AP expects ISO timestamps
startTime INTEGER, -- When the object is said to have "begun," in some context
endTime INTEGER, -- When the object is said to "end," in some context
published INTEGER, -- When the object was first created
updated INTEGER, -- When the object was last updated
FOREIGN KEY (attributedTo) REFERENCES object(id),
PRIMARY KEY(id)
);
CREATE TABLE IF NOT EXISTS activity (
objectId TEXT,
-- All of these are object IDs, all of them are optional
actor TEXT, -- Actor "behind" the activity
object TEXT, -- Object encapsulated by the activity, if applicable
origin TEXT, -- Object the activity is "from"
target TEXT, -- Object the activity is "going to", or the encapsulated object is
result TEXT, -- Object describing the outcome
instrument TEXT, -- Object with which the activity was performed
FOREIGN KEY (objectId) REFERENCES object(id),
PRIMARY KEY (objectId)
);
CREATE TABLE IF NOT EXISTS object_contentMap (
objectId INTEGER, -- The object attaching `attachedId`
key TEXT, -- Langauge code
content TEXT, -- The content being mapped to by the key
FOREIGN KEY(objectId) REFERENCES object(id),
PRIMARY KEY(objectId, key)
);
CREATE TABLE IF NOT EXISTS object_attachment (
objectId INTEGER, -- The object attaching `attachedId`
attachedId INTEGER, -- The object attached by `objectId`
FOREIGN KEY(objectId) REFERENCES object(id),
FOREIGN KEY(attachedId) REFERENCES object(id),
PRIMARY KEY(objectId, attachedId)
);
CREATE TABLE IF NOT EXISTS object_audience (
objectId INTEGER, -- Object identifying an audience
audienceId INTEGER, -- Audience being identified
FOREIGN KEY(objectId) REFERENCES object(id),
FOREIGN KEY(audienceId) REFERENCES object(id),
PRIMARY KEY(objectId, audienceId)
);
CREATE TABLE IF NOT EXISTS object_replies (
objectId INTEGER, -- "original post," or whatever is being replied to
responseId INTEGER, -- The response to the original object
FOREIGN KEY(objectId) REFERENCES object(id),
FOREIGN KEY(responseId) REFERENCES object(id),
PRIMARY KEY(objectId, responseId)
);
CREATE TABLE IF NOT EXISTS object_tags (
taggerId INTEGER,
taggedId INTEGER,
FOREIGN KEY(taggerId) REFERENCES object(id),
FOREIGN KEY(taggedId) REFERENCES object(id),
PRIMARY KEY(taggerId, taggedId)
);