#!/usr/bin/env bun
/**
* Generates src/server/scoped-db/schema.gen.ts: the DDL each scoped Durable Object (RepoState, AccountState)
* creates in its own SQLite, derived from the D1 migrations (which created and later dropped these tables in
* D1). Foreign keys to tables that live elsewhere are dropped (the referenced row is in another object or the D1
* directory); keys within a scope are kept.
*
* bun scripts/gen-scoped-schema.ts
*/
import { Database } from "bun:sqlite";
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
const ROOT = join(import.meta.dir, "..");
/**
* Access and social edges stay in the D1 directory on purpose: `collaborators`, `org_members`, `stars`,
* `watches` and `follows` are what "which repositories can this user see" and the social lists are computed
* from, and they are lookups rather than repository or account data.
*/
/** Tables that live in a repository's RepoState (and in a repo-less site's own 'site:<id>' object). */
export const REPO_TABLES: string[] = [
"issues",
"issues_fts",
"comments",
"issue_events",
"labels",
"issue_labels",
"milestones",
"issue_types",
"issue_assignees",
"pinned_issues",
"reactions",
"pull_requests",
"reviews",
"review_comments",
"review_requests",
"pull_issue_links",
"pull_auto_merges",
"issue_redirects",