import { callback2 } from "@cocalc/util/async-utils" ; import { PostgreSQL } from "./types" ; export async function permanently_unlink_all_deleted_projects_of_user ( db , account_id_or_email_address ) { const account_id = await get_account_id ( db , account_id_or_email_address ) ; await callback2 ( db . _query , { query : "UPDATE projects" , set : { users : null } , where : [ "deleted  = true" , `users#>'{${ account_id }}' IS NOT NULL` ] , } ) ; } async function get_account_id ( db , account_id_or_email_address ) { if ( account_id_or_email_address . indexOf ( "@" ) == - 1 ) { return account_id_or_email_address ; } return ( await callback2 ( db . get_account , { email_address : account_id_or_email_address , columns : [ "account_id" ] , } ) ) . account_id ; } export async function unlink_old_deleted_projects ( db , age_d = 30 ) { await callback2 ( db . _query , { query : "UPDATE projects" , set : { users : null } , where : [ "deleted  = true" , "users IS NOT NULL" , `last_edited <= NOW() - '${ age_d } days'::INTERVAL` , ] , } ) ; }