Skip to the page
Social CrawlDocs

Data model

Updated
View as Markdown

The ten PostgreSQL tables, what each holds, how a saved post's files relate to its row, and what to know about tables made by synchronize instead of migrations.

On this page

The database holds metadata and state. The saved files of a post (pictures, videos, the offline page) are in the bundle storage, not here. See Architecture.

All tables are listed in apps/api/src/entities.ts. TypeORM creates and alters them at start while DB_SYNCHRONIZE is on (it is in the compose file).

Tables#

TableHolds
bookmarksOne row per saved post. The card data the library needs (see below).
restrict_rulesThe site and account rules that send saves to the restricted part (host, path; unique together).
post_sharesTemporary links to one post: label, expiresAt, SHA-256 of the secret, open and download counts, who fetched it last.
collection_sharesTemporary links to several posts: the post ids (a snapshot, up to 50) and the same counters.
big_uploadsA big video's tracks sent to WebDAV in parts: platform, post, track (video or audio), total bytes, part size, the finished parts with fingerprints, and the state of the one-file copy (joinState).
big_conversionsA smaller copy of a big video, one row per post and size: state, stage (sample, full, or own for a file you converted yourself and attached), percent, estimates, output size, layout (file or parts) and the checks.
attachmentsWhat you attached to a post: kind is post, file or link, with its target, title, address, file name, size and where the bytes are.
layoutsA layout template per site: domain and source.
app_settingsOne row (id 1): settings changed in the web app instead of the environment. Today: maxVideoMb.
webdav_settingsOne row (id 1): the WebDAV address, user name, the password sealed with AES-256-GCM, the offload switch and the large-file threshold in MB.

The bookmarks table#

ColumnMeaning
idThe UUID used in the web app's addresses (/bookmarks/<id>).
platform, postIdThe post's platform and its id there. Unique together: saving the same post again replaces the row.
url, authorName, previewThe address, the author, and the start of the text for search and cards.
bundleKeyWhere the files are: <platform>/<id>, for example bluesky/3kabc.
tagsThe tags, as an array of text.
noteYour note.
restrictedTrue when the post is in the restricted part.
sizeBytes, webdavBytes, bigBytesWhat the post takes: in total, how much of that is on WebDAV, and what its big-video tracks and copies take (they are not in the bundle, so they are kept apart and added back when the bundle is counted again).
Card columnscoverPath, coverWidth, coverHeight, mediaCount, imageCount, videoCount, fileCount, avatarPath, siteName, siteLogoPath, coverVideoPath, hasSavedVideo, hasMadeSizes, hasOnlineOnlyMedia. Computed from the saved post so the library does not read every bundle.
authorKey, authorHandleThe page or account the post comes from, in lower case, to group the library by. Older posts are filled in at start.
metaVersionA post whose version is below the code's META_VERSION (11) has its card data computed again at start.
createdAt, updatedAtDates.

Bundles#

A bundle is the folder <platform>/<id> in the bundle storage:

Text
index.html       the offline page (no scripts, a strict CSP)
post.json        the BundleManifest: version, the Post, and { path, bytes, sha256 } for every file
post.md          the Markdown version
text/post.txt    the plain text
images/ videos/ files/ transcripts/ ...
.webdav.json     only when some files are on WebDAV: which ones

post.json is the source of truth. index.html is rendered from it by packages/render, which is why a layout or a fix to the renderer can redraw old posts. See The Post schema.

Tables are made by synchronize#

There are no migrations. With DB_SYNCHRONIZE=true, TypeORM compares the entities to the database at start and changes the tables to match. That is convenient and also risky: a renamed column can be dropped and made again empty. For data you cannot lose:

  • Take a backup of pgdata (or your hosted database) before each update.
  • Use Settings → Database to copy to another database first if you want a second copy: see Copy the database.
  • If you add a column, synchronize adds it. If you turn DB_SYNCHRONIZE off, you must add columns by hand. For example the bookmarks columns authorKey and authorHandle were added this way.

Moving the database#

The database copy tool makes the new database's tables from the entity list, copies every table, and compares them. It needs the uuid-ossp add-on in the new database.