posts table
The posts table in the Social Media Database Schema schema has 14 columns, keyed by id, with 3 foreign keys to users, posts and groups. 12 columns in post_media, post_hashtags, post_mentions, post_likes and 8 more reference it.
Self-referencing for threads. The three count columns are denormalised caches, rebuildable from the engagement tables. deleted_at is a soft delete so replies do not orphan.
Columns (14)
| Column | Type | Constraints | Description |
|---|---|---|---|
| id | uuid | primary key | |
| author_id | uuid | not null, references users.id | |
| parent_post_id | uuid | references posts.id | |
| group_id | uuid | references groups.id | |
| type | post_type | not null | |
| visibility | post_visibility | not null | |
| body | varchar(2000) | ||
| language | char(2) | ||
| reply_count | integer | not null | |
| like_count | integer | not null | |
| repost_count | integer | not null | |
| created_at | timestamptz | not null | |
| edited_at | timestamptz | ||
| deleted_at | timestamptz |
Indexes (4)
(author_id, created_at)(parent_post_id)(group_id, created_at)(visibility, created_at)
Relationships
posts.author_idreferencesusers.idposts.parent_post_idreferencesposts.idposts.group_idreferencesgroups.idpost_media.post_idreferencespostspost_hashtags.post_idreferencespostspost_mentions.post_idreferencespostspost_likes.post_idreferencespostsreposts.post_idreferencespostsbookmarks.post_idreferencespostscomments.post_idreferencespostspolls.post_idreferencespostsfeed_entries.post_idreferencespostsnotifications.post_idreferencespostsreports.post_idreferencespostsmoderation_actions.target_post_idreferencesposts