Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump lovers #3503

Merged
merged 6 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions backend/scripts/dump-love-tables.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

pg_dump -U postgres -d manifold \
-t lovers \
-t love_answers \
-t love_compatability_answers \
-t love_likes \
-t love_questions \
-t love_ships \
-t love_waitlist \
-t private_user_channels \
-t private_user_seen_message_channels \
--function firebase_uid \
--function get_average_rating \
--function get_compatibility_questions_with_answer_count \
--function get_love_question_answers_and_lovers \
--function millis_interval \
--function millis_to_ts \
--function random_alphanumeric \
--function to_jsonb \
--function ts_to_millis \
77 changes: 77 additions & 0 deletions backend/scripts/dump-lovers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { runScript } from 'run-script'
import { type SupabaseDirectClient } from 'shared/supabase/init'
import * as fs from 'fs'

// get all users of manifold love but ONLY the data relevant to manifold love

runScript(({ pg }) => {
dumpUsers(pg)
dumpChats(pg)
})

const dumpUsers = async (pg: SupabaseDirectClient) => {
const user_results = await pg.many(`
SELECT
u.id,
u.username,
u.name,

-- select some keys from user data
u.data - array(select jsonb_object_keys(u.data)
- 'isBannedFromPosting'
- 'userDeleted'
- 'bio'
- 'website'
- 'twitterHandle'
- 'discordHandle'
- 'fromLove'
- 'sweestakesVerified'
- 'verifiedPhone'
- 'idVerified'
) as user_data,

-- select some keys from private user data
pu.data - array(select jsonb_object_keys(pu.data)
- 'email'
- 'notificationPreferences'
) as private_user_data

FROM lovers l
JOIN users u ON u.id = l.user_id
LEFT JOIN private_users pu ON u.id = pu.id
`)

const keys = Object.keys(user_results[0])
const csv = user_results
.map((row) => keys.map((k) => row.data[k]).join(','))
.join('\n')

fs.writeFileSync('users.csv', keys.join(',') + '\n' + csv)
}

const dumpChats = async (pg: SupabaseDirectClient) => {
const results = await pg.many(`
with love_channels as (
select mc.*
from private_user_message_channels mc
where not exists (
-- Check if any member is NOT a love user
select unnest(mc.member_ids) as user_id
except
select user_id from lovers
)
and mc.member_count > 0
)
select
pum.*
from love_channels lc
left join private_user_messages pum
on pum.channel_id = lc.channel_id
order by lc.channel_id, pum.created_time
`)

const keys = Object.keys(results[0])
const csv = results.map((row) => keys.map((k) => row[k]).join(',')).join('\n')

fs.writeFileSync('chats.csv', keys.join(',') + '\n' + csv)
}