Skip to content

Commit

Permalink
delete all fs_updated_time once and for all
Browse files Browse the repository at this point in the history
also deletes a bunch of views:

drop view public_open_contracts;
drop view trending_contracts;
drop view listed_open_contracts;
drop view contract_distance;
drop view user_contract_distance;

drop view public_contracts;

alter table contracts
drop column fs_updated_time;

create or replace view
  public_contracts as (
    select
      *
    from
      contracts
    where
      visibility = 'public'
  );

alter table answers
drop column fs_updated_time;

drop view private_contract_comments;

alter table contract_comments
drop column fs_updated_time;

alter table contract_liquidity
drop column fs_updated_time;

-- alter table group_contracts
-- drop column fs_updated_time;

alter table manalinks
drop column fs_updated_time;

alter table old_posts
drop column fs_updated_time;

alter table private_users
drop column fs_updated_time;

alter table user_contract_metrics
drop column fs_updated_time;

alter table user_notifications
drop column fs_updated_time;
  • Loading branch information
sipec committed Jul 9, 2024
1 parent 3ddf395 commit 1e4c734
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 806 deletions.
4 changes: 0 additions & 4 deletions backend/scripts/txn-native-columns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ create trigger txns_populate before insert
or
update on txns for each row
execute function txns_populate_cols ();

update txns
set
fs_updated_time = fs_updated_time;
2 changes: 0 additions & 2 deletions backend/shared/src/helpers/user-contract-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export async function updateContractMetricsForUsers(

export async function bulkUpdateContractMetrics(metrics: ContractMetric[]) {
const pg = createSupabaseDirectClient()
const updatedTime = new Date().toISOString()
return bulkUpsert(
pg,
'user_contract_metrics',
Expand All @@ -53,7 +52,6 @@ export async function bulkUpdateContractMetrics(metrics: ContractMetric[]) {
contract_id: m.contractId,
user_id: m.userId,
data: m,
fs_updated_time: updatedTime,
has_shares: m.hasShares,
profit: m.profit,
has_no_shares: m.hasNoShares,
Expand Down
9 changes: 2 additions & 7 deletions backend/shared/src/supabase/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ export const insertNotificationToSupabase = async (
pg: SupabaseDirectClient
) => {
return await pg.none(
`insert into postgres.public.user_notifications (user_id, notification_id, data, fs_updated_time) values ($1, $2, $3, $4) on conflict do nothing`,
[
notification.userId,
notification.id,
notification,
new Date().toISOString(),
]
`insert into postgres.public.user_notifications (user_id, notification_id, data) values ($1, $2, $3) on conflict do nothing`,
[notification.userId, notification.id, notification]
)
}
1 change: 0 additions & 1 deletion backend/supabase/answers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ create table if not exists
total_liquidity numeric default 0, -- for historical reasons, this the total subsidy amount added in M
subsidy_pool numeric default 0, -- current value of subsidy pool in M
data jsonb not null,
fs_updated_time timestamp,
text_fts tsvector generated always as (to_tsvector('english', text)) stored,
prob_change_day numeric default 0, -- change in prob in the last 24h
prob_change_week numeric default 0, -- change in prob in the last week
Expand Down
1 change: 0 additions & 1 deletion backend/supabase/contract_comments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ create table if not exists
contract_id text not null,
comment_id text not null,
data jsonb not null,
fs_updated_time timestamp,
primary key (contract_id, comment_id),
visibility text,
user_id text not null,
Expand Down
20 changes: 9 additions & 11 deletions backend/supabase/contract_liquidity.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@

create table if not exists
contract_liquidity (
contract_id text not null,
liquidity_id text not null,
data jsonb not null,
fs_updated_time timestamp,
primary key (contract_id, liquidity_id)
);
contract_liquidity (
contract_id text not null,
liquidity_id text not null,
data jsonb not null,
primary key (contract_id, liquidity_id)
);

alter table contract_liquidity enable row level security;

drop policy if exists "public read" on contract_liquidity;

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

alter table contract_liquidity
cluster on contract_liquidity_pkey;
cluster on contract_liquidity_pkey;
1 change: 0 additions & 1 deletion backend/supabase/contracts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ create table if not exists
add_creator_name_to_description (data)
)
) stored,
fs_updated_time timestamp,
deleted boolean default false,
group_slugs text[],
last_updated_time timestamptz,
Expand Down
35 changes: 15 additions & 20 deletions backend/supabase/group_contracts.sql
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@

create table if not exists
group_contracts (
group_id text not null,
contract_id text not null,
data jsonb,
fs_updated_time timestamp,
primary key (group_id, contract_id)
);
group_contracts (
group_id text not null,
contract_id text not null,
data jsonb,
primary key (group_id, contract_id)
);

alter table group_contracts enable row level security;

drop policy if exists "public read" on group_contracts;

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

create index if not exists group_contracts_contract_id on group_contracts (contract_id);

alter table group_contracts
cluster on group_contracts_pkey;
cluster on group_contracts_pkey;

create type group_with_score_and_bet_flag as (
id text,
data jsonb,
importance_score numeric,
has_bet boolean
id text,
data jsonb,
importance_score numeric,
has_bet boolean
);

create or replace function get_groups_and_scores_from_user_seen_markets(uid text)
returns setof group_with_score_and_bet_flag
language sql
as
$$
create
or replace function get_groups_and_scores_from_user_seen_markets (uid text) returns setof group_with_score_and_bet_flag language sql as $$
select (g.id, g.data, g.importance_score, false)::group_with_score_and_bet_flag
from
groups g
Expand Down
1 change: 0 additions & 1 deletion backend/supabase/manalinks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ create table if not exists
max_uses int null,
message text null,
data jsonb null,
fs_updated_time timestamp null
);

create index if not exists manalinks_creator_id on manalinks (creator_id);
Expand Down
24 changes: 11 additions & 13 deletions backend/supabase/old_posts.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@

create table if not exists
old_posts (
id text not null primary key default uuid_generate_v4 (),
data jsonb not null,
visibility text,
group_id text,
creator_id text,
created_time timestamptz default now(),
fs_updated_time timestamp
);
old_posts (
id text not null primary key default uuid_generate_v4 (),
data jsonb not null,
visibility text,
group_id text,
creator_id text,
created_time timestamptz default now(),
);

alter table old_posts enable row level security;

drop policy if exists "public read" on old_posts;

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

alter table old_posts
cluster on posts_pkey;
cluster on posts_pkey;
3 changes: 1 addition & 2 deletions backend/supabase/private_users.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ create table if not exists
private_users (
id text not null primary key,
data jsonb not null,
fs_updated_time timestamp,
weekly_trending_email_sent boolean default false,
weekly_portfolio_email_sent boolean default false
);
Expand All @@ -12,4 +11,4 @@ alter table private_users enable row level security;
alter table private_users
cluster on private_users_pkey;

create index if not exists private_users_data_api_key on private_users ((data->>'apiKey'));
create index if not exists private_users_data_api_key on private_users ((data ->> 'apiKey'));
1 change: 0 additions & 1 deletion backend/supabase/user_contract_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ create table if not exists
user_id text not null,
contract_id text not null,
data jsonb not null,
fs_updated_time timestamp,
has_yes_shares boolean,
has_no_shares boolean,
total_shares_yes numeric,
Expand Down
30 changes: 14 additions & 16 deletions backend/supabase/user_notifications.sql
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@

create table if not exists
user_notifications (
user_id text not null,
notification_id text not null,
data jsonb not null,
fs_updated_time timestamp not null,
primary key (user_id, notification_id)
);
user_notifications (
user_id text not null,
notification_id text not null,
data jsonb not null,
primary key (user_id, notification_id)
);

alter table user_notifications enable row level security;

drop policy if exists "public read" on user_notifications;

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

create index if not exists user_notifications_notification_id on user_notifications (notification_id, user_id);

create index if not exists user_notifications_created_time on user_notifications (user_id, (to_jsonb(data) -> 'createdTime') desc);

create index if not exists user_notifications_unseen_text_created_time_idx on user_notifications (
user_id,
-- Unfortunately casting to a boolean doesn't work in postgrest ((data->'isSeen')::boolean),
(data ->> 'isSeen'),
((data -> 'createdTime')::bigint) desc
);
user_id,
-- Unfortunately casting to a boolean doesn't work in postgrest ((data->'isSeen')::boolean),
(data ->> 'isSeen'),
((data -> 'createdTime')::bigint) desc
);

alter table user_notifications
cluster on user_notifications_created_time_idx;
cluster on user_notifications_created_time_idx;
66 changes: 0 additions & 66 deletions backend/supabase/views.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
create or replace view
public_open_contracts as (
select
*
from
contracts
where
resolution_time is null
and visibility = 'public'
and (
(close_time > now() + interval '10 minutes')
or close_time is null
)
);

create or replace view
public_contracts as (
select
Expand All @@ -23,57 +8,6 @@ create or replace view
visibility = 'public'
);

create or replace view
listed_open_contracts as (
select
*
from
contracts
where
resolution_time is null -- row level security prevents the 'private' contracts from being returned
and visibility != 'unlisted'
and (
(close_time > now() + interval '10 minutes')
or close_time is null
)
);

create or replace view
trending_contracts as (
select
*
from
listed_open_contracts
where
listed_open_contracts.importance_score > 0
order by
importance_score desc
);

create or replace view
contract_distance as (
select
ce1.contract_id as id1,
ce2.contract_id as id2,
ce1.embedding <= > ce2.embedding as distance
from
contract_embeddings ce1
cross join contract_embeddings ce2
order by
distance
);

create or replace view
user_contract_distance as (
select
user_id,
contract_id,
user_embeddings.interest_embedding <= > contract_embeddings.embedding as distance
from
user_embeddings
cross join contract_embeddings
);

drop view if exists group_role;

create view
Expand Down
1 change: 0 additions & 1 deletion common/src/supabase/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export async function getRecentTopLevelCommentsAndReplies(

export const convertContractComment = (row: Row<'contract_comments'>) =>
convertSQLtoTS<'contract_comments', ContractComment>(row, {
fs_updated_time: false,
created_time: tsToMillis as any,
})

Expand Down
1 change: 0 additions & 1 deletion common/src/supabase/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const REALTIME_TABLES: Partial<{ [T in TableName]: TableSpec<T> }> = {
},
user_notifications: {
pk: ['user_id', 'notification_id'],
ts: (r) => Date.parse(r.fs_updated_time),
},
user_contract_metrics: {
pk: ['user_id', 'contract_id'],
Expand Down
Loading

0 comments on commit 1e4c734

Please sign in to comment.