201 lines · 9.2 KB
import { all, batch, first, run, 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 { sitesOwnedBy } from "./sites/store";
import { accountDb, repoDb, stmt as scopedStmt } from "./scoped-db";
import { dropAccountState, forEachScope } from "./account-scope";
import { backfillDone } from "./backfill";
import { invitationOrgs } from "./invitation-index";
import { ACTIVITY_INDEX, touchedRepoIds } from "./activity-index";
import { userInbox } from "./user-inbox";
import { revokeAccessTokensWhere } from "./access-token-store";
import { revokeAllDeployTokensCreatedBy } from "./deploy-token-index";
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"],