/* From the 'accounts' table username - id account_1_username - account_1_id account_2_username - account_2_id account_3_username - account_3_id account_4_username - account_4_id */ /* Tidy (DELETE FROM) the gotosocial db accounts table */ DELETE FROM public."accounts" a /* Don't remove any accounts with the following id's */ WHERE NOT (a."id" = ('account_1_id') OR a."id" = ('account_2_id') OR a."id" = ('account_3_id') OR a."id" = ('account_4_id')) /* Remove any accounts that are not followers */ AND NOT EXISTS (SELECT id FROM public."follows" f WHERE f."target_account_id" = a."id") /* Remove any accounts that are not followees */ AND NOT EXISTS (SELECT id FROM public."follows" f WHERE f."account_id" = a."id") AND NOT EXISTS /* Don't remove any accounts that are in the blocking table */ (SELECT id FROM public."blocks" b WHERE b."target_account_id" = a."id") AND NOT EXISTS /* Don't remove any accounts that are in the muting table */ (SELECT id FROM public."user_mutes" um WHERE um."target_account_id" = a."id"); /* Tidy (DELETE FROM) the gotosocial db accounts_stats table */ DELETE FROM public."account_stats" as2 /* Don't remove any stats with the following id's */ WHERE NOT (as2."account_id" = ('account_1_id') OR as2."account_id" = ('account_2_id') OR as2."account_id" = ('account_3_id') OR as2."account_id" = ('account_4_id')) /* Remove any stats that are not followers */ AND NOT EXISTS (SELECT id FROM public."follows" f WHERE f."target_account_id" = as2."account_id") /* Remove any stats that are not followees */ AND NOT EXISTS (SELECT id FROM public."follows" f WHERE f."account_id" = as2."account_id"); /* Tidy (DELETE FROM) the gotosocial db tokens table */ DELETE FROM public."tokens" /* Keeping the (bot) sessions */ WHERE "access" NOT LIKE 'AUTH_TOKEN'; /* Keeping this even though it has been commented out to remind */ /* me that for some reason this 'DELETE' nukes ALL the 'statuses' */ /* Tidy (DELETE FROM) the gotosocial db applications table */ --DELETE FROM -- public."applications" /* Keeping the (bot) sessions */ --WHERE "client_id" NOT LIKE 'bot_account_id'; /* Tidy (TRUNCATE) the gotosocial db tables: public.clients public.emojis public.tombstones */ TRUNCATE public.clients, public.emojis, public.tombstones; /* Tidy (VACUUM.ANALYZE) the gotosocial db */ VACUUM ANALYZE;