147 lines · 6.6 KB
import { all, batch, first, stmt } from "./db";
import { badRequest, conflict } from "./errors";
import { loadRepoById } from "./repos";
import { deleteRepository } from "./repo-ops";
import { deleteRunnerRow } from "./ci/runner-registration";
import { disableSite } from "./sites/site";
import type { SiteRow } from "./sites/config";
import { ACTIVE_STATUSES, customerFor } from "./billing/checkout";
import { stripe, stripeEnabled } from "./billing/config";
import { cancelDomainAddon } from "./billing/domain-addon";
import { emailTemplates, queueEmail } from "./email";
import { GHOST } from "./people";
import { discardAccountExport } from "./account-export";
import type { Viewer } from "~/lib/types";

export const MAX_USER_REPOS_DELETED = 100;

/**
 * Authored rows that must outlive the account so other people's conversations stay intact. They are
 * reassigned to the shared `ghost` account (GitHub's model) because these columns are NOT NULL or carry
 * no ON DELETE action; everything else keyed to the user cascades or is nulled with the account row.
 */
const GHOSTED_COLUMNS = [
  ["issues", "author_id"],
  ["issues", "closed_by"],
  ["comments", "author_id"],
  ["issue_events", "actor_id"],
  ["reviews", "author_id"],
  ["reviews", "dismissed_by"],
  ["review_comments", "author_id"],
  ["pull_requests", "merged_by"],
  ["pull_auto_merges", "enabled_by"],
  ["merge_queue_entries", "enqueued_by"],
  ["pull_issue_links", "created_by"],
  ["discussions", "author_id"],
  ["discussion_comments", "author_id"],
  ["attachments", "uploader_id"],
  ["projects", "created_by"],
  ["releases", "author_id"],
  ["workflow_runs", "actor_id"],