Skip to content

Commit

Permalink
Deprecate posts and post comments, refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Dec 12, 2023
1 parent 726e439 commit 3c276e1
Show file tree
Hide file tree
Showing 35 changed files with 220 additions and 1,668 deletions.
4 changes: 0 additions & 4 deletions backend/api/src/app.ts
Expand Up @@ -29,7 +29,6 @@ import { closeMarket } from './close-market'
import { unsubscribe } from './unsubscribe'
import { stripewebhook, createcheckoutsession } from './stripe-endpoints'
import { getCurrentUser } from './get-current-user'
import { createpost } from './create-post'
import { saveTwitchCredentials } from './save-twitch-credentials'
import { addLiquidity } from './add-subsidy'
import { validateiap } from './validate-iap'
Expand All @@ -55,7 +54,6 @@ import { followtopic } from './follow-topic'
import { editcomment } from 'api/edit-comment'
import { supabasesearchgroups } from './supabase-search-groups'
import { leagueActivity } from './league-activity'
import { updatepost } from './update-post'
import { updategroup } from './update-group'
import { updateUserDisinterestEmbedding } from 'api/update-user-disinterests'
import { awardBounty } from './award-bounty'
Expand Down Expand Up @@ -265,8 +263,6 @@ app.post('/creategroup', ...apiRoute(creategroup))
app.post('/updategroup', ...apiRoute(updategroup))
app.post('/resolvemarket', ...apiRoute(resolveMarket))
app.post('/closemarket', ...apiRoute(closeMarket))
app.post('/createpost', ...apiRoute(createpost))
app.post('/updatepost', ...apiRoute(updatepost))
app.post('/validateIap', ...apiRoute(validateiap))
app.post('/markallnotifications', ...apiRoute(markallnotifications))
app.post('/updatememberrole', ...apiRoute(updatememberrole))
Expand Down
127 changes: 0 additions & 127 deletions backend/api/src/create-post.ts

This file was deleted.

20 changes: 0 additions & 20 deletions backend/api/src/update-post.ts

This file was deleted.

4 changes: 2 additions & 2 deletions backend/scripts/migrate-about-posts.sql
Expand Up @@ -6,7 +6,7 @@ create temp table
p.data -> 'content' as new
from
groups g
join posts p on g.data ->> 'aboutPostId' = p.id
join old_posts p on g.data ->> 'aboutPostId' = p.id
);

update groups
Expand All @@ -17,7 +17,7 @@ from
where
about_updates.id = groups.id;

delete from posts
delete from old_posts
where
id in (
select
Expand Down
28 changes: 12 additions & 16 deletions backend/scripts/supabase-import.ts
Expand Up @@ -168,7 +168,12 @@ async function importDatabase(
}

if (shouldImport('private_users'))
await importCollection(pg, firestore.collection('private-users'), 'private_users', 500)
await importCollection(
pg,
firestore.collection('private-users'),
'private_users',
500
)
if (shouldImport('users'))
await importCollection(pg, firestore.collection('users'), 'users', 500)
if (shouldImport('user_portfolio_history'))
Expand Down Expand Up @@ -306,15 +311,6 @@ async function importDatabase(
'manalinks',
2500
)
if (shouldImport('posts'))
await importCollection(pg, firestore.collection('posts'), 'posts', 100)
if (shouldImport('post_comments'))
await importCollectionGroup(pg,
firestore.collectionGroup('comments'),
'post_comments',
(c) => c.get('commentType') === 'post',
500
)
}

if (require.main === module) {
Expand Down Expand Up @@ -344,10 +340,10 @@ if (require.main === module) {
runScript(async ({ pg }) => {
await importDatabase(pg, tables, timestamp, chunk)
})
.then(() => {
log('Finished importing.')
})
.catch((e) => {
console.error(e)
})
.then(() => {
log('Finished importing.')
})
.catch((e) => {
console.error(e)
})
}
6 changes: 0 additions & 6 deletions backend/supabase/comments/rls.sql
Expand Up @@ -2,9 +2,3 @@
create policy "Enable read access for non private comments" on public.contract_comments for
select
using ((visibility <> 'private'::text));

drop policy if exists "Enable read access for non private post comments" on public.post_comments;

create policy "Enable read access for non private post comments" on public.post_comments for
select
using ((visibility <> 'private'::text));
13 changes: 0 additions & 13 deletions backend/supabase/comments/triggers.sql
Expand Up @@ -10,21 +10,8 @@ or replace function comment_populate_cols () returns trigger language plpgsql as
return new;
end $$;

create
or replace function post_comment_populate_cols () returns trigger language plpgsql as $$ begin
if new.data is not null then
new.visibility := (new.data)->>'visibility';
new.user_id := (new.data)->>'userId';
end if;
return new;
end $$;

create trigger comment_populate before insert
or
update on contract_comments for each row
execute function comment_populate_cols ();

create trigger post_comment_populate before insert
or
update on post_comments for each row
execute function post_comment_populate_cols ();
Expand Up @@ -2,8 +2,8 @@ create
or replace function can_access_private_post (this_post_id text, this_member_id text) returns boolean immutable parallel SAFE language sql as $$
select exists (
select 1
from posts
join group_members on group_members.group_id = posts.group_id
where posts.id = this_post_id
from old_posts
join group_members on group_members.group_id = old_posts.group_id
where old_posts.id = this_post_id
and group_members.member_id = this_member_id
) $$;
@@ -1,5 +1,5 @@
drop policy if exists "Enable read access for non private posts" on public.posts;
drop policy if exists "Enable read access for non private posts" on public.old_posts;

create policy "Enable read access for non private posts" on public.posts for
create policy "Enable read access for non private posts" on public.old_posts for
select
using (visibility <> 'private');
@@ -1,13 +1,13 @@
alter table posts
alter table old_posts
add column visibility text;

alter table posts
alter table old_posts
add column group_id text;

alter table posts
alter table old_posts
add column creator_id text;

alter table posts
alter table old_posts
add column created_time timestamptz;

create
Expand All @@ -22,5 +22,5 @@ end $$;

create trigger post_populate before insert
or
update on posts for each row
update on old_posts for each row
execute function post_populate_cols ();
42 changes: 5 additions & 37 deletions backend/supabase/seed.sql
Expand Up @@ -744,7 +744,7 @@ create table if not exists
alter table manalink_claims cluster on manalink_claims_pkey;

create table if not exists
posts (
old_posts (
id text not null primary key default uuid_generate_v4 (),
data jsonb not null,
visibility text,
Expand All @@ -754,46 +754,17 @@ create table if not exists
fs_updated_time timestamp
);

alter table posts enable row level security;
alter table old_posts enable row level security;

drop policy if exists "public read" on posts;
drop policy if exists "public read" on old_posts;

create policy "public read" on posts for
create policy "public read" on old_posts for
select
using (true);

alter table posts
alter table old_posts
cluster on posts_pkey;

create table if not exists
post_comments (
post_id text not null,
comment_id text not null default uuid_generate_v4 (),
data jsonb not null,
fs_updated_time timestamp,
visibility text,
user_id text,
created_time timestamptz default now(),
primary key (post_id, comment_id)
);

alter table post_comments enable row level security;

drop policy if exists "public read" on post_comments;

create policy "public read" on post_comments for
select
using (true);

drop policy if exists "user can insert" on post_comments;

create policy "user can insert" on post_comments for insert
with
check (true);

alter table post_comments
cluster on post_comments_pkey;

create table if not exists
user_recommendation_features (
user_id text not null primary key,
Expand Down Expand Up @@ -1042,9 +1013,6 @@ add table contract_bets;
alter publication supabase_realtime
add table contract_comments;

alter publication supabase_realtime
add table post_comments;

alter publication supabase_realtime
add table group_contracts;

Expand Down
8 changes: 0 additions & 8 deletions common/src/ad.ts

This file was deleted.

5 comments on commit 3c276e1

@vercel
Copy link

@vercel vercel bot commented on 3c276e1 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-mantic.vercel.app
docs-pi-teal.vercel.app
docs-git-main-mantic.vercel.app
docs.manifold.markets

@vercel
Copy link

@vercel vercel bot commented on 3c276e1 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 3c276e1 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 3c276e1 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dev – ./web

dev-git-main-mantic.vercel.app
dev-mantic.vercel.app
dev-manifold.vercel.app
dev.manifold.markets

@vercel
Copy link

@vercel vercel bot commented on 3c276e1 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.