mirror of
https://github.com/BillyOutlast/posthog.com.git
synced 2026-02-04 03:11:21 +01:00
* remove org providers * merge questions components * merge authentication components * merge question form components * move main login * move Squeak.tsx * merge question * update exports * split out replies component * begin rewriting question component * add the ability to fetch by permalink * move gatsby-source-squeak to ts * working questions table * working question permalink pages! * add images to questions table * basic login working * working topics pages * move topiGroup fetching * working topic groups * working login state * remove unused apiHost and organizationId params * fix useUser hook * small tweaks * rename Question.permalink to SqueakQuestion.permalink * remove reply resolver * remove useOrg hook * add back old CommunityQuestions components * update roadmap queries * fetch roadmaps * remove console.log * small tweaks * remove key * add squeak migration script * only fetch questions that match the current slug * unify useQuestions hook * fix build * change markdown component * search: removing padding * working reply! * expand question by default * replace username with email * working sign up * working question sidebar + remove pre-rendered question pages * add back pre-rendered question component pages * uncomment Changelog query * display multiple teams * remove updatedAt field * don't access avatar if it's null * fix question profile links * only add replies with profiles * fail when no question * fixes * remove ErrorBoundary from QuestionForm * remove old changelog page * delete ErrorBoundary component * working question posting * gravatar urls * working profiles * use questions component * reset password * display profile info in dropdown * post question to specific page * remove excess padding on replies * remove changelog from dropdown * make registering and signing in work * avatar fixes * login / registration error messages * more avatar fixes * update slugs in queries * fail on non-ok request to `/me` * add edit profiles * set all user roles to authenticated * upload avatars * use getAvatarURL * only show edit profile button on active user * fix question pages * working subscribe and unsubscribe endpoints * refactor useUser logic separate out logic to fetch and save the current user * working subscriptions * chore: remove misc console logs * use fetchUser in EditProfile * ensure all questions have profiles * add more misc to migration sql * use useRoadmap hook in Roadmap * working team roadmaps * show login when trying to subscribe as anon * fix profile TODO * add sortBy newest, popular, and activity * add back homepage roadmap * remove unused Changelog component * bring back reply actions * fix collapsed avatars * fix badge text * small ui improvements * mobile edit profile * add teams to profile sidebar * also show questions that user has replied to * hide discussions if no questions exist * reduce required reply count to show collapsed view * fix: return correct user from login and signUp methods * remove unused lib/api * add body to form preview * button labels on questionform * question page modal initial view * fix blur bug * try not passing slug on questions page * dark mode colors * dark mode fix * error messages * correct type of slugs object * more onBlur fixes * add logged in user email and add edit profile button back * remove log --------- Co-authored-by: Eli Kinsey <eli@ekinsey.dev> Co-authored-by: Cory Watilo <cww@watilo.com>
251 lines
8.9 KiB
SQL
251 lines
8.9 KiB
SQL
-- Importing existing records
|
|
|
|
-- Import users
|
|
SELECT
|
|
DISTINCT users.email,
|
|
sp.first_name AS first_name,
|
|
sp.last_name AS last_name,
|
|
users.email AS username,
|
|
'local' AS provider,
|
|
users.encrypted_password AS password,
|
|
users.confirmed_at IS NULL AS confirmed,
|
|
false AS blocked,
|
|
users.created_at,
|
|
1 AS created_by_id,
|
|
1 AS updated_by_id
|
|
FROM users
|
|
INNER JOIN (
|
|
SELECT * FROM squeak_profiles WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626'
|
|
) sp on users.id = sp.user_id;
|
|
|
|
-- Import profiles
|
|
-- ALTER SEQUENCE profiles_id_seq RESTART WITH 1;
|
|
SELECT row_number() OVER (ORDER BY squeak_profiles.created_at) AS id,
|
|
first_name,
|
|
last_name,
|
|
biography,
|
|
company,
|
|
company_role,
|
|
github,
|
|
linkedin,
|
|
location,
|
|
twitter,
|
|
website,
|
|
now() AS published_at,
|
|
squeak_profiles.created_at
|
|
FROM squeak_profiles
|
|
-- INNER JOIN users u on squeak_profiles.user_id = u.id
|
|
-- INNER JOIN up_users uu on u.email = uu.email
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626'
|
|
ORDER BY squeak_profiles.created_at;
|
|
|
|
-- Import existing avatars (Manually done by adjusting OFFSET and LIMIT
|
|
SELECT *
|
|
FROM (SELECT DISTINCT avatar
|
|
FROM squeak_profiles
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626'
|
|
AND length(avatar) > 0
|
|
AND avatar NOT ILIKE '%avatars.slack-edge.com%') ad
|
|
OFFSET 100 LIMIT 10;
|
|
|
|
-- Import questions
|
|
SELECT
|
|
squeak_messages.id AS id,
|
|
subject,
|
|
CASE published WHEN TRUE THEN now() END AS published_at,
|
|
permalink,
|
|
resolved,
|
|
now() AS updated_at,
|
|
reply.body,
|
|
created_at
|
|
FROM squeak_messages
|
|
INNER JOIN (
|
|
SELECT id, message_id, body
|
|
FROM (SELECT id,
|
|
body,
|
|
message_id,
|
|
rank() OVER (
|
|
PARTITION BY message_id ORDER BY created_at ASC
|
|
) rank
|
|
FROM squeak_replies) replies
|
|
WHERE replies.rank = 1
|
|
) reply ON reply.message_id = squeak_messages.id
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import question slugs
|
|
SELECT id, unnest(slug) AS slug FROM squeak_messages WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import replies
|
|
SELECT ranked_replies.id, body, created_at, CASE published WHEN TRUE THEN now() END AS published_at
|
|
FROM (SELECT *,
|
|
rank() OVER (PARTITION BY message_id ORDER BY created_at ASC) rank
|
|
FROM squeak_replies
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626') ranked_replies
|
|
WHERE rank > 1;
|
|
|
|
-- Import topics
|
|
SELECT id, label, created_at, now() AS updated_at, now() AS published_at, 1 AS created_by_id, 1 AS updated_by_id
|
|
FROM squeak_topics
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import topic groups
|
|
SELECT id, label, created_at, now() AS published_at, 1 AS created_by_id, 1 AS updated_by_id
|
|
FROM squeak_topic_groups
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import roadmaps
|
|
SELECT id,
|
|
title,
|
|
date_completed,
|
|
complete,
|
|
NULL AS slug,
|
|
description,
|
|
projected_completion_date AS projected_complete,
|
|
array_to_json(github_urls)::jsonb AS github_urls,
|
|
category,
|
|
milestone,
|
|
beta_available,
|
|
created_at,
|
|
1 AS created_by_id,
|
|
1 AS updated_by_id,
|
|
now() AS published_at
|
|
FROM squeak_roadmaps
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import teams
|
|
SELECT id, name, created_at, now() AS published_at, 1 AS created_by_id, 1 AS updated_by_id
|
|
FROM squeak_teams
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
|
|
-- Link records together
|
|
|
|
|
|
-- Connect profiles to users
|
|
SELECT uu.id AS user_id, profile_id FROM (
|
|
SELECT u.email, row_number() OVER (ORDER BY squeak_profiles.created_at) AS profile_id FROM squeak_profiles
|
|
LEFT JOIN users u on squeak_profiles.user_id = u.id
|
|
WHERE squeak_profiles.organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626'
|
|
ORDER BY squeak_profiles.created_at
|
|
) profiles
|
|
INNER JOIN up_users uu on profiles.email = uu.email;
|
|
|
|
-- Import connections between profiles and questions
|
|
SELECT rank_id AS profile_id, squeak_messages.id AS question_id FROM squeak_messages
|
|
INNER JOIN (
|
|
SELECT *, row_number() OVER (ORDER BY created_at) rank_id FROM squeak_profiles WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626' ORDER BY created_at
|
|
) ranked_profiles ON profile_id = ranked_profiles.id
|
|
WHERE squeak_messages.organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Link avatars to profiles
|
|
SELECT
|
|
files.id AS file_id,
|
|
rp.rank_id AS related_id,
|
|
'api::profile.profile' AS related_type,
|
|
'avatar' AS field
|
|
FROM files
|
|
INNER JOIN squeak_profiles sp ON sp.avatar ILIKE '%' || name || '%'
|
|
INNER JOIN (
|
|
SELECT *, row_number() OVER (ORDER BY created_at) rank_id FROM squeak_profiles WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626' ORDER BY created_at
|
|
) rp on rp.id = sp.id;
|
|
|
|
-- Import links between topics and topic groups
|
|
SELECT id AS topic_id, topic_group_id
|
|
FROM squeak_topics
|
|
WHERE topic_group_id IS NOT NULL
|
|
AND organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import connections between questions and topics
|
|
SELECT question_id, topic_id, sm.created_at FROM squeak_question_topics
|
|
INNER JOIN squeak_messages sm on squeak_question_topics.question_id = sm.id
|
|
WHERE sm.organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import connection between profiles and teams into team_members_links
|
|
SELECT st.id AS team_id,
|
|
rank_id AS profile_id
|
|
FROM users
|
|
INNER JOIN (SELECT *, row_number() OVER (ORDER BY created_at) AS rank_id
|
|
FROM squeak_profiles
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626'
|
|
ORDER BY created_at) sp on users.id = sp.user_id
|
|
INNER JOIN squeak_teams st on sp.team_id = st.id
|
|
WHERE sp.organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import connections between teams and roadmaps
|
|
SELECT id AS roadmap_id, "teamId" AS team_id
|
|
FROM squeak_roadmaps
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626' AND "teamId" IS NOT NULL;
|
|
|
|
-- Import connections between replies and profiles
|
|
SELECT DISTINCT ranked_replies.id AS reply_id, rank_id AS profile_id FROM (
|
|
SELECT
|
|
*,
|
|
rank() OVER (PARTITION BY message_id ORDER BY created_at ASC) rank
|
|
FROM squeak_replies
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626'
|
|
) ranked_replies
|
|
INNER JOIN (
|
|
SELECT *, row_number() OVER (ORDER BY created_at) AS rank_id FROM squeak_profiles WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626' ORDER BY created_at
|
|
) profiles ON profile_id = profiles.id
|
|
INNER JOIN (
|
|
SELECT up_users.id, u.id AS user_id FROM up_users
|
|
INNER JOIN users u ON u.email = up_users.email
|
|
) joined_users ON joined_users.user_id = profiles.user_id
|
|
WHERE rank > 1;
|
|
|
|
-- Import connections between replies and questions
|
|
SELECT ranked_replies.id AS reply_id, message_id AS question_id FROM (
|
|
SELECT
|
|
*,
|
|
rank() OVER (PARTITION BY message_id ORDER BY created_at ASC) rank
|
|
FROM squeak_replies
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626'
|
|
) ranked_replies
|
|
WHERE rank > 1;
|
|
|
|
-- Import connections between questions and slugs
|
|
SELECT
|
|
id AS entity_id,
|
|
id AS component_id,
|
|
'questions.slugs' AS component_type,
|
|
'slugs' AS field
|
|
FROM squeak_messages WHERE organization_id='a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Import connections between questions and resolutions
|
|
SELECT id AS question_id, resolved_reply_id AS reply_id FROM squeak_messages WHERE resolved_reply_id IS NOT NULL AND organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626';
|
|
|
|
-- Set all user roles to 'Authenticated'
|
|
SELECT id AS user_id, 1 AS role_id FROM up_users;
|
|
|
|
|
|
|
|
-- Miscellaneous
|
|
|
|
-- Ensure all questions have profiles
|
|
SELECT * FROM squeak_messages WHERE profile_id IS NULL;
|
|
|
|
UPDATE squeak_messages AS sm SET
|
|
profile_id = qs.profile_id
|
|
FROM (SELECT squeak_messages.id AS id,
|
|
sr.profile_id AS profile_id
|
|
FROM squeak_messages
|
|
INNER JOIN (SELECT *,
|
|
rank() OVER (PARTITION BY message_id ORDER BY created_at ASC) rank
|
|
FROM squeak_replies
|
|
WHERE organization_id = 'a898bcf2-c5b9-4039-82a0-a00220a8c626') sr
|
|
on squeak_messages.id = sr.message_id
|
|
WHERE squeak_messages.profile_id IS NULL
|
|
AND rank = 1) qs WHERE qs.id = sm.id;
|
|
|
|
|
|
-- Ensure all questions marked as 'resolved' have a corresponding reply
|
|
UPDATE questions SET resolved = false
|
|
WHERE questions.id IN (
|
|
SELECT questions.id AS id
|
|
FROM questions
|
|
LEFT JOIN questions_resolved_by_links qrbl on questions.id = qrbl.question_id
|
|
WHERE resolved = True AND qrbl.reply_id IS NULL
|
|
);
|
|
|
|
|