Skip to content

feat: Add Postgres Schema, Indexes, and Feed Queries - #4

Merged
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/postgres
Aug 16, 2026
Merged

feat: Add Postgres Schema, Indexes, and Feed Queries#4
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/postgres

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

Postgres now implements ActivityStore. Users, follows, and posts are 3NF tables with a unique handle index, a no-self-follow CHECK, and a composite (author_id, created_at DESC, id DESC) index. Author timelines and the home feed use two statements (first page vs keyed page) so a null cursor cannot force a generic plan. The home feed is CROSS JOIN LATERAL: each followee walks that index newest-first, then the outer query merges.

Same contract suite as the in-memory store. After ANALYZE, EXPLAIN on the author timeline is an Index Scan using posts_author_timeline_idx with no Sort. Tests run the SQL on PGlite. Any { query(sql, params) } client works, including node-postgres.

Closes #3

Users, follows, and posts sit in 3NF with a composite author timeline
index and keyset SQL. PostgresStore implements ActivityStore and runs
the shared contract suite against PGlite.
Seed enough posts, ANALYZE, and EXPLAIN the author timeline as an
index scan with no sort. Walk each followee through the same index
with LATERAL. First page and keyed page are separate statements.
@ThomasHartDev
ThomasHartDev merged commit e955802 into main Aug 16, 2026
1 check passed
@ThomasHartDev
ThomasHartDev deleted the thomas/feat/postgres branch August 16, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a Postgres backend: schema, indexes, and feed SQL

1 participant