-- Media: the metadata of content uploaded here and of content fetched from -- other servers and kept, and of the thumbnails made from either. -- -- The content itself is not in the database. It is in the blob store — -- files under media.base_path by default — named by its SHA-256, so the -- same bytes uploaded twice are stored once and a row here only says which -- blob an mxc:// URI refers to. -- -- Timestamps are milliseconds since the Unix epoch, as everywhere else in -- Warp. CREATE TABLE IF NOT EXISTS media_repository ( -- The server name of the mxc:// URI: this server for an upload, -- another for cached remote media. media_origin TEXT NOT NULL, media_id TEXT NOT NULL, -- As uploaded, parameters included: "text/plain; charset=utf-8". content_type TEXT NOT NULL DEFAULT '', upload_name TEXT NOT NULL DEFAULT '', file_size BIGINT NOT NULL DEFAULT 0, -- Lower-case hex SHA-256 of the content; '' while pending. sha256 TEXT NOT NULL DEFAULT '', -- The uploader; '' for remote media. user_id TEXT NOT NULL DEFAULT '', created_at_ms BIGINT NOT NULL, -- An ID handed out by POST /_matrix/media/v1/create whose content has -- not been uploaded yet. It is deleted unused at expires_at_ms. pending BOOLEAN NOT NULL DEFAULT 0, expires_at_ms BIGINT NOT NULL DEFAULT 0, PRIMARY KEY (media_origin, media_id) ); -- Counting a user's pending uploads, and sweeping the expired ones. CREATE INDEX IF NOT EXISTS media_repository_pending_idx ON media_repository (pending, user_id, expires_at_ms); -- Thumbnails, one per configured size that has been asked for. -- -- There is no foreign key to media_repository: the thumbnail of remote -- media is fetched from its server on its own, and the original it was -- made from may never have been fetched here at all. CREATE TABLE IF NOT EXISTS media_thumbnails ( media_origin TEXT NOT NULL, media_id TEXT NOT NULL, -- The configured size the thumbnail answers, not the size of the -- image: a "scale" thumbnail keeps the original's aspect ratio. width INTEGER NOT NULL, height INTEGER NOT NULL, -- 'crop' or 'scale'. method TEXT NOT NULL, content_type TEXT NOT NULL, file_size BIGINT NOT NULL, sha256 TEXT NOT NULL, created_at_ms BIGINT NOT NULL, PRIMARY KEY (media_origin, media_id, width, height, method) );