Parakeet is a Rust-based Bluesky AppServer aiming to implement most of the functionality required to support the Bluesky client
appview atproto bluesky rust appserver
67
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: clean up sql

Mia b7ce0e7b cec02ee9

+425 -332
+21
.sqruff
··· 1 + [sqruff] 2 + dialect = postgres 3 + max_line_length = 96 4 + 5 + [sqruff:identation] 6 + ident_unit = tab 7 + tab_space_size = 4 8 + idented_joins = True 9 + 10 + [sqruff:layout:type:alias_expression] 11 + spacing_before = align 12 + align_within = select_clause 13 + align_scope = bracketed 14 + 15 + [sqruff:layout:type:column_constraint_segment] 16 + spacing_before = align 17 + align_within = create_table_statement 18 + 19 + [sqruff:layout:type:data_type] 20 + spacing_before = align 21 + align_within = create_table_statement
+3 -3
crates/consumer/src/db/sql/bookmarks_upsert.sql
··· 1 1 INSERT INTO bookmarks (did, rkey, subject, subject_type, tags, created_at) 2 2 VALUES ($1, $2, $3, $4, $5, $6) 3 - ON CONFLICT (did, rkey) DO UPDATE SET subject=EXCLUDED.subject, 4 - subject_type=EXCLUDED.subject_type, 5 - tags=EXCLUDED.tags 3 + ON CONFLICT (did, rkey) DO UPDATE SET subject = excluded.subject, 4 + subject_type = excluded.subject_type, 5 + tags = excluded.tags
+21 -11
crates/consumer/src/db/sql/feedgen_upsert.sql
··· 1 - INSERT INTO feedgens (at_uri, owner, cid, service_did, content_mode, name, description, description_facets, avatar_cid, 2 - created_at) 1 + INSERT INTO feedgens ( 2 + at_uri, 3 + owner, 4 + cid, 5 + service_did, 6 + content_mode, 7 + name, 8 + description, 9 + description_facets, 10 + avatar_cid, 11 + created_at 12 + ) 3 13 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) 4 - ON CONFLICT (at_uri) DO UPDATE SET cid=EXCLUDED.cid, 5 - service_did=EXCLUDED.service_did, 6 - content_mode=EXCLUDED.content_mode, 7 - name=EXCLUDED.name, 8 - description=EXCLUDED.description, 9 - description_facets=EXCLUDED.description_facets, 10 - avatar_cid=EXCLUDED.avatar_cid, 11 - indexed_at=NOW() 12 - RETURNING XMAX::text::int 14 + ON CONFLICT (at_uri) DO UPDATE SET cid = excluded.cid, 15 + service_did = excluded.service_did, 16 + content_mode = excluded.content_mode, 17 + name = excluded.name, 18 + description = excluded.description, 19 + description_facets = excluded.description_facets, 20 + avatar_cid = excluded.avatar_cid, 21 + indexed_at = NOW() 22 + RETURNING xmax::text::int
+5 -5
crates/consumer/src/db/sql/label_copy_upsert.sql
··· 1 1 INSERT INTO labels 2 - SELECT DISTINCT on (labeler, label, uri) * 2 + SELECT DISTINCT ON (labeler, label, uri) * 3 3 FROM label_tmp 4 4 ON CONFLICT (labeler, label, uri) DO UPDATE 5 - SET negated=EXCLUDED.negated, 6 - expires=EXCLUDED.expires, 7 - sig=EXCLUDED.sig, 8 - created_at=excluded.created_at 5 + SET negated = excluded.negated, 6 + expires = excluded.expires, 7 + sig = excluded.sig, 8 + created_at = excluded.created_at
+9 -7
crates/consumer/src/db/sql/label_defs_upsert.sql
··· 1 - INSERT INTO labeler_defs (labeler, label_identifier, severity, blurs, default_setting, adult_only, locales) 1 + INSERT INTO labeler_defs ( 2 + labeler, label_identifier, severity, blurs, default_setting, adult_only, locales 3 + ) 2 4 VALUES ($1, $2, $3, $4, $5, $6, $7) 3 5 ON CONFLICT (labeler, label_identifier) DO UPDATE 4 - SET severity=EXCLUDED.severity, 5 - blurs=EXCLUDED.blurs, 6 - default_setting=EXCLUDED.default_setting, 7 - adult_only=EXCLUDED.adult_only, 8 - locales=EXCLUDED.locales, 9 - indexed_at=NOW() 6 + SET severity = excluded.severity, 7 + blurs = excluded.blurs, 8 + default_setting = excluded.default_setting, 9 + adult_only = excluded.adult_only, 10 + locales = excluded.locales, 11 + indexed_at = NOW()
+5 -5
crates/consumer/src/db/sql/label_service_upsert.sql
··· 1 1 INSERT INTO labelers (did, cid, reasons, subject_types, subject_collections) 2 2 VALUES ($1, $2, $3, $4, $5) 3 - ON CONFLICT (did) DO UPDATE SET cid=EXCLUDED.cid, 4 - reasons=EXCLUDED.reasons, 5 - subject_types=EXCLUDED.subject_types, 6 - subject_collections=EXCLUDED.subject_collections, 7 - indexed_at=NOW() 3 + ON CONFLICT (did) DO UPDATE SET cid = excluded.cid, 4 + reasons = excluded.reasons, 5 + subject_types = excluded.subject_types, 6 + subject_collections = excluded.subject_collections, 7 + indexed_at = NOW()
+11 -9
crates/consumer/src/db/sql/list_upsert.sql
··· 1 - INSERT INTO lists (at_uri, owner, cid, list_type, name, description, description_facets, avatar_cid, created_at) 1 + INSERT INTO lists ( 2 + at_uri, owner, cid, list_type, name, description, description_facets, avatar_cid, created_at 3 + ) 2 4 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) 3 - ON CONFLICT (at_uri) DO UPDATE SET cid=EXCLUDED.cid, 4 - list_type=EXCLUDED.list_type, 5 - name=EXCLUDED.name, 6 - description=EXCLUDED.description, 7 - description_facets=EXCLUDED.description_facets, 8 - avatar_cid=EXCLUDED.avatar_cid, 9 - indexed_at=NOW() 10 - RETURNING XMAX::text::int 5 + ON CONFLICT (at_uri) DO UPDATE SET cid = excluded.cid, 6 + list_type = excluded.list_type, 7 + name = excluded.name, 8 + description = excluded.description, 9 + description_facets = excluded.description_facets, 10 + avatar_cid = excluded.avatar_cid, 11 + indexed_at = NOW() 12 + RETURNING xmax::text::int
+15 -3
crates/consumer/src/db/sql/post_insert.sql
··· 1 - INSERT INTO posts (at_uri, did, cid, record, content, facets, languages, tags, parent_uri, parent_cid, root_uri, 2 - root_cid, embed, embed_subtype, mentions, violates_threadgate, created_at) 1 + INSERT INTO posts ( 2 + at_uri, 3 + did, 4 + cid, 5 + record, 6 + content, 7 + facets, 8 + languages, 9 + tags, 10 + parent_uri, 11 + parent_cid, 12 + root_uri, 13 + root_cid, embed, embed_subtype, mentions, violates_threadgate, created_at 14 + ) 3 15 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) 4 - ON CONFLICT DO NOTHING 16 + ON CONFLICT DO NOTHING
+5 -5
crates/consumer/src/db/sql/postgate_upsert.sql
··· 1 1 INSERT INTO postgates (at_uri, cid, post_uri, detached, rules, created_at) 2 2 VALUES ($1, $2, $3, $4, $5, $6) 3 - ON CONFLICT (at_uri) DO UPDATE SET cid=EXCLUDED.cid, 4 - post_uri=EXCLUDED.post_uri, 5 - detached=EXCLUDED.detached, 6 - rules=EXCLUDED.rules, 7 - indexed_at=NOW() 3 + ON CONFLICT (at_uri) DO UPDATE SET cid = excluded.cid, 4 + post_uri = excluded.post_uri, 5 + detached = excluded.detached, 6 + rules = excluded.rules, 7 + indexed_at = NOW()
+16 -14
crates/consumer/src/db/sql/profile_upsert.sql
··· 1 - INSERT INTO profiles (did, cid, avatar_cid, banner_cid, display_name, description, pinned_uri, pinned_cid, 2 - joined_sp_uri, joined_sp_cid, pronouns, website, created_at) 1 + INSERT INTO profiles ( 2 + did, cid, avatar_cid, banner_cid, display_name, description, pinned_uri, pinned_cid, 3 + joined_sp_uri, joined_sp_cid, pronouns, website, created_at 4 + ) 3 5 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) 4 - ON CONFLICT (did) DO UPDATE SET cid=EXCLUDED.cid, 5 - avatar_cid=EXCLUDED.avatar_cid, 6 - banner_cid=EXCLUDED.banner_cid, 7 - display_name=EXCLUDED.display_name, 8 - description=EXCLUDED.description, 9 - pinned_uri=EXCLUDED.pinned_uri, 10 - pinned_cid=EXCLUDED.pinned_cid, 11 - joined_sp_uri=EXCLUDED.joined_sp_uri, 12 - joined_sp_cid=EXCLUDED.joined_sp_cid, 13 - pronouns=EXCLUDED.pronouns, 14 - website=EXCLUDED.website, 15 - indexed_at=NOW() 6 + ON CONFLICT (did) DO UPDATE SET cid = excluded.cid, 7 + avatar_cid = excluded.avatar_cid, 8 + banner_cid = excluded.banner_cid, 9 + display_name = excluded.display_name, 10 + description = excluded.description, 11 + pinned_uri = excluded.pinned_uri, 12 + pinned_cid = excluded.pinned_cid, 13 + joined_sp_uri = excluded.joined_sp_uri, 14 + joined_sp_cid = excluded.joined_sp_cid, 15 + pronouns = excluded.pronouns, 16 + website = excluded.website, 17 + indexed_at = NOW()
+12 -10
crates/consumer/src/db/sql/starterpack_upsert.sql
··· 1 - INSERT INTO starterpacks (at_uri, owner, cid, record, name, description, description_facets, list, feeds, created_at) 1 + INSERT INTO starterpacks ( 2 + at_uri, owner, cid, record, name, description, description_facets, list, feeds, created_at 3 + ) 2 4 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) 3 - ON CONFLICT (at_uri) DO UPDATE SET cid=EXCLUDED.cid, 4 - record=EXCLUDED.record, 5 - name=EXCLUDED.name, 6 - description=EXCLUDED.description, 7 - description_facets=EXCLUDED.description_facets, 8 - list=EXCLUDED.list, 9 - feeds=EXCLUDED.feeds, 10 - indexed_at=NOW() 11 - RETURNING XMAX::text::int 5 + ON CONFLICT (at_uri) DO UPDATE SET cid = excluded.cid, 6 + record = excluded.record, 7 + name = excluded.name, 8 + description = excluded.description, 9 + description_facets = excluded.description_facets, 10 + list = excluded.list, 11 + feeds = excluded.feeds, 12 + indexed_at = NOW() 13 + RETURNING xmax::text::int
+22 -12
crates/consumer/src/db/sql/status_upsert.sql
··· 1 - INSERT INTO statuses (did, cid, status, duration, record, embed_uri, embed_title, embed_description, thumb_mime_type, 2 - thumb_cid, created_at) 1 + INSERT INTO statuses ( 2 + did, 3 + cid, 4 + status, 5 + duration, 6 + record, 7 + embed_uri, 8 + embed_title, 9 + embed_description, 10 + thumb_mime_type, 11 + thumb_cid, created_at 12 + ) 3 13 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) 4 - ON CONFLICT (did) DO UPDATE SET cid=EXCLUDED.cid, 5 - status=EXCLUDED.status, 6 - duration=EXCLUDED.duration, 7 - record=EXCLUDED.record, 8 - embed_uri=EXCLUDED.embed_uri, 9 - embed_title=EXCLUDED.embed_title, 10 - embed_description=EXCLUDED.embed_description, 11 - thumb_mime_type=EXCLUDED.thumb_mime_type, 12 - thumb_cid=EXCLUDED.thumb_cid, 13 - indexed_at=NOW() 14 + ON CONFLICT (did) DO UPDATE SET cid = excluded.cid, 15 + status = excluded.status, 16 + duration = excluded.duration, 17 + record = excluded.record, 18 + embed_uri = excluded.embed_uri, 19 + embed_title = excluded.embed_title, 20 + embed_description = excluded.embed_description, 21 + thumb_mime_type = excluded.thumb_mime_type, 22 + thumb_cid = excluded.thumb_cid, 23 + indexed_at = NOW()
+9 -7
crates/consumer/src/db/sql/threadgate_upsert.sql
··· 1 - INSERT INTO threadgates (at_uri, cid, post_uri, hidden_replies, allow, allowed_lists, record, created_at) 1 + INSERT INTO threadgates ( 2 + at_uri, cid, post_uri, hidden_replies, allow, allowed_lists, record, created_at 3 + ) 2 4 VALUES ($1, $2, $3, $4, $5, $6, $7, $8) 3 - ON CONFLICT (at_uri) DO UPDATE SET cid=EXCLUDED.cid, 4 - hidden_replies=EXCLUDED.hidden_replies, 5 - allow=EXCLUDED.allow, 6 - allowed_lists=EXCLUDED.allowed_lists, 7 - record=EXCLUDED.record, 8 - indexed_at=NOW() 5 + ON CONFLICT (at_uri) DO UPDATE SET cid = excluded.cid, 6 + hidden_replies = excluded.hidden_replies, 7 + allow = excluded.allow, 8 + allowed_lists = excluded.allowed_lists, 9 + record = excluded.record, 10 + indexed_at = NOW()
+7 -4
crates/parakeet/src/sql/list_states.sql
··· 1 - select l.at_uri, lb.at_uri as block, lm.did is not null as muted 1 + select 2 + l.at_uri, 3 + lb.at_uri as block, 4 + lm.did is not null as muted 2 5 from lists l 3 - left join list_blocks lb on l.at_uri = lb.list_uri and lb.did = $1 4 - left join list_mutes lm on l.at_uri = lm.list_uri and lm.did = $1 5 - where l.at_uri = any ($2) and (lm.did is not null or lb.at_uri is not null) 6 + left join list_blocks lb on l.at_uri = lb.list_uri and lb.did = $1 7 + left join list_mutes lm on l.at_uri = lm.list_uri and lm.did = $1 8 + where l.at_uri = any($2) and (lm.did is not null or lb.at_uri is not null)
+29 -17
crates/parakeet/src/sql/post_state.sql
··· 1 1 select bq.*, coalesce(bq.at_uri = pinned_uri, false) as pinned 2 - from (select p.at_uri, 3 - p.did, 4 - p.cid, 5 - l.rkey as like_rkey, 6 - r.rkey as repost_rkey, 7 - b.did is not null as bookmarked, 8 - tm.did is not null as thread_muted, 9 - coalesce(pg.rules && ARRAY ['app.bsky.feed.postgate#disableRule'], false) as embed_disabled 10 - from posts p 11 - left join likes l on l.subject = p.at_uri and l.did = $1 12 - left join reposts r on r.post = p.at_uri and r.did = $1 13 - left join bookmarks b on b.subject = p.at_uri and b.did = $1 14 - left join postgates pg on pg.post_uri = p.at_uri 15 - left join thread_mutes tm on tm.thread = coalesce(p.root_uri, p.at_uri) 16 - where p.at_uri = any ($2) 17 - and (l.rkey is not null or r.rkey is not null or b.did is not null or tm.did is not null or pg.rules is not null)) bq, 18 - (select pinned_uri, pinned_cid from profiles where did = $1) pp; 2 + from ( 3 + select 4 + p.at_uri, 5 + p.did, 6 + p.cid, 7 + l.rkey as like_rkey, 8 + r.rkey as repost_rkey, 9 + b.did is not null as bookmarked, 10 + tm.did is not null as thread_muted, 11 + coalesce( 12 + pg.rules && array['app.bsky.feed.postgate#disableRule'], false 13 + ) as embed_disabled 14 + from posts p 15 + left join likes l on l.subject = p.at_uri and l.did = $1 16 + left join reposts r on r.post = p.at_uri and r.did = $1 17 + left join bookmarks b on b.subject = p.at_uri and b.did = $1 18 + left join postgates pg on pg.post_uri = p.at_uri 19 + left join thread_mutes tm on tm.thread = coalesce(p.root_uri, p.at_uri) 20 + where 21 + p.at_uri = any($2) 22 + and ( 23 + l.rkey is not null 24 + or r.rkey is not null 25 + or b.did is not null 26 + or tm.did is not null 27 + or pg.rules is not null 28 + ) 29 + ) bq, 30 + (select pinned_uri, pinned_cid from profiles where did = $1) pp;
+24 -19
crates/parakeet/src/sql/profile_state.sql
··· 1 - with vlb as (select * from v_list_block_exp where did = $1 and subject = any ($2)), 2 - vlm as (select * from v_list_mutes_exp where did = $1 and subject = any ($2)), 3 - ps as (select * from profile_states where did = $1 and subject = any ($2)), 4 - vlb2 as (select subject as did, did as subject, list_uri is not null as blocked 5 - from v_list_block_exp 6 - where did = any ($2) 7 - and subject = $1) 8 - select distinct on (did, subject) did, 9 - subject, 10 - muting, 11 - ps.blocked or vlb2.blocked as blocked, 12 - blocking, 13 - following, 14 - followed, 15 - vlb.list_uri as list_block, 16 - vlm.list_uri as list_mute 1 + with vlb as (select * from v_list_block_exp where did = $1 and subject = any($2)), 2 + vlm as (select * from v_list_mutes_exp where did = $1 and subject = any($2)), 3 + ps as (select * from profile_states where did = $1 and subject = any($2)), 4 + vlb2 as ( 5 + select subject as did, did as subject, list_uri is not null as blocked 6 + from v_list_block_exp 7 + where 8 + did = any($2) 9 + and subject = $1 10 + ) 11 + 12 + select distinct on (did, subject) 13 + did, 14 + subject, 15 + muting, 16 + ps.blocked or vlb2.blocked as blocked, 17 + blocking, 18 + following, 19 + followed, 20 + vlb.list_uri as list_block, 21 + vlm.list_uri as list_mute 17 22 from ps 18 - full join vlb using (did, subject) 19 - full join vlm using (did, subject) 20 - full join vlb2 using (did, subject); 23 + full join vlb using (did, subject) 24 + full join vlm using (did, subject) 25 + full join vlb2 using (did, subject);
+10 -8
crates/parakeet/src/sql/thread.sql
··· 1 - with recursive thread as (select at_uri, parent_uri, root_uri, 1 as depth 2 - from posts 3 - where parent_uri = $1 and violates_threadgate=FALSE 4 - union all 5 - select p.at_uri, p.parent_uri, p.root_uri, thread.depth + 1 6 - from posts p 7 - join thread on p.parent_uri = thread.at_uri 8 - where thread.depth <= $2 and p.violates_threadgate=FALSE) 1 + with recursive thread as ( 2 + select at_uri, parent_uri, root_uri, 1 as depth 3 + from posts 4 + where parent_uri = $1 and violates_threadgate = FALSE 5 + union all 6 + select p.at_uri, p.parent_uri, p.root_uri, thread.depth + 1 7 + from posts p 8 + join thread on p.parent_uri = thread.at_uri 9 + where thread.depth <= $2 and p.violates_threadgate = FALSE 10 + ) 9 11 select * 10 12 from thread 11 13 order by depth desc;
+17 -11
crates/parakeet/src/sql/thread_branching.sql
··· 1 - with recursive thread as (select at_uri, parent_uri, root_uri, 1 as depth 2 - from posts 3 - where parent_uri = $1 4 - and violates_threadgate = FALSE 5 - union all 6 - (select p.at_uri, p.parent_uri, p.root_uri, thread.depth + 1 7 - from posts p 8 - join thread on p.parent_uri = thread.at_uri 9 - where thread.depth <= $2 10 - and violates_threadgate = FALSE 11 - LIMIT $3)) 1 + with recursive thread as ( 2 + select at_uri, parent_uri, root_uri, 1 as depth 3 + from posts 4 + where 5 + parent_uri = $1 6 + and violates_threadgate = FALSE 7 + union all 8 + ( 9 + select p.at_uri, p.parent_uri, p.root_uri, thread.depth + 1 10 + from posts p 11 + join thread on p.parent_uri = thread.at_uri 12 + where 13 + thread.depth <= $2 14 + and violates_threadgate = FALSE 15 + limit $3 16 + ) 17 + ) 12 18 select * 13 19 from thread;
+15 -11
crates/parakeet/src/sql/thread_parent.sql
··· 1 - with recursive parents as (select at_uri, cid, parent_uri, root_uri, 0 as depth 2 - from posts 3 - where 4 - at_uri = (select parent_uri from posts where at_uri = $1 and violates_threadgate = FALSE) 5 - union all 6 - select p.at_uri, p.cid, p.parent_uri, p.root_uri, parents.depth + 1 7 - from posts p 8 - join parents on p.at_uri = parents.parent_uri 9 - where parents.depth <= $2 10 - and p.violates_threadgate = FALSE) 1 + with recursive parents as ( 2 + select at_uri, cid, parent_uri, root_uri, 0 as depth 3 + from posts 4 + where 5 + at_uri 6 + = (select parent_uri from posts where at_uri = $1 and violates_threadgate = FALSE) 7 + union all 8 + select p.at_uri, p.cid, p.parent_uri, p.root_uri, parents.depth + 1 9 + from posts p 10 + join parents on p.at_uri = parents.parent_uri 11 + where 12 + parents.depth <= $2 13 + and p.violates_threadgate = FALSE 14 + ) 11 15 select * 12 16 from parents 13 - order by depth desc; 17 + order by depth desc;
+7 -4
crates/parakeet/src/sql/thread_v2_hidden_children.sql
··· 1 1 select at_uri 2 2 from posts 3 - where parent_uri = $1 4 - and at_uri = any (select unnest(hidden_replies) 5 - from threadgates 6 - where post_uri = $2) 3 + where 4 + parent_uri = $1 5 + and at_uri = any( 6 + select unnest(hidden_replies) 7 + from threadgates 8 + where post_uri = $2 9 + )
+3 -1
migrations/00000000000000_diesel_initial_setup/up.sql
··· 16 16 -- 17 17 -- SELECT diesel_manage_updated_at('users'); 18 18 -- ``` 19 - CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ 19 + CREATE OR REPLACE FUNCTION diesel_manage_updated_at( 20 + _tbl regclass 21 + ) RETURNS void AS $$ 20 22 BEGIN 21 23 EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s 22 24 FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
+1 -1
migrations/2025-01-26-171756_actors/down.sql
··· 1 - drop table actors; 1 + drop table actors;
+1 -1
migrations/2025-01-29-213341_follows_and_blocks/down.sql
··· 1 1 drop table blocks; 2 - drop table follows; 2 + drop table follows;
+2 -4
migrations/2025-01-29-213341_follows_and_blocks/up.sql
··· 8 8 primary key (did, rkey) 9 9 ); 10 10 11 - create index blocks_did_index on blocks (did); 12 - create index blocks_subject_index on blocks (subject); 11 + create index blocks_subject_index on blocks using hash (subject); 13 12 14 13 create table follows 15 14 ( ··· 21 20 primary key (did, rkey) 22 21 ); 23 22 24 - create index follow_did_index on follows (did); 25 - create index follow_subject_index on follows (subject); 23 + create index follow_subject_index on follows using hash (subject);
+1 -1
migrations/2025-01-30-204801_profiles/down.sql
··· 1 - drop table profiles; 1 + drop table profiles;
+2 -2
migrations/2025-01-30-204801_profiles/up.sql
··· 1 1 create table profiles 2 2 ( 3 - did text primary key references actors (did), 3 + did text primary key references actors (did), 4 4 cid text not null, 5 5 6 6 avatar_cid text, ··· 17 17 18 18 created_at timestamp not null default now(), 19 19 indexed_at timestamp not null default now() 20 - ); 20 + );
+1 -1
migrations/2025-02-07-203450_lists/down.sql
··· 1 1 drop table list_items; 2 2 drop table list_blocks; 3 - drop table lists; 3 + drop table lists;
+6 -6
migrations/2025-02-07-203450_lists/up.sql
··· 1 1 create table lists 2 2 ( 3 - at_uri text primary key, 3 + at_uri text primary key, 4 4 owner text not null references actors (did), 5 5 cid text not null, 6 6 ··· 16 16 17 17 create table list_items 18 18 ( 19 - at_uri text primary key, 19 + at_uri text primary key, 20 20 21 21 list_uri text not null, 22 22 subject text not null, ··· 25 25 indexed_at timestamp not null default now() 26 26 ); 27 27 28 - create index listitems_list_index on list_items (list_uri); 29 - create index listitems_subject_index on list_items (subject); 28 + create index listitems_list_index on list_items using hash (list_uri); 29 + create index listitems_subject_index on list_items using hash (subject); 30 30 31 31 create table list_blocks 32 32 ( 33 - at_uri text primary key, 33 + at_uri text primary key, 34 34 35 35 did text not null references actors (did), 36 36 list_uri text not null, ··· 40 40 ); 41 41 42 42 create index listblocks_list_index on list_blocks using hash (list_uri); 43 - create index listblocks_did_index on list_blocks using hash (did); 43 + create index listblocks_did_index on list_blocks using hash (did);
+1 -1
migrations/2025-02-08-162441_feedgen/down.sql
··· 1 - drop table feedgens; 1 + drop table feedgens;
+2 -2
migrations/2025-02-08-162441_feedgen/up.sql
··· 1 1 create table feedgens 2 2 ( 3 - at_uri text primary key, 3 + at_uri text primary key, 4 4 cid text not null, 5 5 owner text not null references actors (did), 6 6 ··· 17 17 indexed_at timestamp not null default now() 18 18 ); 19 19 20 - create index feedgens_owner_index on feedgens using hash (owner); 20 + create index feedgens_owner_index on feedgens using hash (owner);
+1 -1
migrations/2025-02-12-211348_backfill/down.sql
··· 1 1 drop table backfill; 2 - drop table backfill_jobs; 2 + drop table backfill_jobs;
+4 -3
migrations/2025-02-12-211348_backfill/up.sql
··· 16 16 17 17 create table backfill_jobs 18 18 ( 19 - id serial primary key, 19 + id serial primary key, 20 20 did text not null, 21 21 since text, -- for future use. 22 22 23 - status text not null, -- pending/processing/failed/completed (completed rows will be deleted) 23 + -- pending/processing/failed/completed (completed rows will be deleted) 24 + status text not null, 24 25 created_at timestamp not null default now(), 25 26 updated_at timestamp not null default now() 26 27 ); 27 28 28 29 create unique index bfjobs_did_uindex on backfill_jobs (did); 29 - create index bfjobs_status on backfill_jobs (status); 30 + create index bfjobs_status on backfill_jobs (status);
+1 -1
migrations/2025-02-16-142357_posts/down.sql
··· 6 6 drop table post_embed_video_captions; 7 7 drop table post_embed_video; 8 8 drop table post_embed_images; 9 - drop table posts; 9 + drop table posts;
+24 -28
migrations/2025-02-16-142357_posts/up.sql
··· 1 1 create table posts 2 2 ( 3 - at_uri text primary key, 3 + at_uri text primary key, 4 4 cid text not null, 5 5 did text not null references actors (did), 6 6 record jsonb not null, 7 7 8 8 content text not null, 9 9 facets jsonb, 10 - languages text[] not null, 11 - tags text[] not null, 10 + languages text [] not null, 11 + tags text [] not null, 12 12 13 13 parent_uri text, 14 14 parent_cid text, ··· 16 16 root_cid text, 17 17 18 18 embed text, 19 - embed_subtype text, -- this is used for recordWithMedia to store the type of media. 19 + -- this is used for recordWithMedia to store the type of media. 20 + embed_subtype text, 20 21 21 22 created_at timestamptz not null default now(), 22 23 indexed_at timestamp not null default now() 23 24 ); 24 25 25 - create index posts_did_index on posts (did); 26 - create index posts_parent_index on posts (parent_uri); 27 - create index posts_root_index on posts (root_uri); 26 + create index posts_did_index on posts using hash (did); 27 + create index posts_parent_index on posts using hash (parent_uri); 28 + create index posts_root_index on posts using hash (root_uri); 28 29 create index posts_lang_index on posts using gin (languages); 29 30 create index posts_tags_index on posts using gin (tags); 30 31 ··· 42 43 43 44 primary key (post_uri, seq) 44 45 ); 45 - 46 - create index post_embed_images_posturi on post_embed_images (post_uri); 47 46 48 47 create table post_embed_video 49 48 ( ··· 57 56 height integer 58 57 ); 59 58 60 - create index post_embed_video_posturi on post_embed_video (post_uri); 61 - 62 59 create table post_embed_video_captions 63 60 ( 64 61 post_uri text not null references posts (at_uri) on delete cascade deferrable, ··· 70 67 primary key (post_uri, language) 71 68 ); 72 69 73 - create index post_embed_video_captions_posturi on post_embed_video_captions (post_uri); 74 - 75 70 create table post_embed_ext 76 71 ( 77 72 post_uri text primary key references posts (at_uri) on delete cascade deferrable, ··· 82 77 thumb_mime_type text, 83 78 thumb_cid text 84 79 ); 85 - 86 - create index post_embed_ext_posturi on post_embed_ext (post_uri); 87 80 88 81 create table post_embed_record 89 82 ( ··· 95 88 detached bool not null default false 96 89 ); 97 90 98 - create index post_embed_record_posturi on post_embed_record (post_uri); 99 91 create index post_embed_record_detached on post_embed_record (detached); 100 - create index post_embed_record_uri on post_embed_record (uri); 92 + create index post_embed_record_uri on post_embed_record using hash (uri); 101 93 102 94 create table postgates 103 95 ( 104 - at_uri text primary key, 96 + at_uri text primary key, 105 97 cid text not null, 106 98 post_uri text not null, 107 99 108 - detached text[] not null, 109 - rules text[] not null, 100 + detached text [] not null, 101 + rules text [] not null, 110 102 111 103 created_at timestamptz not null default now(), 112 104 indexed_at timestamp not null default now() 113 105 ); 114 106 115 - create index postgates_posts on postgates (post_uri); 107 + create index postgates_posts on postgates using hash (post_uri); 116 108 create index postgates_detached on postgates using gin (detached); 117 109 create index postgates_rules on postgates using gin (rules); 118 110 119 111 create table threadgates 120 112 ( 121 - at_uri text primary key, 113 + at_uri text primary key, 122 114 cid text not null, 123 115 post_uri text not null, 124 116 125 - hidden_replies text[] not null, 126 - allow text[], 127 - allowed_lists text[], 117 + hidden_replies text [] not null, 118 + allow text [], 119 + allowed_lists text [], 128 120 129 121 record jsonb not null, 130 122 ··· 132 124 indexed_at timestamp not null default now() 133 125 ); 134 126 135 - create index threadgates_posts on threadgates (post_uri); 127 + create index threadgates_posts on threadgates using hash (post_uri); 136 128 create index threadgates_hidden on threadgates using gin (hidden_replies); 137 129 create index threadgates_allow on threadgates using gin (allow); 138 130 create index threadgates_allowedlist on threadgates using gin (allowed_lists); 139 131 140 - create or replace function maintain_postgates(post text, detached_posts text[], effective timestamp) returns void as 132 + create or replace function maintain_postgates( 133 + post text, 134 + detached_posts text [], 135 + effective timestamp 136 + ) returns void as 141 137 $$ 142 138 begin 143 139 -- first clear all the old data ··· 158 154 end if; 159 155 160 156 end; 161 - $$ language plpgsql; 157 + $$ language plpgsql;
+1 -1
migrations/2025-04-05-114428_likes_and_reposts/down.sql
··· 1 1 drop table likes; 2 - drop table reposts; 2 + drop table reposts;
+2 -4
migrations/2025-04-05-114428_likes_and_reposts/up.sql
··· 10 10 primary key (did, rkey) 11 11 ); 12 12 13 - create index likes_did_index on likes (did); 14 - create index likes_subject_index on likes (subject); 13 + create index likes_subject_index on likes using hash (subject); 15 14 16 15 create table reposts 17 16 ( ··· 25 24 primary key (did, rkey) 26 25 ); 27 26 28 - create index reposts_did_index on reposts (did); 29 - create index reposts_post_index on reposts (post); 27 + create index reposts_post_index on reposts using hash (post);
+1 -1
migrations/2025-04-08-171113_chat-decl/down.sql
··· 1 - drop table chat_decls; 1 + drop table chat_decls;
+2 -2
migrations/2025-04-08-171113_chat-decl/up.sql
··· 1 1 create table chat_decls 2 2 ( 3 - did text primary key references actors (did), 3 + did text primary key references actors (did), 4 4 allow_incoming text not null, 5 5 indexed_at timestamp not null default now() 6 - ); 6 + );
+1 -1
migrations/2025-04-09-175735_starterpacks/down.sql
··· 1 - drop table starterpacks; 1 + drop table starterpacks;
+2 -2
migrations/2025-04-09-175735_starterpacks/up.sql
··· 1 1 create table starterpacks 2 2 ( 3 - at_uri text primary key, 3 + at_uri text primary key, 4 4 owner text not null references actors (did), 5 5 cid text not null, 6 6 record jsonb not null, ··· 9 9 description text, 10 10 description_facets jsonb, 11 11 list text not null, 12 - feeds text[], 12 + feeds text [], 13 13 14 14 created_at timestamptz not null default now(), 15 15 indexed_at timestamp not null default now()
+1 -1
migrations/2025-04-11-155301_labels/down.sql
··· 1 1 drop table labels; 2 2 drop table labeler_defs; 3 - drop table labelers; 3 + drop table labelers;
+5 -5
migrations/2025-04-11-155301_labels/up.sql
··· 1 1 create table labelers 2 2 ( 3 - did text primary key references actors (did) on delete cascade, 3 + did text primary key references actors (did) on delete cascade, 4 4 cid text not null, 5 5 6 - reasons text[], 7 - subject_types text[], 8 - subject_collections text[], 6 + reasons text [], 7 + subject_types text [], 8 + subject_collections text [], 9 9 10 10 created_at timestamp not null default now(), 11 11 indexed_at timestamp not null default now() ··· 13 13 14 14 create table labeler_defs 15 15 ( 16 - id serial primary key, 16 + id serial primary key, 17 17 18 18 labeler text not null references labelers (did) on delete cascade, 19 19 label_identifier text not null,
+1 -1
migrations/2025-04-18-185717_verification/down.sql
··· 1 - drop table verification; 1 + drop table verification;
+3 -3
migrations/2025-04-18-185717_verification/up.sql
··· 1 1 create table verification 2 2 ( 3 - at_uri text primary key, 3 + at_uri text primary key, 4 4 cid text not null, 5 5 verifier text not null references actors (did), 6 6 ··· 12 12 indexed_at timestamp not null default now() 13 13 ); 14 14 15 - create index verification_verifier_index on verification (verifier); 16 - create index verification_subject_index on verification (subject); 15 + create index verification_verifier_index on verification using hash (verifier); 16 + create index verification_subject_index on verification using hash (subject);
+1 -1
migrations/2025-05-03-103435_records/down.sql
··· 1 - drop table records; 1 + drop table records;
+1 -1
migrations/2025-05-03-103435_records/up.sql
··· 5 5 6 6 did text not null, 7 7 indexed_at timestamp not null default now() 8 - ); 8 + );
+1 -1
migrations/2025-06-11-192947_statuses/down.sql
··· 1 - drop table statuses; 1 + drop table statuses;
+2 -2
migrations/2025-06-11-192947_statuses/up.sql
··· 1 1 create table statuses 2 2 ( 3 - did text primary key references actors (did), 3 + did text primary key references actors (did), 4 4 status text not null, 5 5 duration int, 6 6 record jsonb not null, ··· 13 13 14 14 created_at timestamptz not null default now(), 15 15 indexed_at timestamp not null default now() 16 - ); 16 + );
+1 -1
migrations/2025-06-18-200415_like-repost-via/down.sql
··· 1 1 alter table likes drop column via_uri, drop column via_cid; 2 - alter table reposts drop column via_uri, drop column via_cid; 2 + alter table reposts drop column via_uri, drop column via_cid;
+4 -4
migrations/2025-06-18-200415_like-repost-via/up.sql
··· 1 1 alter table likes 2 - add column via_uri text, 3 - add column via_cid text; 2 + add column via_uri text, 3 + add column via_cid text; 4 4 5 5 alter table reposts 6 - add column via_uri text, 7 - add column via_cid text; 6 + add column via_uri text, 7 + add column via_cid text;
+1 -1
migrations/2025-07-21-173906_notif-decl/down.sql
··· 1 - drop table notif_decl; 1 + drop table notif_decl;
+2 -2
migrations/2025-07-21-173906_notif-decl/up.sql
··· 1 1 create table notif_decl 2 2 ( 3 - did text primary key references actors (did), 3 + did text primary key references actors (did), 4 4 allow_subscriptions text, 5 5 indexed_at timestamp not null default now() 6 - ); 6 + );
+1 -1
migrations/2025-08-03-125504_mutes/down.sql
··· 1 1 drop table list_mutes; 2 - drop table mutes; 2 + drop table mutes;
+1 -1
migrations/2025-08-03-125504_mutes/up.sql
··· 19 19 primary key (did, subject) 20 20 ); 21 21 22 - create index mutes_subject_index on mutes (subject); 22 + create index mutes_subject_index on mutes using hash (subject);
+1 -1
migrations/2025-09-02-190833_bookmarks/down.sql
··· 1 - drop table bookmarks; 1 + drop table bookmarks;
+2 -2
migrations/2025-09-02-190833_bookmarks/up.sql
··· 5 5 subject text not null, 6 6 subject_cid text, 7 7 subject_type text not null, 8 - tags text[] not null default ARRAY []::text[], 8 + tags text [] not null default array[]::text [], 9 9 10 10 created_at timestamptz not null default now(), 11 11 ··· 13 13 ); 14 14 15 15 create index bookmarks_rkey_index on bookmarks (rkey); 16 - create index bookmarks_subject_index on bookmarks (subject); 16 + create index bookmarks_subject_index on bookmarks using hash (subject); 17 17 create index bookmarks_subject_type_index on bookmarks (subject_type); 18 18 create index bookmarks_tags_index on bookmarks using gin (tags); 19 19 create unique index bookmarks_rkey_ui on bookmarks (did, rkey);
+33 -33
migrations/2025-09-17-190406_viewer-interactions/up.sql
··· 16 16 17 17 create view v_list_block_exp as 18 18 ( 19 - select lb.list_uri, did, li.subject 20 - from list_blocks lb 21 - inner join list_items li on lb.list_uri = li.list_uri 22 - ); 19 + select lb.list_uri, did, li.subject 20 + from list_blocks lb 21 + inner join list_items li on lb.list_uri = li.list_uri 22 + ); 23 23 24 24 create view v_list_mutes_exp as 25 25 ( 26 - select lm.list_uri, did, li.subject 27 - from list_mutes lm 28 - inner join list_items li on lm.list_uri = li.list_uri 29 - ); 26 + select lm.list_uri, did, li.subject 27 + from list_mutes lm 28 + inner join list_items li on lm.list_uri = li.list_uri 29 + ); 30 30 31 31 -- profile_states follow triggers 32 32 create function f_profile_state_ins_follow() returns trigger 33 - language plpgsql as 33 + language plpgsql as 34 34 $$ 35 35 begin 36 36 insert into profile_states (did, subject, following) ··· 46 46 $$; 47 47 48 48 create trigger t_profile_state_ins 49 - before insert 50 - on follows 51 - for each row 49 + before insert 50 + on follows 51 + for each row 52 52 execute procedure f_profile_state_ins_follow(); 53 53 54 54 create function f_profile_state_del_follow() returns trigger 55 - language plpgsql as 55 + language plpgsql as 56 56 $$ 57 57 begin 58 58 update profile_states set following = null where did = OLD.did and subject = OLD.subject; ··· 63 63 $$; 64 64 65 65 create trigger t_profile_state_del 66 - before delete 67 - on follows 68 - for each row 66 + before delete 67 + on follows 68 + for each row 69 69 execute procedure f_profile_state_del_follow(); 70 70 71 71 -- profile_states block triggers 72 72 73 73 create function f_profile_state_ins_block() returns trigger 74 - language plpgsql as 74 + language plpgsql as 75 75 $$ 76 76 begin 77 77 insert into profile_states (did, subject, blocking) ··· 87 87 $$; 88 88 89 89 create trigger t_profile_state_ins 90 - before insert 91 - on blocks 92 - for each row 90 + before insert 91 + on blocks 92 + for each row 93 93 execute procedure f_profile_state_ins_block(); 94 94 95 95 create function f_profile_state_del_block() returns trigger 96 - language plpgsql as 96 + language plpgsql as 97 97 $$ 98 98 begin 99 99 update profile_states set blocking = null where did = OLD.did and subject = OLD.subject; ··· 104 104 $$; 105 105 106 106 create trigger t_profile_state_del 107 - before delete 108 - on blocks 109 - for each row 107 + before delete 108 + on blocks 109 + for each row 110 110 execute procedure f_profile_state_del_block(); 111 111 112 112 -- profile_states mutes triggers 113 113 114 114 create function f_profile_state_ins_mute() returns trigger 115 - language plpgsql as 115 + language plpgsql as 116 116 $$ 117 117 begin 118 118 insert into profile_states (did, subject, muting) ··· 124 124 $$; 125 125 126 126 create trigger t_profile_state_ins 127 - before insert 128 - on mutes 129 - for each row 127 + before insert 128 + on mutes 129 + for each row 130 130 execute procedure f_profile_state_ins_mute(); 131 131 132 132 create function f_profile_state_del_mute() returns trigger 133 - language plpgsql as 133 + language plpgsql as 134 134 $$ 135 135 begin 136 136 update profile_states set muting = false where did = OLD.did and subject = OLD.subject; ··· 140 140 $$; 141 141 142 142 create trigger t_profile_state_del 143 - before delete 144 - on mutes 145 - for each row 146 - execute procedure f_profile_state_del_mute(); 143 + before delete 144 + on mutes 145 + for each row 146 + execute procedure f_profile_state_del_mute();
+2 -2
migrations/2025-09-24-205239_profiles-4224/down.sql
··· 1 1 alter table profiles 2 - drop column pronouns, 3 - drop column website; 2 + drop column pronouns, 3 + drop column website;
+2 -2
migrations/2025-09-24-205239_profiles-4224/up.sql
··· 1 1 alter table profiles 2 - add column pronouns text, 3 - add column website text; 2 + add column pronouns text, 3 + add column website text;
+3 -3
migrations/2025-09-27-171241_post-tweaks/down.sql
··· 1 1 alter table posts 2 - drop column mentions, 3 - drop column violates_threadgate; 2 + drop column mentions, 3 + drop column violates_threadgate; 4 4 5 5 drop trigger t_author_feed_ins_post on posts; 6 6 drop trigger t_author_feed_del_post on posts; ··· 12 12 drop function f_author_feed_ins_repost; 13 13 drop function f_author_feed_del_repost; 14 14 15 - drop table author_feeds; 15 + drop table author_feeds;
+19 -19
migrations/2025-09-27-171241_post-tweaks/up.sql
··· 1 1 alter table posts 2 - add column mentions text[], 3 - add column violates_threadgate bool not null default false; 2 + add column mentions text [], 3 + add column violates_threadgate bool not null default false; 4 4 5 5 create table author_feeds 6 6 ( 7 - uri text primary key, 7 + uri text primary key, 8 8 cid text not null, 9 9 post text not null, 10 10 did text not null, ··· 14 14 15 15 -- author_feeds post triggers 16 16 create function f_author_feed_ins_post() returns trigger 17 - language plpgsql as 17 + language plpgsql as 18 18 $$ 19 19 begin 20 20 insert into author_feeds (uri, cid, post, did, typ, sort_at) ··· 25 25 $$; 26 26 27 27 create trigger t_author_feed_ins_post 28 - before insert 29 - on posts 30 - for each row 28 + before insert 29 + on posts 30 + for each row 31 31 execute procedure f_author_feed_ins_post(); 32 32 33 33 create function f_author_feed_del_post() returns trigger 34 - language plpgsql as 34 + language plpgsql as 35 35 $$ 36 36 begin 37 37 delete from author_feeds where did = OLD.did and uri = OLD.at_uri and typ = 'post'; ··· 40 40 $$; 41 41 42 42 create trigger t_author_feed_del_post 43 - before delete 44 - on posts 45 - for each row 43 + before delete 44 + on posts 45 + for each row 46 46 execute procedure f_author_feed_del_post(); 47 47 48 48 -- author_feeds repost triggers 49 49 create function f_author_feed_ins_repost() returns trigger 50 - language plpgsql as 50 + language plpgsql as 51 51 $$ 52 52 begin 53 53 insert into author_feeds (uri, cid, post, did, typ, sort_at) ··· 58 58 $$; 59 59 60 60 create trigger t_author_feed_ins_repost 61 - before insert 62 - on reposts 63 - for each row 61 + before insert 62 + on reposts 63 + for each row 64 64 execute procedure f_author_feed_ins_repost(); 65 65 66 66 create function f_author_feed_del_repost() returns trigger 67 - language plpgsql as 67 + language plpgsql as 68 68 $$ 69 69 begin 70 70 delete from author_feeds where did = OLD.did and post = OLD.post and typ = 'repost'; ··· 73 73 $$; 74 74 75 75 create trigger t_author_feed_del_repost 76 - before delete 77 - on reposts 78 - for each row 76 + before delete 77 + on reposts 78 + for each row 79 79 execute procedure f_author_feed_del_repost();
+13 -13
migrations/2026-03-18-175443-0000_drafts/up.sql
··· 1 1 create table drafts ( 2 - did text not null references actors (did), 3 - draft_id text not null, -- draft_id is an rkey 2 + did text not null references actors (did), 3 + draft_id text not null, -- draft_id is an rkey 4 4 5 - device_id text, 6 - device_name text, 5 + device_id text, 6 + device_name text, 7 7 8 - posts jsonb not null, 9 - languages text [], 10 - postgate_embedding_rules text [], 11 - threadgate_allow text [], 12 - threadgate_allowed_lists text [], 8 + posts jsonb not null, 9 + languages text [], 10 + postgate_embedding_rules text [], 11 + threadgate_allow text [], 12 + threadgate_allowed_lists text [], 13 13 14 - created_at timestamptz not null default now (), 15 - updated_at timestamptz not null default now (), 14 + created_at timestamptz not null default now(), 15 + updated_at timestamptz not null default now(), 16 16 17 - primary key (did, draft_id) 18 - ) ; 17 + primary key (did, draft_id) 18 + );
+3 -3
migrations/2026-04-28-191914-0000_thread-mutes/up.sql
··· 1 1 create table thread_mutes 2 2 ( 3 - did text not null references actors (did), 4 - thread text not null, 3 + did text not null references actors (did), 4 + thread text not null, 5 5 created_at timestamptz not null default now(), 6 6 7 7 primary key (did, thread) 8 8 ); 9 9 10 - create index threadmutes_list_index on thread_mutes (thread); 10 + create index threadmutes_thread_index on thread_mutes using hash (thread);