2024-02-25 11:29:08 +01:00
|
|
|
alter table records alter content set compression lz4;
|
2024-02-19 20:05:50 +01:00
|
|
|
alter table records rename to records_like;
|
|
|
|
|
|
|
|
create table records
|
2024-02-25 11:29:08 +01:00
|
|
|
(like records_like including defaults including compression)
|
2024-02-19 20:05:50 +01:00
|
|
|
partition by list (collection);
|
|
|
|
|
|
|
|
drop index idx_repo_record_key;
|
|
|
|
drop index idx_repo_rev;
|
|
|
|
alter table records_like drop constraint records_pkey;
|
|
|
|
create unique index records_pkey on records (id, collection);
|
|
|
|
|
|
|
|
create table records_default
|
|
|
|
partition of records default;
|
|
|
|
|
|
|
|
create table records_post
|
|
|
|
partition of records for values in ('app.bsky.feed.post');
|
|
|
|
create table records_follow
|
|
|
|
partition of records for values in ('app.bsky.graph.follow');
|
|
|
|
create table records_block
|
|
|
|
partition of records for values in ('app.bsky.graph.block');
|
|
|
|
create table records_repost
|
|
|
|
partition of records for values in ('app.bsky.feed.repost');
|
|
|
|
create table records_profile
|
|
|
|
partition of records for values in ('app.bsky.actor.profile');
|
|
|
|
|
2024-02-23 03:54:29 +01:00
|
|
|
ALTER TABLE records_like
|
|
|
|
ADD CHECK (collection in ('app.bsky.feed.like'));
|
2024-02-22 03:09:12 +01:00
|
|
|
|
2024-02-23 03:54:29 +01:00
|
|
|
ALTER TABLE records_post
|
|
|
|
ADD CHECK (collection in ('app.bsky.feed.post'));
|
|
|
|
|
|
|
|
ALTER TABLE records_follow
|
|
|
|
ADD CHECK (collection in ('app.bsky.graph.follow'));
|
|
|
|
|
|
|
|
ALTER TABLE records_repost
|
|
|
|
ADD CHECK (collection in ('app.bsky.feed.repost'));
|
|
|
|
|
|
|
|
ALTER TABLE records_profile
|
|
|
|
ADD CHECK (collection in ('app.bsky.actor.profile'));
|
|
|
|
|
|
|
|
-- SLOW, can run overnight
|
2024-02-19 20:05:50 +01:00
|
|
|
with moved_rows as (
|
|
|
|
delete from records_like r
|
|
|
|
where collection <> 'app.bsky.feed.like'
|
|
|
|
returning r.*
|
|
|
|
)
|
|
|
|
insert into records select * from moved_rows;
|
|
|
|
|
2024-02-23 03:54:29 +01:00
|
|
|
-- ULTRA SLOW, DO NOT RUN on large DB
|
2024-02-19 20:05:50 +01:00
|
|
|
alter table records attach partition records_like for values in ('app.bsky.feed.like');
|
2024-02-20 16:36:52 +01:00
|
|
|
|
|
|
|
create index idx_like_subject
|
|
|
|
on records_like
|
|
|
|
(split_part(jsonb_extract_path_text(content, 'subject', 'uri'), '/', 3));
|
|
|
|
|
|
|
|
create index idx_follow_subject
|
|
|
|
on records_follow
|
|
|
|
(jsonb_extract_path_text(content, 'subject'));
|
|
|
|
|
|
|
|
create index idx_reply_subject
|
|
|
|
on records_post
|
|
|
|
(split_part(jsonb_extract_path_text(content, 'reply', 'parent', 'uri'), '/', 3));
|