From 1897a01112d2bd9fcc1c7769ed36eeb2d778026d Mon Sep 17 00:00:00 2001 From: Sid Jain Date: Sun, 27 Sep 2026 20:04:51 +0000 Subject: [PATCH 1/2] perf: freeze daily history and reduce database churn --- drizzle/0023_daily_history.sql | 194 + drizzle/meta/0023_snapshot.json | 3786 ++++++++++++++++++ drizzle/meta/_journal.json | 7 + knip.jsonc | 14 - knip.ts | 32 + package.json | 4 +- scripts/configure-codex-account.ts | 80 +- scripts/configure-supabase-cron.ts | 7 + scripts/migrate-daily-history.ts | 68 + scripts/migrate-production-database.ts | 1 + scripts/test-daily-history-database.ts | 770 ++++ src/app/api/cron/codex-stats/route.ts | 4 +- src/app/api/github/activity/route.ts | 7 - src/components/github-activity-days.tsx | 45 +- src/components/github-timeline-pager.tsx | 19 +- src/db/codex-schema.ts | 22 + src/db/schema.ts | 237 +- src/lib/codex/analytics.ts | 192 +- src/lib/codex/daily-history.ts | 122 + src/lib/codex/public-stats.ts | 147 +- src/lib/codex/stats.ts | 21 +- src/lib/codex/store.ts | 207 +- src/lib/codex/sync.ts | 81 +- src/lib/github-activity-cursor.ts | 8 +- src/lib/github-activity-feed-core.ts | 42 +- src/lib/github-activity-feed.ts | 2 +- src/lib/github-activity-snapshots.ts | 283 ++ src/lib/github-activity-store.ts | 261 +- src/lib/github-activity-worker-store.ts | 136 +- src/lib/github-backfill-store.ts | 19 +- src/lib/github-commits-store.ts | 107 +- src/lib/github-pull-request-store.ts | 245 +- src/lib/github-repository-inventory.ts | 5 +- src/lib/github-repository-store.ts | 5 +- src/lib/github-work-unit-projection-state.ts | 18 +- src/lib/github-work-unit-store.ts | 287 +- src/lib/github-work-unit-summary-store.ts | 141 +- tests/codex-stats.test.ts | 17 +- tests/daily-history-database.test.ts | 45 + tests/daily-history.test.ts | 187 + tests/github-activity-cursor.test.ts | 7 +- tests/github-activity-days.test.tsx | 21 +- tests/github-activity-feed-core.test.ts | 22 +- tests/github-activity-schema.test.ts | 36 +- tests/hourly-publication-resilience.test.ts | 12 +- tests/knip.test.ts | 98 + tests/token-details.test.tsx | 8 +- 47 files changed, 6868 insertions(+), 1211 deletions(-) create mode 100644 drizzle/0023_daily_history.sql create mode 100644 drizzle/meta/0023_snapshot.json delete mode 100644 knip.jsonc create mode 100644 knip.ts create mode 100644 scripts/migrate-daily-history.ts create mode 100644 scripts/test-daily-history-database.ts create mode 100644 src/lib/codex/daily-history.ts create mode 100644 src/lib/github-activity-snapshots.ts create mode 100644 tests/daily-history-database.test.ts create mode 100644 tests/daily-history.test.ts create mode 100644 tests/knip.test.ts diff --git a/drizzle/0023_daily_history.sql b/drizzle/0023_daily_history.sql new file mode 100644 index 00000000..b5516265 --- /dev/null +++ b/drizzle/0023_daily_history.sql @@ -0,0 +1,194 @@ +CREATE TABLE "codex_usage_days" ( + "account_id" varchar(64) NOT NULL, + "day" date NOT NULL, + "payload" jsonb NOT NULL, + "recorded_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "codex_usage_days_account_id_day_pk" PRIMARY KEY("account_id","day") +); +--> statement-breakpoint +ALTER TABLE "codex_usage_days" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint +CREATE TABLE "github_activity_snapshots" ( + "day" date NOT NULL, + "identity_key" varchar(180) NOT NULL, + "repository_id" varchar(32) NOT NULL, + "payload" jsonb NOT NULL, + "work_unit_id" uuid, + "work_unit_revision" integer, + "attribution_mode" varchar(32), + "facts_digest" varchar(64), + "outcome_digest" varchar(64), + "summary_input_digest" varchar(64), + "recorded_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "github_activity_snapshots_day_identity_key_pk" PRIMARY KEY("day","identity_key") +); +--> statement-breakpoint +ALTER TABLE "github_activity_snapshots" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint +ALTER TABLE "github_commits" ALTER COLUMN "file_facts_digest" DROP EXPRESSION;--> statement-breakpoint +ALTER TABLE "codex_accounts" ADD COLUMN "provider_account_id" varchar(200);--> statement-breakpoint +ALTER TABLE "codex_accounts" ADD COLUMN "sync_token" uuid;--> statement-breakpoint +ALTER TABLE "codex_accounts" ADD COLUMN "sync_until" timestamp with time zone;--> statement-breakpoint +ALTER TABLE "github_commits" ADD COLUMN "file_facts_pruned_at" timestamp with time zone;--> statement-breakpoint +ALTER TABLE "github_public_feed_head" ADD COLUMN "history_initialized_at" timestamp with time zone;--> statement-breakpoint +ALTER TABLE "github_repositories" ADD COLUMN "projection_request_token" uuid;--> statement-breakpoint +ALTER TABLE "codex_usage_days" ADD CONSTRAINT "codex_usage_days_account_id_codex_accounts_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."codex_accounts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "github_activity_snapshots_latest_idx" ON "github_activity_snapshots" USING btree ("identity_key","day" DESC NULLS LAST);--> statement-breakpoint +CREATE INDEX "github_activity_snapshots_repository_idx" ON "github_activity_snapshots" USING btree ("repository_id");--> statement-breakpoint +ALTER TABLE "codex_accounts" ADD CONSTRAINT "codex_accounts_provider_account_id_unique" UNIQUE("provider_account_id"); +--> statement-breakpoint +-- Bind aliases before historical accounts become visible together. Duplicate +-- provider identities fail the migration rather than silently counting twice. +DO $$ BEGIN + IF to_regclass('vault.decrypted_secrets') IS NOT NULL THEN + EXECUTE $identity$ + UPDATE codex_accounts a SET provider_account_id = s.decrypted_secret::jsonb #>> '{tokens,account_id}' + FROM vault.decrypted_secrets s WHERE s.name = 'codex_auth_' || a.id + $identity$; + END IF; +END $$; +--> statement-breakpoint +-- Preserve the generated digest when only disposable patches are removed. +CREATE FUNCTION record_github_commit_file_digest() RETURNS trigger +LANGUAGE plpgsql SET search_path = public AS $$ +BEGIN + IF TG_OP = 'UPDATE' AND NEW.file_facts_pruned_at IS NOT NULL THEN + IF NEW.file_facts IS DISTINCT FROM OLD.file_facts AND NEW.file_facts IS DISTINCT FROM ( + SELECT jsonb_agg(value || jsonb_build_object('patch', null, 'patchComplete', false) ORDER BY position) + FROM jsonb_array_elements(OLD.file_facts) WITH ORDINALITY AS entry(value, position) + ) THEN RAISE EXCEPTION 'Pruning cannot change compact commit facts'; END IF; + NEW.file_facts_digest := OLD.file_facts_digest; + ELSE + NEW.file_facts_digest := CASE WHEN NEW.file_facts IS NULL THEN NULL ELSE encode(sha256(jsonb_send(NEW.file_facts)), 'hex') END; + END IF; + RETURN NEW; +END; +$$; +--> statement-breakpoint +CREATE TRIGGER record_github_commit_file_digest BEFORE INSERT OR UPDATE OF file_facts, file_facts_pruned_at +ON github_commits FOR EACH ROW EXECUTE FUNCTION record_github_commit_file_digest(); +--> statement-breakpoint +CREATE FUNCTION protect_github_activity_history() RETURNS trigger +LANGUAGE plpgsql SET search_path = public AS $$ +BEGIN + IF OLD.day < (clock_timestamp() AT TIME ZONE 'Asia/Kolkata')::date THEN + IF TG_OP = 'DELETE' THEN RAISE EXCEPTION 'Closed activity cannot be deleted'; END IF; + IF NEW.day <> OLD.day OR NEW.identity_key <> OLD.identity_key OR NEW.repository_id <> OLD.repository_id + OR (NEW.payload - 'headline' - 'summary' - 'summarizing') IS DISTINCT FROM (OLD.payload - 'headline' - 'summary' - 'summarizing') + OR (OLD.payload->>'headline' IS NOT NULL AND NEW.payload IS DISTINCT FROM OLD.payload) + THEN RAISE EXCEPTION 'Closed activity facts are immutable'; END IF; + END IF; + IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; + RETURN NEW; +END; +$$; +--> statement-breakpoint +CREATE TRIGGER protect_github_activity_history BEFORE UPDATE OR DELETE ON github_activity_snapshots +FOR EACH ROW EXECUTE FUNCTION protect_github_activity_history(); +--> statement-breakpoint +ALTER TABLE "github_pull_request_memberships" DROP CONSTRAINT "gh_pr_memberships_version_fk"; +--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD COLUMN "file_facts" jsonb;--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD COLUMN "file_facts_digest" varchar(64) GENERATED ALWAYS AS (CASE WHEN "file_facts" IS NULL THEN NULL ELSE encode(sha256(jsonb_send("file_facts")), 'hex') END) STORED;--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD COLUMN "file_facts_complete" boolean DEFAULT false NOT NULL;--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD COLUMN "membership_complete" boolean DEFAULT false NOT NULL;--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD COLUMN "merge_snapshot" boolean DEFAULT false NOT NULL;--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD COLUMN "snapshot_id" uuid;--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD COLUMN "snapshot_observed_at" timestamp with time zone;--> statement-breakpoint +ALTER TABLE "github_push_observations" ADD COLUMN "known_shas" text[] DEFAULT ARRAY[]::text[] NOT NULL;--> statement-breakpoint +CREATE UNIQUE INDEX "github_pull_requests_snapshot_unique" ON "github_pull_requests" USING btree ("snapshot_id");--> statement-breakpoint +-- Preserve the exact current evidence IDs/digests used by live work and summaries. +UPDATE github_pull_requests p SET + snapshot_id = v.id, snapshot_observed_at = v.observed_at, + base_ref_name = v.base_ref_name, base_repository_id = v.base_repository_id, + base_sha = v.base_sha, head_ref_name = v.head_ref_name, + head_repository_id = v.head_repository_id, head_sha = v.head_sha, + commit_count = v.commit_count, file_facts = v.file_facts, + file_facts_complete = v.file_facts_complete, + membership_complete = v.membership_complete, merge_snapshot = v.merge_snapshot +FROM github_pull_request_versions v WHERE v.pull_request_node_id = p.node_id AND v.is_current; +--> statement-breakpoint +DELETE FROM github_pull_request_memberships m WHERE NOT EXISTS ( + SELECT 1 FROM github_pull_requests p WHERE p.snapshot_id = m.version_id +); +--> statement-breakpoint +-- Refuse corrupted legacy lists rather than quietly changing their order/repository. +DO $$ BEGIN + IF EXISTS (SELECT 1 FROM github_push_observation_commits c + JOIN github_push_observations o ON o.id = c.observation_id + GROUP BY o.id HAVING bool_or(c.repository_id <> o.repository_id) + OR min(c.position) <> 0 OR max(c.position) <> count(*) - 1) THEN + RAISE EXCEPTION 'Invalid legacy push commit evidence'; + END IF; +END $$; +--> statement-breakpoint +UPDATE github_push_observations o SET known_shas = c.shas FROM ( + SELECT observation_id, array_agg(sha::text ORDER BY position) AS shas + FROM github_push_observation_commits GROUP BY observation_id +) c WHERE c.observation_id = o.id; +--> statement-breakpoint +-- Accepted attempts already survive removal of their live work unit. Import +-- cache-only outputs as zero-start accepted attempts; never invent paid usage. +INSERT INTO github_work_unit_summary_attempts + (work_unit_id, revision, identity_key, repository_id, attribution_mode, recipe, + outcome_digest, summary_input_digest, outcome, state, accepted_at, completed_at, debounce_until) +SELECT gen_random_uuid(), 1, s.identity_key, s.repository_id, s.attribution_mode, s.recipe, + s.outcome_digest, s.summary_input_digest, s.outcome, 'accepted', s.accepted_at, s.accepted_at, s.accepted_at +FROM github_work_unit_accepted_summaries s WHERE NOT EXISTS ( + SELECT 1 FROM github_work_unit_summary_attempts a WHERE a.state = 'accepted' + AND a.identity_key = s.identity_key AND a.repository_id = s.repository_id + AND a.attribution_mode = s.attribution_mode AND a.recipe = s.recipe + AND a.outcome_digest = s.outcome_digest AND a.summary_input_digest = s.summary_input_digest + AND a.outcome = s.outcome AND a.accepted_at = s.accepted_at +); +--> statement-breakpoint +ALTER TABLE "github_pull_request_memberships" ADD CONSTRAINT "gh_pr_memberships_version_fk" FOREIGN KEY ("version_id") REFERENCES "public"."github_pull_requests"("snapshot_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "gh_work_unit_summary_accepted_outcome_idx" ON "github_work_unit_summary_attempts" USING btree ("repository_id","outcome_digest","attribution_mode","recipe","accepted_at") WHERE "github_work_unit_summary_attempts"."state" = 'accepted';--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD CONSTRAINT "github_pull_requests_file_facts_array" CHECK ("github_pull_requests"."file_facts" IS NULL OR jsonb_typeof("github_pull_requests"."file_facts") = 'array');--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD CONSTRAINT "github_pull_requests_file_facts_complete" CHECK (NOT "github_pull_requests"."file_facts_complete" OR "github_pull_requests"."file_facts" IS NOT NULL);--> statement-breakpoint +ALTER TABLE "github_pull_requests" ADD CONSTRAINT "github_pull_requests_snapshot" CHECK (("github_pull_requests"."snapshot_id" IS NULL) = ("github_pull_requests"."snapshot_observed_at" IS NULL) AND ("github_pull_requests"."snapshot_id" IS NULL OR ("github_pull_requests"."base_sha" IS NOT NULL AND "github_pull_requests"."head_sha" IS NOT NULL))); +--> statement-breakpoint +CREATE FUNCTION github_commit_evidence_needed(repo text, commit_sha text) RETURNS boolean +LANGUAGE sql STABLE SET search_path = public AS $$ + SELECT EXISTS (SELECT 1 FROM github_work_unit_memberships WHERE logical_repository_id = repo AND logical_sha = $2) + OR EXISTS (SELECT 1 FROM github_ref_memberships m WHERE m.commit_repository_id = repo AND m.commit_sha = $2) + OR EXISTS (SELECT 1 FROM github_pull_request_memberships m JOIN github_pull_requests p ON p.snapshot_id = m.version_id + WHERE m.commit_repository_id = repo AND m.commit_sha = $2) + OR EXISTS (SELECT 1 FROM github_work_unit_summary_attempts WHERE repository_id = repo + AND state IN ('pending', 'processing', 'retryable')) +$$; +--> statement-breakpoint +CREATE FUNCTION cleanup_activity_history() RETURNS jsonb +LANGUAGE plpgsql SET search_path = public AS $$ +DECLARE commits integer; logs integer := 0; +BEGIN + PERFORM pg_advisory_xact_lock(hashtext('github-work-unit-projection-v1')); + IF NOT EXISTS (SELECT 1 FROM github_public_feed_head WHERE history_initialized_at IS NOT NULL) THEN + RAISE EXCEPTION 'Initialize saved history before retention'; + END IF; + UPDATE github_commits c SET file_facts_pruned_at = clock_timestamp(), file_facts = ( + SELECT jsonb_agg(value || jsonb_build_object('patch', null, 'patchComplete', false) ORDER BY position) + FROM jsonb_array_elements(c.file_facts) WITH ORDINALITY AS entry(value, position) + ) WHERE c.file_facts_pruned_at IS NULL AND jsonb_array_length(c.file_facts) > 0 + AND c.first_observed_at < now() - interval '30 days' + AND c.enrichment_state = 'complete' AND c.pr_discovery_state = 'complete' + AND NOT github_commit_evidence_needed(c.repository_id, c.sha); + GET DIAGNOSTICS commits = ROW_COUNT; + IF to_regclass('cron.job_run_details') IS NOT NULL THEN + EXECUTE 'DELETE FROM cron.job_run_details WHERE end_time < now() - interval ''7 days'''; + GET DIAGNOSTICS logs = ROW_COUNT; + END IF; + RETURN jsonb_build_object('commitPatches', commits, 'cronLogs', logs); +END; +$$; +--> statement-breakpoint +-- No CASCADE: an unexpected dependency must abort this transaction. +DROP TABLE github_pull_request_versions; +--> statement-breakpoint +DROP TABLE github_push_observation_commits; +--> statement-breakpoint +DROP TABLE github_work_unit_accepted_summaries; +--> statement-breakpoint +REVOKE ALL ON FUNCTION cleanup_activity_history() FROM PUBLIC; +--> statement-breakpoint +UPDATE github_repositories SET projection_request_token = gen_random_uuid(); +--> statement-breakpoint +UPDATE github_public_feed_head SET projection_request_token = gen_random_uuid(); diff --git a/drizzle/meta/0023_snapshot.json b/drizzle/meta/0023_snapshot.json new file mode 100644 index 00000000..dc7ecd0a --- /dev/null +++ b/drizzle/meta/0023_snapshot.json @@ -0,0 +1,3786 @@ +{ + "id": "5bcfa2c4-da42-4b15-ad73-6c0811ebbd08", + "prevId": "9948f913-1fd3-4315-a57d-c9f1bbc15e7f", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.codex_accounts": { + "name": "codex_accounts", + "schema": "", + "columns": { + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "provider_account_id": { + "name": "provider_account_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "sync_token": { + "name": "sync_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "sync_until": { + "name": "sync_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "snapshot": { + "name": "snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "snapshot_at": { + "name": "snapshot_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "codex_accounts_provider_account_id_unique": { + "name": "codex_accounts_provider_account_id_unique", + "nullsNotDistinct": false, + "columns": ["provider_account_id"] + } + }, + "policies": {}, + "checkConstraints": { + "codex_accounts_id_shape": { + "name": "codex_accounts_id_shape", + "value": "\"codex_accounts\".\"id\" ~ '^[a-z0-9][a-z0-9_-]{0,63}$'" + }, + "codex_accounts_snapshot_pair": { + "name": "codex_accounts_snapshot_pair", + "value": "(\"codex_accounts\".\"snapshot\" IS NULL) = (\"codex_accounts\".\"snapshot_at\" IS NULL)" + }, + "codex_accounts_snapshot_object": { + "name": "codex_accounts_snapshot_object", + "value": "\"codex_accounts\".\"snapshot\" IS NULL OR jsonb_typeof(\"codex_accounts\".\"snapshot\") = 'object'" + } + }, + "isRLSEnabled": true + }, + "public.codex_usage_days": { + "name": "codex_usage_days", + "schema": "", + "columns": { + "account_id": { + "name": "account_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "recorded_at": { + "name": "recorded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "codex_usage_days_account_id_codex_accounts_id_fk": { + "name": "codex_usage_days_account_id_codex_accounts_id_fk", + "tableFrom": "codex_usage_days", + "tableTo": "codex_accounts", + "columnsFrom": ["account_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "codex_usage_days_account_id_day_pk": { + "name": "codex_usage_days_account_id_day_pk", + "columns": ["account_id", "day"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": true + }, + "public.github_account_checkpoints": { + "name": "github_account_checkpoints", + "schema": "", + "columns": { + "account": { + "name": "account", + "type": "varchar(39)", + "primaryKey": true, + "notNull": true + }, + "events_etag": { + "name": "events_etag", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "events_last_attempted_at": { + "name": "events_last_attempted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "events_last_succeeded_at": { + "name": "events_last_succeeded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "events_next_poll_at": { + "name": "events_next_poll_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "gap_detected_at": { + "name": "gap_detected_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "gap_expected_event_id": { + "name": "gap_expected_event_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "gap_oldest_available_event_id": { + "name": "gap_oldest_available_event_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "gap_state": { + "name": "gap_state", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true, + "default": "'clear'" + }, + "latest_event_id": { + "name": "latest_event_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "paused": { + "name": "paused", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "pull_request_backfill_digest": { + "name": "pull_request_backfill_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "head_ref_cursor_repository_id": { + "name": "head_ref_cursor_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "head_ref_cycle_started_at": { + "name": "head_ref_cycle_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "head_ref_last_attempted_at": { + "name": "head_ref_last_attempted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "head_ref_last_succeeded_at": { + "name": "head_ref_last_succeeded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "head_ref_lease_token": { + "name": "head_ref_lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "head_ref_lease_until": { + "name": "head_ref_lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "head_ref_next_page": { + "name": "head_ref_next_page", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "head_ref_scan_started_at": { + "name": "head_ref_scan_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ref_backfill_since_at": { + "name": "ref_backfill_since_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "tag_ref_cursor_repository_id": { + "name": "tag_ref_cursor_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "tag_ref_cycle_started_at": { + "name": "tag_ref_cycle_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "tag_ref_last_attempted_at": { + "name": "tag_ref_last_attempted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "tag_ref_last_succeeded_at": { + "name": "tag_ref_last_succeeded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "tag_ref_lease_token": { + "name": "tag_ref_lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "tag_ref_lease_until": { + "name": "tag_ref_lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "tag_ref_next_page": { + "name": "tag_ref_next_page", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tag_ref_scan_started_at": { + "name": "tag_ref_scan_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_account_checkpoints_tracked_account": { + "name": "github_account_checkpoints_tracked_account", + "value": "\"github_account_checkpoints\".\"account\" ~ '^[a-z0-9]([a-z0-9-]{0,37}[a-z0-9])?$'" + }, + "github_account_checkpoints_event_id_shape": { + "name": "github_account_checkpoints_event_id_shape", + "value": "(\"github_account_checkpoints\".\"latest_event_id\" IS NULL OR \"github_account_checkpoints\".\"latest_event_id\" ~ '^[0-9]{1,64}$') AND (\"github_account_checkpoints\".\"gap_expected_event_id\" IS NULL OR \"github_account_checkpoints\".\"gap_expected_event_id\" ~ '^[0-9]{1,64}$') AND (\"github_account_checkpoints\".\"gap_oldest_available_event_id\" IS NULL OR \"github_account_checkpoints\".\"gap_oldest_available_event_id\" ~ '^[0-9]{1,64}$')" + }, + "github_account_checkpoints_gap_state": { + "name": "github_account_checkpoints_gap_state", + "value": "\"github_account_checkpoints\".\"gap_state\" IN ('clear', 'detected')" + }, + "github_account_checkpoints_gap_details": { + "name": "github_account_checkpoints_gap_details", + "value": "(\"github_account_checkpoints\".\"gap_state\" = 'detected' AND \"github_account_checkpoints\".\"gap_detected_at\" IS NOT NULL) OR (\"github_account_checkpoints\".\"gap_state\" = 'clear' AND \"github_account_checkpoints\".\"gap_detected_at\" IS NULL AND \"github_account_checkpoints\".\"gap_expected_event_id\" IS NULL AND \"github_account_checkpoints\".\"gap_oldest_available_event_id\" IS NULL)" + }, + "github_account_checkpoints_ref_cursor_shape": { + "name": "github_account_checkpoints_ref_cursor_shape", + "value": "(\"github_account_checkpoints\".\"head_ref_cursor_repository_id\" IS NULL OR \"github_account_checkpoints\".\"head_ref_cursor_repository_id\" ~ '^[0-9]{1,32}$') AND (\"github_account_checkpoints\".\"tag_ref_cursor_repository_id\" IS NULL OR \"github_account_checkpoints\".\"tag_ref_cursor_repository_id\" ~ '^[0-9]{1,32}$')" + }, + "github_account_checkpoints_ref_leases": { + "name": "github_account_checkpoints_ref_leases", + "value": "(\"github_account_checkpoints\".\"head_ref_lease_token\" IS NULL) = (\"github_account_checkpoints\".\"head_ref_lease_until\" IS NULL) AND (\"github_account_checkpoints\".\"tag_ref_lease_token\" IS NULL) = (\"github_account_checkpoints\".\"tag_ref_lease_until\" IS NULL)" + }, + "github_account_checkpoints_ref_scans": { + "name": "github_account_checkpoints_ref_scans", + "value": "(\"github_account_checkpoints\".\"head_ref_next_page\" IS NULL AND \"github_account_checkpoints\".\"head_ref_scan_started_at\" IS NULL OR \"github_account_checkpoints\".\"head_ref_next_page\" >= 2 AND \"github_account_checkpoints\".\"head_ref_scan_started_at\" IS NOT NULL) AND (\"github_account_checkpoints\".\"tag_ref_next_page\" IS NULL AND \"github_account_checkpoints\".\"tag_ref_scan_started_at\" IS NULL OR \"github_account_checkpoints\".\"tag_ref_next_page\" >= 2 AND \"github_account_checkpoints\".\"tag_ref_scan_started_at\" IS NOT NULL)" + }, + "github_account_checkpoints_pr_backfill_digest": { + "name": "github_account_checkpoints_pr_backfill_digest", + "value": "\"github_account_checkpoints\".\"pull_request_backfill_digest\" IS NULL OR \"github_account_checkpoints\".\"pull_request_backfill_digest\" ~ '^[a-f0-9]{64}$'" + } + }, + "isRLSEnabled": true + }, + "public.github_account_repository_catalogs": { + "name": "github_account_repository_catalogs", + "schema": "", + "columns": { + "account_user_id": { + "name": "account_user_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "active_access": { + "name": "active_access", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "inventory_generation": { + "name": "inventory_generation", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "observed_at": { + "name": "observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "gh_account_repo_catalogs_current_idx": { + "name": "gh_account_repo_catalogs_current_idx", + "columns": [ + { + "expression": "account_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "inventory_generation", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "active_access", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "gh_account_repo_catalogs_account_fk": { + "name": "gh_account_repo_catalogs_account_fk", + "tableFrom": "github_account_repository_catalogs", + "tableTo": "github_repository_inventory_heads", + "columnsFrom": ["account_user_id"], + "columnsTo": ["account_user_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gh_account_repo_catalogs_repository_fk": { + "name": "gh_account_repo_catalogs_repository_fk", + "tableFrom": "github_account_repository_catalogs", + "tableTo": "github_repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "gh_account_repo_catalogs_pk": { + "name": "gh_account_repo_catalogs_pk", + "columns": ["account_user_id", "repository_id"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "gh_account_repo_catalogs_generation": { + "name": "gh_account_repo_catalogs_generation", + "value": "\"github_account_repository_catalogs\".\"inventory_generation\" > 0" + } + }, + "isRLSEnabled": true + }, + "public.github_activity_snapshots": { + "name": "github_activity_snapshots", + "schema": "", + "columns": { + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "identity_key": { + "name": "identity_key", + "type": "varchar(180)", + "primaryKey": false, + "notNull": true + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "work_unit_id": { + "name": "work_unit_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "work_unit_revision": { + "name": "work_unit_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "attribution_mode": { + "name": "attribution_mode", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "facts_digest": { + "name": "facts_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "outcome_digest": { + "name": "outcome_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "summary_input_digest": { + "name": "summary_input_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "recorded_at": { + "name": "recorded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "github_activity_snapshots_latest_idx": { + "name": "github_activity_snapshots_latest_idx", + "columns": [ + { + "expression": "identity_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "day", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_activity_snapshots_repository_idx": { + "name": "github_activity_snapshots_repository_idx", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "github_activity_snapshots_day_identity_key_pk": { + "name": "github_activity_snapshots_day_identity_key_pk", + "columns": ["day", "identity_key"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": true + }, + "public.github_commit_pull_request_associations": { + "name": "github_commit_pull_request_associations", + "schema": "", + "columns": { + "commit_repository_id": { + "name": "commit_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "commit_sha": { + "name": "commit_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "pull_request_node_id": { + "name": "pull_request_node_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "gh_commit_pr_associations_commit_fk": { + "name": "gh_commit_pr_associations_commit_fk", + "tableFrom": "github_commit_pull_request_associations", + "tableTo": "github_commits", + "columnsFrom": ["commit_repository_id", "commit_sha"], + "columnsTo": ["repository_id", "sha"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gh_commit_pr_associations_pr_fk": { + "name": "gh_commit_pr_associations_pr_fk", + "tableFrom": "github_commit_pull_request_associations", + "tableTo": "github_pull_requests", + "columnsFrom": ["pull_request_node_id"], + "columnsTo": ["node_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "gh_commit_pr_associations_pk": { + "name": "gh_commit_pr_associations_pk", + "columns": [ + "commit_repository_id", + "commit_sha", + "pull_request_node_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "gh_commit_pr_associations_sha_shape": { + "name": "gh_commit_pr_associations_sha_shape", + "value": "\"github_commit_pull_request_associations\".\"commit_sha\" ~ '^[a-f0-9]{40}$'" + } + }, + "isRLSEnabled": true + }, + "public.github_commits": { + "name": "github_commits", + "schema": "", + "columns": { + "additions": { + "name": "additions", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "author_login": { + "name": "author_login", + "type": "varchar(39)", + "primaryKey": false, + "notNull": true + }, + "authored_at": { + "name": "authored_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "author_user_id": { + "name": "author_user_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "changed_files": { + "name": "changed_files", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "committed_at": { + "name": "committed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "committer_at": { + "name": "committer_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "committer_user_id": { + "name": "committer_user_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "deletions": { + "name": "deletions", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "enrichment_error": { + "name": "enrichment_error", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "enrichment_attempts": { + "name": "enrichment_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "enrichment_lease_token": { + "name": "enrichment_lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "enrichment_lease_until": { + "name": "enrichment_lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "enrichment_state": { + "name": "enrichment_state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "file_facts": { + "name": "file_facts", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "file_facts_digest": { + "name": "file_facts_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "file_facts_pruned_at": { + "name": "file_facts_pruned_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "file_facts_complete": { + "name": "file_facts_complete", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "first_observed_at": { + "name": "first_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent_shas": { + "name": "parent_shas", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "provider_file_cap_reached": { + "name": "provider_file_cap_reached", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "pr_discovery_error": { + "name": "pr_discovery_error", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "pr_discovery_attempts": { + "name": "pr_discovery_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "pr_discovery_lease_token": { + "name": "pr_discovery_lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "pr_discovery_lease_until": { + "name": "pr_discovery_lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "pr_discovery_state": { + "name": "pr_discovery_state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "sha": { + "name": "sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "github_commits_committed_at_idx": { + "name": "github_commits_committed_at_idx", + "columns": [ + { + "expression": "committed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_commits_enrichment_pending_idx": { + "name": "github_commits_enrichment_pending_idx", + "columns": [ + { + "expression": "enrichment_state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enrichment_lease_until", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "committed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_commits_pr_discovery_pending_idx": { + "name": "github_commits_pr_discovery_pending_idx", + "columns": [ + { + "expression": "pr_discovery_state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pr_discovery_lease_until", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "first_observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "github_commits_repository_fk": { + "name": "github_commits_repository_fk", + "tableFrom": "github_commits", + "tableTo": "github_repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "github_commits_repository_id_sha_pk": { + "name": "github_commits_repository_id_sha_pk", + "columns": ["repository_id", "sha"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_commits_sha_shape": { + "name": "github_commits_sha_shape", + "value": "\"github_commits\".\"sha\" ~ '^[a-f0-9]{40}$'" + }, + "github_commits_parent_shas_array": { + "name": "github_commits_parent_shas_array", + "value": "\"github_commits\".\"parent_shas\" IS NULL OR jsonb_typeof(\"github_commits\".\"parent_shas\") = 'array'" + }, + "github_commits_file_facts_array": { + "name": "github_commits_file_facts_array", + "value": "\"github_commits\".\"file_facts\" IS NULL OR jsonb_typeof(\"github_commits\".\"file_facts\") = 'array'" + }, + "github_commits_file_facts_completeness": { + "name": "github_commits_file_facts_completeness", + "value": "NOT \"github_commits\".\"file_facts_complete\" OR (\"github_commits\".\"file_facts\" IS NOT NULL AND NOT \"github_commits\".\"provider_file_cap_reached\")" + }, + "github_commits_enrichment_state": { + "name": "github_commits_enrichment_state", + "value": "\"github_commits\".\"enrichment_state\" IN ('pending', 'processing', 'complete', 'unavailable')" + }, + "github_commits_enrichment_lease": { + "name": "github_commits_enrichment_lease", + "value": "(\"github_commits\".\"enrichment_state\" = 'processing') = (\"github_commits\".\"enrichment_lease_token\" IS NOT NULL) AND (\"github_commits\".\"enrichment_state\" <> 'processing' OR \"github_commits\".\"enrichment_lease_until\" IS NOT NULL) AND (\"github_commits\".\"enrichment_state\" NOT IN ('complete', 'unavailable') OR \"github_commits\".\"enrichment_lease_until\" IS NULL)" + }, + "github_commits_pr_discovery_state": { + "name": "github_commits_pr_discovery_state", + "value": "\"github_commits\".\"pr_discovery_state\" IN ('pending', 'processing', 'complete', 'unavailable')" + }, + "github_commits_pr_discovery_lease": { + "name": "github_commits_pr_discovery_lease", + "value": "(\"github_commits\".\"pr_discovery_state\" = 'processing') = (\"github_commits\".\"pr_discovery_lease_token\" IS NOT NULL) AND (\"github_commits\".\"pr_discovery_state\" <> 'processing' OR \"github_commits\".\"pr_discovery_lease_until\" IS NOT NULL) AND (\"github_commits\".\"pr_discovery_state\" NOT IN ('complete', 'unavailable') OR \"github_commits\".\"pr_discovery_lease_until\" IS NULL)" + }, + "github_commits_tracked_author": { + "name": "github_commits_tracked_author", + "value": "\"github_commits\".\"author_login\" ~ '^[a-z0-9]([a-z0-9-]{0,37}[a-z0-9])?$'" + }, + "github_commits_nonnegative_activity_counts": { + "name": "github_commits_nonnegative_activity_counts", + "value": "(\"github_commits\".\"changed_files\" IS NULL OR \"github_commits\".\"changed_files\" >= 0) AND (\"github_commits\".\"additions\" IS NULL OR \"github_commits\".\"additions\" >= 0) AND (\"github_commits\".\"deletions\" IS NULL OR \"github_commits\".\"deletions\" >= 0)" + }, + "github_commits_nonnegative_attempts": { + "name": "github_commits_nonnegative_attempts", + "value": "\"github_commits\".\"enrichment_attempts\" >= 0 AND \"github_commits\".\"pr_discovery_attempts\" >= 0" + } + }, + "isRLSEnabled": true + }, + "public.github_issues": { + "name": "github_issues", + "schema": "", + "columns": { + "account": { + "name": "account", + "type": "varchar(39)", + "primaryKey": false, + "notNull": true + }, + "author_login": { + "name": "author_login", + "type": "varchar(39)", + "primaryKey": false, + "notNull": false + }, + "author_user_id": { + "name": "author_user_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "first_observed_at": { + "name": "first_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "node_id": { + "name": "node_id", + "type": "varchar(128)", + "primaryKey": true, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "title_snapshot": { + "name": "title_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url_snapshot": { + "name": "url_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "github_issues_repository_number_unique": { + "name": "github_issues_repository_number_unique", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_issues_author_idx": { + "name": "github_issues_author_idx", + "columns": [ + { + "expression": "author_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "github_issues_repository_id_github_repositories_id_fk": { + "name": "github_issues_repository_id_github_repositories_id_fk", + "tableFrom": "github_issues", + "tableTo": "github_repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_issues_tracked_account": { + "name": "github_issues_tracked_account", + "value": "\"github_issues\".\"account\" ~ '^[a-z0-9]([a-z0-9-]{0,37}[a-z0-9])?$'" + }, + "github_issues_positive_number": { + "name": "github_issues_positive_number", + "value": "\"github_issues\".\"number\" > 0" + } + }, + "isRLSEnabled": true + }, + "public.github_public_feed_head": { + "name": "github_public_feed_head", + "schema": "", + "columns": { + "history_initialized_at": { + "name": "history_initialized_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "feed_revision": { + "name": "feed_revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "head_content_revision": { + "name": "head_content_revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "id": { + "name": "id", + "type": "boolean", + "primaryKey": true, + "notNull": true, + "default": true + }, + "last_published_at": { + "name": "last_published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ordering_revision": { + "name": "ordering_revision", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "projection_request_token": { + "name": "projection_request_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "summary_policy_digest": { + "name": "summary_policy_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "summarizing": { + "name": "summarizing", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "gh_public_feed_head_singleton": { + "name": "gh_public_feed_head_singleton", + "value": "\"github_public_feed_head\".\"id\"" + }, + "gh_public_feed_head_revisions": { + "name": "gh_public_feed_head_revisions", + "value": "\"github_public_feed_head\".\"feed_revision\" >= 0 AND \"github_public_feed_head\".\"head_content_revision\" >= 0 AND \"github_public_feed_head\".\"ordering_revision\" >= 0" + }, + "gh_public_feed_head_summary_policy_digest": { + "name": "gh_public_feed_head_summary_policy_digest", + "value": "\"github_public_feed_head\".\"summary_policy_digest\" IS NULL OR \"github_public_feed_head\".\"summary_policy_digest\" ~ '^[a-f0-9]{64}$'" + } + }, + "isRLSEnabled": true + }, + "public.github_pull_request_memberships": { + "name": "github_pull_request_memberships", + "schema": "", + "columns": { + "commit_repository_id": { + "name": "commit_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "commit_sha": { + "name": "commit_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "is_head": { + "name": "is_head", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "version_id": { + "name": "version_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "github_pull_request_memberships_position_unique": { + "name": "github_pull_request_memberships_position_unique", + "columns": [ + { + "expression": "version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "position", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_pull_request_memberships_commit_lookup_idx": { + "name": "github_pull_request_memberships_commit_lookup_idx", + "columns": [ + { + "expression": "commit_repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "commit_sha", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "gh_pr_memberships_version_fk": { + "name": "gh_pr_memberships_version_fk", + "tableFrom": "github_pull_request_memberships", + "tableTo": "github_pull_requests", + "columnsFrom": ["version_id"], + "columnsTo": ["snapshot_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "gh_pr_memberships_pk": { + "name": "gh_pr_memberships_pk", + "columns": ["version_id", "commit_repository_id", "commit_sha"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_pull_request_memberships_sha_shape": { + "name": "github_pull_request_memberships_sha_shape", + "value": "\"github_pull_request_memberships\".\"commit_sha\" ~ '^[a-f0-9]{40}$'" + }, + "github_pull_request_memberships_nonnegative_position": { + "name": "github_pull_request_memberships_nonnegative_position", + "value": "\"github_pull_request_memberships\".\"position\" >= 0" + } + }, + "isRLSEnabled": true + }, + "public.github_pull_request_signals": { + "name": "github_pull_request_signals", + "schema": "", + "columns": { + "account": { + "name": "account", + "type": "varchar(39)", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "error_code": { + "name": "error_code", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "event_id": { + "name": "event_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_until": { + "name": "lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "observed_at": { + "name": "observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "repository_name_snapshot": { + "name": "repository_name_snapshot", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + } + }, + "indexes": { + "github_pull_request_signals_event_unique": { + "name": "github_pull_request_signals_event_unique", + "columns": [ + { + "expression": "account", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_pull_request_signals_pending_idx": { + "name": "github_pull_request_signals_pending_idx", + "columns": [ + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lease_until", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_pull_request_signals_account": { + "name": "github_pull_request_signals_account", + "value": "\"github_pull_request_signals\".\"account\" ~ '^[a-z0-9]([a-z0-9-]{0,37}[a-z0-9])?$'" + }, + "github_pull_request_signals_event_id": { + "name": "github_pull_request_signals_event_id", + "value": "\"github_pull_request_signals\".\"event_id\" ~ '^[0-9]{1,64}$'" + }, + "github_pull_request_signals_repository_id": { + "name": "github_pull_request_signals_repository_id", + "value": "\"github_pull_request_signals\".\"repository_id\" ~ '^[0-9]{1,32}$'" + }, + "github_pull_request_signals_state": { + "name": "github_pull_request_signals_state", + "value": "\"github_pull_request_signals\".\"state\" IN ('pending', 'processing', 'complete', 'unavailable')" + }, + "github_pull_request_signals_lease": { + "name": "github_pull_request_signals_lease", + "value": "(\"github_pull_request_signals\".\"state\" = 'processing') = (\"github_pull_request_signals\".\"lease_token\" IS NOT NULL) AND (\"github_pull_request_signals\".\"state\" <> 'processing' OR \"github_pull_request_signals\".\"lease_until\" IS NOT NULL)" + }, + "github_pull_request_signals_values": { + "name": "github_pull_request_signals_values", + "value": "\"github_pull_request_signals\".\"number\" > 0 AND \"github_pull_request_signals\".\"attempt_count\" >= 0" + } + }, + "isRLSEnabled": true + }, + "public.github_pull_requests": { + "name": "github_pull_requests", + "schema": "", + "columns": { + "account": { + "name": "account", + "type": "varchar(39)", + "primaryKey": false, + "notNull": true + }, + "additions": { + "name": "additions", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "author_login": { + "name": "author_login", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "author_user_id": { + "name": "author_user_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "base_ref_name": { + "name": "base_ref_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "base_repository_id": { + "name": "base_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "base_sha": { + "name": "base_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body_snapshot": { + "name": "body_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "changed_files": { + "name": "changed_files", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "commit_count": { + "name": "commit_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "deletions": { + "name": "deletions", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_facts": { + "name": "file_facts", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "file_facts_digest": { + "name": "file_facts_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "generated": { + "as": "CASE WHEN \"file_facts\" IS NULL THEN NULL ELSE encode(sha256(jsonb_send(\"file_facts\")), 'hex') END", + "type": "stored" + } + }, + "file_facts_complete": { + "name": "file_facts_complete", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "membership_complete": { + "name": "membership_complete", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "merge_snapshot": { + "name": "merge_snapshot", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "snapshot_id": { + "name": "snapshot_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "snapshot_observed_at": { + "name": "snapshot_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "draft": { + "name": "draft", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "first_observed_at": { + "name": "first_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "head_ref_name": { + "name": "head_ref_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "head_repository_id": { + "name": "head_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "head_sha": { + "name": "head_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "last_reconciled_at": { + "name": "last_reconciled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "merged_at": { + "name": "merged_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "merge_sha": { + "name": "merge_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "merge_sha_verified_at": { + "name": "merge_sha_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "next_reconcile_at": { + "name": "next_reconcile_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "node_id": { + "name": "node_id", + "type": "varchar(128)", + "primaryKey": true, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "provider_updated_at": { + "name": "provider_updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "reconcile_attempts": { + "name": "reconcile_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reconcile_error": { + "name": "reconcile_error", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true + }, + "terminal_at": { + "name": "terminal_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title_snapshot": { + "name": "title_snapshot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "github_pull_requests_snapshot_unique": { + "name": "github_pull_requests_snapshot_unique", + "columns": [ + { + "expression": "snapshot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_pull_requests_repository_number_unique": { + "name": "github_pull_requests_repository_number_unique", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_pull_requests_reconciliation_idx": { + "name": "github_pull_requests_reconciliation_idx", + "columns": [ + { + "expression": "account", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_reconcile_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_pull_requests_author_idx": { + "name": "github_pull_requests_author_idx", + "columns": [ + { + "expression": "author_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "github_pull_requests_repository_id_github_repositories_id_fk": { + "name": "github_pull_requests_repository_id_github_repositories_id_fk", + "tableFrom": "github_pull_requests", + "tableTo": "github_repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_pull_requests_file_facts_array": { + "name": "github_pull_requests_file_facts_array", + "value": "\"github_pull_requests\".\"file_facts\" IS NULL OR jsonb_typeof(\"github_pull_requests\".\"file_facts\") = 'array'" + }, + "github_pull_requests_file_facts_complete": { + "name": "github_pull_requests_file_facts_complete", + "value": "NOT \"github_pull_requests\".\"file_facts_complete\" OR \"github_pull_requests\".\"file_facts\" IS NOT NULL" + }, + "github_pull_requests_snapshot": { + "name": "github_pull_requests_snapshot", + "value": "(\"github_pull_requests\".\"snapshot_id\" IS NULL) = (\"github_pull_requests\".\"snapshot_observed_at\" IS NULL) AND (\"github_pull_requests\".\"snapshot_id\" IS NULL OR (\"github_pull_requests\".\"base_sha\" IS NOT NULL AND \"github_pull_requests\".\"head_sha\" IS NOT NULL))" + }, + "github_pull_requests_tracked_account": { + "name": "github_pull_requests_tracked_account", + "value": "\"github_pull_requests\".\"account\" ~ '^[a-z0-9]([a-z0-9-]{0,37}[a-z0-9])?$'" + }, + "github_pull_requests_state": { + "name": "github_pull_requests_state", + "value": "\"github_pull_requests\".\"state\" IN ('open', 'closed', 'merged')" + }, + "github_pull_requests_terminal_state": { + "name": "github_pull_requests_terminal_state", + "value": "(\"github_pull_requests\".\"state\" = 'open' AND \"github_pull_requests\".\"terminal_at\" IS NULL) OR (\"github_pull_requests\".\"state\" IN ('closed', 'merged') AND \"github_pull_requests\".\"terminal_at\" IS NOT NULL)" + }, + "github_pull_requests_merged_state": { + "name": "github_pull_requests_merged_state", + "value": "(\"github_pull_requests\".\"state\" = 'merged') = (\"github_pull_requests\".\"merged_at\" IS NOT NULL)" + }, + "github_pull_requests_sha_shapes": { + "name": "github_pull_requests_sha_shapes", + "value": "(\"github_pull_requests\".\"base_sha\" IS NULL OR \"github_pull_requests\".\"base_sha\" ~ '^[a-f0-9]{40}$') AND (\"github_pull_requests\".\"head_sha\" IS NULL OR \"github_pull_requests\".\"head_sha\" ~ '^[a-f0-9]{40}$') AND (\"github_pull_requests\".\"merge_sha\" IS NULL OR \"github_pull_requests\".\"merge_sha\" ~ '^[a-f0-9]{40}$')" + }, + "github_pull_requests_verified_merge_sha": { + "name": "github_pull_requests_verified_merge_sha", + "value": "(\"github_pull_requests\".\"merge_sha\" IS NULL AND \"github_pull_requests\".\"merge_sha_verified_at\" IS NULL) OR (\"github_pull_requests\".\"state\" = 'merged' AND \"github_pull_requests\".\"merge_sha_verified_at\" IS NOT NULL)" + }, + "github_pull_requests_positive_number": { + "name": "github_pull_requests_positive_number", + "value": "\"github_pull_requests\".\"number\" > 0" + }, + "github_pull_requests_nonnegative_counts": { + "name": "github_pull_requests_nonnegative_counts", + "value": "(\"github_pull_requests\".\"changed_files\" IS NULL OR \"github_pull_requests\".\"changed_files\" >= 0) AND (\"github_pull_requests\".\"additions\" IS NULL OR \"github_pull_requests\".\"additions\" >= 0) AND (\"github_pull_requests\".\"deletions\" IS NULL OR \"github_pull_requests\".\"deletions\" >= 0) AND (\"github_pull_requests\".\"commit_count\" IS NULL OR \"github_pull_requests\".\"commit_count\" >= 0)" + }, + "github_pull_requests_nonnegative_attempts": { + "name": "github_pull_requests_nonnegative_attempts", + "value": "\"github_pull_requests\".\"reconcile_attempts\" >= 0" + } + }, + "isRLSEnabled": true + }, + "public.github_push_observations": { + "name": "github_push_observations", + "schema": "", + "columns": { + "account": { + "name": "account", + "type": "varchar(39)", + "primaryKey": false, + "notNull": true + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "after_sha": { + "name": "after_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "before_sha": { + "name": "before_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "error_code": { + "name": "error_code", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "known_shas": { + "name": "known_shas", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "ARRAY[]::text[]" + }, + "expected_commit_count": { + "name": "expected_commit_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "history_since_at": { + "name": "history_since_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "history_until_at": { + "name": "history_until_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_until": { + "name": "lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "observed_at": { + "name": "observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "provider_created_at": { + "name": "provider_created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ref_name": { + "name": "ref_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "repository_name_snapshot": { + "name": "repository_name_snapshot", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + } + }, + "indexes": { + "github_push_observations_source_unique": { + "name": "github_push_observations_source_unique", + "columns": [ + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_push_observations_push_unique": { + "name": "github_push_observations_push_unique", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "ref_name", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "before_sha", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "after_sha", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"github_push_observations\".\"source\" <> 'backfill'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_push_observations_pending_idx": { + "name": "github_push_observations_pending_idx", + "columns": [ + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lease_until", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_push_observations_account_idx": { + "name": "github_push_observations_account_idx", + "columns": [ + { + "expression": "account", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "gh_push_observations_repository_fk": { + "name": "gh_push_observations_repository_fk", + "tableFrom": "github_push_observations", + "tableTo": "github_repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_push_observations_tracked_account": { + "name": "github_push_observations_tracked_account", + "value": "\"github_push_observations\".\"account\" ~ '^[a-z0-9]([a-z0-9-]{0,37}[a-z0-9])?$'" + }, + "github_push_observations_source": { + "name": "github_push_observations_source", + "value": "\"github_push_observations\".\"source\" IN ('webhook', 'events', 'refs', 'backfill')" + }, + "github_push_observations_sha_shape": { + "name": "github_push_observations_sha_shape", + "value": "\"github_push_observations\".\"before_sha\" ~ '^[a-f0-9]{40}$' AND \"github_push_observations\".\"after_sha\" ~ '^[a-f0-9]{40}$'" + }, + "github_push_observations_nonnegative_count": { + "name": "github_push_observations_nonnegative_count", + "value": "\"github_push_observations\".\"attempt_count\" >= 0 AND (\"github_push_observations\".\"expected_commit_count\" IS NULL OR \"github_push_observations\".\"expected_commit_count\" >= 0)" + }, + "github_push_observations_history_bounds": { + "name": "github_push_observations_history_bounds", + "value": "(\"github_push_observations\".\"source\" <> 'backfill' AND \"github_push_observations\".\"history_since_at\" IS NULL AND \"github_push_observations\".\"history_until_at\" IS NULL) OR (\"github_push_observations\".\"source\" = 'backfill' AND \"github_push_observations\".\"history_since_at\" IS NOT NULL AND \"github_push_observations\".\"history_until_at\" IS NOT NULL AND \"github_push_observations\".\"history_since_at\" <= \"github_push_observations\".\"history_until_at\" AND \"github_push_observations\".\"expected_commit_count\" IS NULL AND \"github_push_observations\".\"before_sha\" = repeat('0', 40))" + }, + "github_push_observations_state": { + "name": "github_push_observations_state", + "value": "\"github_push_observations\".\"state\" IN ('pending', 'processing', 'complete', 'deferred', 'unavailable')" + }, + "github_push_observations_lease": { + "name": "github_push_observations_lease", + "value": "(\"github_push_observations\".\"state\" = 'processing') = (\"github_push_observations\".\"lease_token\" IS NOT NULL) AND (\"github_push_observations\".\"state\" <> 'processing' OR \"github_push_observations\".\"lease_until\" IS NOT NULL)" + } + }, + "isRLSEnabled": true + }, + "public.github_ref_generations": { + "name": "github_ref_generations", + "schema": "", + "columns": { + "branch_lineage_id": { + "name": "branch_lineage_id", + "type": "uuid", + "primaryKey": false, + "notNull": true, + "default": "gen_random_uuid()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "coverage_since_at": { + "name": "coverage_since_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "head_sha": { + "name": "head_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "ref_name": { + "name": "ref_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "gh_ref_generations_lineage_idx": { + "name": "gh_ref_generations_lineage_idx", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "branch_lineage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "gh_ref_generations_repository_fk": { + "name": "gh_ref_generations_repository_fk", + "tableFrom": "github_ref_generations", + "tableTo": "github_repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "gh_ref_generations_pk": { + "name": "gh_ref_generations_pk", + "columns": ["repository_id", "ref_name"] + } + }, + "uniqueConstraints": { + "gh_ref_generations_version_unique": { + "name": "gh_ref_generations_version_unique", + "nullsNotDistinct": false, + "columns": ["repository_id", "ref_name", "generation"] + } + }, + "policies": {}, + "checkConstraints": { + "gh_ref_generations_head_name": { + "name": "gh_ref_generations_head_name", + "value": "\"github_ref_generations\".\"ref_name\" LIKE 'refs/heads/%'" + }, + "gh_ref_generations_sha_shape": { + "name": "gh_ref_generations_sha_shape", + "value": "\"github_ref_generations\".\"head_sha\" ~ '^[a-f0-9]{40}$'" + }, + "gh_ref_generations_positive": { + "name": "gh_ref_generations_positive", + "value": "\"github_ref_generations\".\"generation\" > 0" + } + }, + "isRLSEnabled": true + }, + "public.github_ref_memberships": { + "name": "github_ref_memberships", + "schema": "", + "columns": { + "commit_repository_id": { + "name": "commit_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "commit_sha": { + "name": "commit_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "ref_name": { + "name": "ref_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "gh_ref_memberships_position_unique": { + "name": "gh_ref_memberships_position_unique", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "ref_name", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "position", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_ref_memberships_commit_idx": { + "name": "gh_ref_memberships_commit_idx", + "columns": [ + { + "expression": "commit_repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "commit_sha", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "gh_ref_memberships_generation_fk": { + "name": "gh_ref_memberships_generation_fk", + "tableFrom": "github_ref_memberships", + "tableTo": "github_ref_generations", + "columnsFrom": ["repository_id", "ref_name", "generation"], + "columnsTo": ["repository_id", "ref_name", "generation"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gh_ref_memberships_commit_fk": { + "name": "gh_ref_memberships_commit_fk", + "tableFrom": "github_ref_memberships", + "tableTo": "github_commits", + "columnsFrom": ["commit_repository_id", "commit_sha"], + "columnsTo": ["repository_id", "sha"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "gh_ref_memberships_pk": { + "name": "gh_ref_memberships_pk", + "columns": [ + "repository_id", + "ref_name", + "commit_repository_id", + "commit_sha" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "gh_ref_memberships_values": { + "name": "gh_ref_memberships_values", + "value": "\"github_ref_memberships\".\"generation\" > 0 AND \"github_ref_memberships\".\"position\" >= 0 AND \"github_ref_memberships\".\"commit_sha\" ~ '^[a-f0-9]{40}$'" + } + }, + "isRLSEnabled": true + }, + "public.github_repositories": { + "name": "github_repositories", + "schema": "", + "columns": { + "default_branch": { + "name": "default_branch", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "first_observed_at": { + "name": "first_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "facts_verified_at": { + "name": "facts_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "inventory_verified_at": { + "name": "inventory_verified_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "full_name": { + "name": "full_name", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "homepage_url": { + "name": "homepage_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "heads_last_reconciled_at": { + "name": "heads_last_reconciled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "html_url": { + "name": "html_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id": { + "name": "id", + "type": "varchar(32)", + "primaryKey": true, + "notNull": true + }, + "projection_request_token": { + "name": "projection_request_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "last_observed_at": { + "name": "last_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "owner_avatar_url": { + "name": "owner_avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner_id": { + "name": "owner_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "owner_login": { + "name": "owner_login", + "type": "varchar(39)", + "primaryKey": false, + "notNull": false + }, + "owner_type": { + "name": "owner_type", + "type": "varchar(12)", + "primaryKey": false, + "notNull": false + }, + "pushed_at": { + "name": "pushed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "topics": { + "name": "topics", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "tags_last_reconciled_at": { + "name": "tags_last_reconciled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "visibility": { + "name": "visibility", + "type": "varchar(12)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "github_repositories_full_name_idx": { + "name": "github_repositories_full_name_idx", + "columns": [ + { + "expression": "full_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_repositories_full_name": { + "name": "github_repositories_full_name", + "value": "length(btrim(\"github_repositories\".\"full_name\")) > 0" + }, + "github_repositories_owner_type": { + "name": "github_repositories_owner_type", + "value": "\"github_repositories\".\"owner_type\" IS NULL OR \"github_repositories\".\"owner_type\" IN ('Organization', 'User')" + }, + "github_repositories_visibility": { + "name": "github_repositories_visibility", + "value": "\"github_repositories\".\"visibility\" IS NULL OR \"github_repositories\".\"visibility\" IN ('public', 'private', 'internal')" + }, + "github_repositories_topics_array": { + "name": "github_repositories_topics_array", + "value": "\"github_repositories\".\"topics\" IS NULL OR jsonb_typeof(\"github_repositories\".\"topics\") = 'array'" + }, + "github_repositories_observation_order": { + "name": "github_repositories_observation_order", + "value": "\"github_repositories\".\"last_observed_at\" >= \"github_repositories\".\"first_observed_at\"" + } + }, + "isRLSEnabled": true + }, + "public.github_repository_inventory_heads": { + "name": "github_repository_inventory_heads", + "schema": "", + "columns": { + "account_login": { + "name": "account_login", + "type": "varchar(39)", + "primaryKey": false, + "notNull": true + }, + "account_user_id": { + "name": "account_user_id", + "type": "varchar(32)", + "primaryKey": true, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "generation": { + "name": "generation", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "gh_repo_inventory_head_account_id": { + "name": "gh_repo_inventory_head_account_id", + "value": "\"github_repository_inventory_heads\".\"account_user_id\" ~ '^[0-9]{1,32}$'" + }, + "gh_repo_inventory_head_generation": { + "name": "gh_repo_inventory_head_generation", + "value": "(\"github_repository_inventory_heads\".\"generation\" = 0 AND \"github_repository_inventory_heads\".\"completed_at\" IS NULL) OR (\"github_repository_inventory_heads\".\"generation\" > 0 AND \"github_repository_inventory_heads\".\"completed_at\" IS NOT NULL)" + } + }, + "isRLSEnabled": true + }, + "public.github_repository_refs": { + "name": "github_repository_refs", + "schema": "", + "columns": { + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "branch_lineage_id": { + "name": "branch_lineage_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "first_observed_at": { + "name": "first_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "head_sha": { + "name": "head_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true + }, + "last_observed_at": { + "name": "last_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "projection_relevant": { + "name": "projection_relevant", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "ref_name": { + "name": "ref_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "repair_attempts": { + "name": "repair_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "repair_error": { + "name": "repair_error", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "repair_lease_token": { + "name": "repair_lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "repair_lease_until": { + "name": "repair_lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "github_repository_refs_active_idx": { + "name": "github_repository_refs_active_idx", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "github_repository_refs_projection_idx": { + "name": "github_repository_refs_projection_idx", + "columns": [ + { + "expression": "projection_relevant", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "active", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "github_repository_refs_repository_fk": { + "name": "github_repository_refs_repository_fk", + "tableFrom": "github_repository_refs", + "tableTo": "github_repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "github_repository_refs_repository_id_ref_name_pk": { + "name": "github_repository_refs_repository_id_ref_name_pk", + "columns": ["repository_id", "ref_name"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_repository_refs_kind": { + "name": "github_repository_refs_kind", + "value": "\"github_repository_refs\".\"kind\" IN ('head', 'tag')" + }, + "github_repository_refs_name": { + "name": "github_repository_refs_name", + "value": "(\"github_repository_refs\".\"kind\" = 'head' AND \"github_repository_refs\".\"ref_name\" LIKE 'refs/heads/%') OR (\"github_repository_refs\".\"kind\" = 'tag' AND \"github_repository_refs\".\"ref_name\" LIKE 'refs/tags/%')" + }, + "github_repository_refs_lineage": { + "name": "github_repository_refs_lineage", + "value": "(\"github_repository_refs\".\"kind\" = 'head') = (\"github_repository_refs\".\"branch_lineage_id\" IS NOT NULL)" + }, + "github_repository_refs_projection_relevance": { + "name": "github_repository_refs_projection_relevance", + "value": "NOT \"github_repository_refs\".\"projection_relevant\" OR \"github_repository_refs\".\"kind\" = 'head'" + }, + "github_repository_refs_sha_shape": { + "name": "github_repository_refs_sha_shape", + "value": "\"github_repository_refs\".\"head_sha\" ~ '^[a-f0-9]{40}$'" + }, + "github_repository_refs_observation_order": { + "name": "github_repository_refs_observation_order", + "value": "\"github_repository_refs\".\"last_observed_at\" >= \"github_repository_refs\".\"first_observed_at\"" + }, + "github_repository_refs_repair_lease": { + "name": "github_repository_refs_repair_lease", + "value": "(\"github_repository_refs\".\"repair_lease_token\" IS NULL) = (\"github_repository_refs\".\"repair_lease_until\" IS NULL) AND (\"github_repository_refs\".\"repair_lease_token\" IS NULL OR \"github_repository_refs\".\"kind\" = 'head')" + }, + "github_repository_refs_repair_attempts": { + "name": "github_repository_refs_repair_attempts", + "value": "\"github_repository_refs\".\"repair_attempts\" >= 0" + } + }, + "isRLSEnabled": true + }, + "public.github_webhook_deliveries": { + "name": "github_webhook_deliveries", + "schema": "", + "columns": { + "accepted": { + "name": "accepted", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "account": { + "name": "account", + "type": "varchar(39)", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "delivery_id": { + "name": "delivery_id", + "type": "varchar(36)", + "primaryKey": true, + "notNull": true + }, + "event": { + "name": "event", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "observed_at": { + "name": "observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "github_webhook_deliveries_audit_idx": { + "name": "github_webhook_deliveries_audit_idx", + "columns": [ + { + "expression": "event", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "github_webhook_deliveries_id_shape": { + "name": "github_webhook_deliveries_id_shape", + "value": "\"github_webhook_deliveries\".\"delivery_id\" ~ '^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$'" + }, + "github_webhook_deliveries_event_shape": { + "name": "github_webhook_deliveries_event_shape", + "value": "\"github_webhook_deliveries\".\"event\" ~ '^[a-z][a-z0-9_]{0,39}$'" + }, + "github_webhook_deliveries_action_shape": { + "name": "github_webhook_deliveries_action_shape", + "value": "\"github_webhook_deliveries\".\"action\" IS NULL OR \"github_webhook_deliveries\".\"action\" ~ '^[a-z][a-z0-9_]{0,39}$'" + }, + "github_webhook_deliveries_repository_id_shape": { + "name": "github_webhook_deliveries_repository_id_shape", + "value": "\"github_webhook_deliveries\".\"repository_id\" IS NULL OR \"github_webhook_deliveries\".\"repository_id\" ~ '^[0-9]{1,32}$'" + }, + "github_webhook_deliveries_tracked_account": { + "name": "github_webhook_deliveries_tracked_account", + "value": "\"github_webhook_deliveries\".\"account\" IS NULL OR \"github_webhook_deliveries\".\"account\" ~ '^[a-z0-9]([a-z0-9-]{0,37}[a-z0-9])?$'" + } + }, + "isRLSEnabled": true + }, + "public.github_work_unit_memberships": { + "name": "github_work_unit_memberships", + "schema": "", + "columns": { + "logical_repository_id": { + "name": "logical_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "logical_sha": { + "name": "logical_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "work_unit_id": { + "name": "work_unit_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "gh_work_unit_memberships_position_unique": { + "name": "gh_work_unit_memberships_position_unique", + "columns": [ + { + "expression": "work_unit_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "position", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_work_unit_memberships_commit_unique": { + "name": "gh_work_unit_memberships_commit_unique", + "columns": [ + { + "expression": "logical_repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "logical_sha", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "gh_work_unit_memberships_unit_fk": { + "name": "gh_work_unit_memberships_unit_fk", + "tableFrom": "github_work_unit_memberships", + "tableTo": "github_work_units", + "columnsFrom": ["work_unit_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gh_work_unit_memberships_commit_fk": { + "name": "gh_work_unit_memberships_commit_fk", + "tableFrom": "github_work_unit_memberships", + "tableTo": "github_commits", + "columnsFrom": ["logical_repository_id", "logical_sha"], + "columnsTo": ["repository_id", "sha"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "gh_work_unit_memberships_pk": { + "name": "gh_work_unit_memberships_pk", + "columns": ["work_unit_id", "logical_repository_id", "logical_sha"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "gh_work_unit_memberships_values": { + "name": "gh_work_unit_memberships_values", + "value": "\"github_work_unit_memberships\".\"position\" >= 0 AND \"github_work_unit_memberships\".\"logical_sha\" ~ '^[a-f0-9]{40}$'" + } + }, + "isRLSEnabled": true + }, + "public.github_work_unit_summary_attempts": { + "name": "github_work_unit_summary_attempts", + "schema": "", + "columns": { + "identity_key": { + "name": "identity_key", + "type": "varchar(180)", + "primaryKey": false, + "notNull": true + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "error_code": { + "name": "error_code", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "attribution_mode": { + "name": "attribution_mode", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "debounce_until": { + "name": "debounce_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "input_tokens": { + "name": "input_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "request_started_at": { + "name": "request_started_at", + "type": "timestamp with time zone[]", + "primaryKey": false, + "notNull": true, + "default": "ARRAY[]::timestamptz[]" + }, + "last_started_at": { + "name": "last_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "latency_ms": { + "name": "latency_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "lease_token": { + "name": "lease_token", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "lease_until": { + "name": "lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "outcome_digest": { + "name": "outcome_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "output_tokens": { + "name": "output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "recipe": { + "name": "recipe", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "request_payload": { + "name": "request_payload", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "started_requests": { + "name": "started_requests", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "state": { + "name": "state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "summary_input_digest": { + "name": "summary_input_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "work_unit_id": { + "name": "work_unit_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "gh_work_unit_summary_input_unique": { + "name": "gh_work_unit_summary_input_unique", + "columns": [ + { + "expression": "work_unit_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "summary_input_digest", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "recipe", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_work_unit_summary_claim_idx": { + "name": "gh_work_unit_summary_claim_idx", + "columns": [ + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "debounce_until", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_work_unit_summary_accepted_outcome_idx": { + "name": "gh_work_unit_summary_accepted_outcome_idx", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "outcome_digest", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "attribution_mode", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "recipe", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "accepted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"github_work_unit_summary_attempts\".\"state\" = 'accepted'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_work_unit_summary_attempts_identity_idx": { + "name": "gh_work_unit_summary_attempts_identity_idx", + "columns": [ + { + "expression": "identity_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "gh_work_unit_summary_attempts_pk": { + "name": "gh_work_unit_summary_attempts_pk", + "columns": ["work_unit_id", "revision"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "gh_work_unit_summary_state": { + "name": "gh_work_unit_summary_state", + "value": "\"github_work_unit_summary_attempts\".\"state\" IN ('pending', 'processing', 'retryable', 'accepted', 'terminal')" + }, + "gh_work_unit_summary_digests": { + "name": "gh_work_unit_summary_digests", + "value": "\"github_work_unit_summary_attempts\".\"outcome_digest\" ~ '^[a-f0-9]{64}$' AND \"github_work_unit_summary_attempts\".\"summary_input_digest\" ~ '^[a-f0-9]{64}$'" + }, + "gh_work_unit_summary_attribution": { + "name": "gh_work_unit_summary_attribution", + "value": "\"github_work_unit_summary_attempts\".\"attribution_mode\" IN ('tracked_authored_pr', 'foreign_pr_contribution', 'canonical_owned_composite', 'branch_owned_composite')" + }, + "gh_work_unit_summary_revisions": { + "name": "gh_work_unit_summary_revisions", + "value": "\"github_work_unit_summary_attempts\".\"revision\" > 0 AND \"github_work_unit_summary_attempts\".\"started_requests\" BETWEEN 0 AND 2" + }, + "gh_work_unit_summary_lease": { + "name": "gh_work_unit_summary_lease", + "value": "(\"github_work_unit_summary_attempts\".\"lease_token\" IS NULL) = (\"github_work_unit_summary_attempts\".\"lease_until\" IS NULL) AND (\"github_work_unit_summary_attempts\".\"state\" = 'processing') = (\"github_work_unit_summary_attempts\".\"lease_token\" IS NOT NULL) AND (\"github_work_unit_summary_attempts\".\"state\" <> 'processing' OR (\"github_work_unit_summary_attempts\".\"started_requests\" > 0 AND \"github_work_unit_summary_attempts\".\"request_payload\" IS NOT NULL))" + }, + "gh_work_unit_summary_terminal_payload": { + "name": "gh_work_unit_summary_terminal_payload", + "value": "\"github_work_unit_summary_attempts\".\"state\" NOT IN ('accepted', 'terminal') OR \"github_work_unit_summary_attempts\".\"request_payload\" IS NULL" + }, + "gh_work_unit_summary_accepted_output": { + "name": "gh_work_unit_summary_accepted_output", + "value": "(\"github_work_unit_summary_attempts\".\"state\" = 'accepted' AND \"github_work_unit_summary_attempts\".\"outcome\" IS NOT NULL AND \"github_work_unit_summary_attempts\".\"accepted_at\" IS NOT NULL AND \"github_work_unit_summary_attempts\".\"completed_at\" IS NOT NULL) OR (\"github_work_unit_summary_attempts\".\"state\" <> 'accepted' AND \"github_work_unit_summary_attempts\".\"outcome\" IS NULL AND \"github_work_unit_summary_attempts\".\"accepted_at\" IS NULL AND (\"github_work_unit_summary_attempts\".\"state\" <> 'terminal' OR \"github_work_unit_summary_attempts\".\"completed_at\" IS NOT NULL))" + }, + "gh_work_unit_summary_started": { + "name": "gh_work_unit_summary_started", + "value": "(\"github_work_unit_summary_attempts\".\"started_requests\" = 0) = (\"github_work_unit_summary_attempts\".\"last_started_at\" IS NULL) AND (\"github_work_unit_summary_attempts\".\"state\" <> 'pending' OR \"github_work_unit_summary_attempts\".\"request_payload\" IS NOT NULL)" + }, + "gh_work_unit_summary_request_cap": { + "name": "gh_work_unit_summary_request_cap", + "value": "\"github_work_unit_summary_attempts\".\"request_payload\" IS NULL OR octet_length(\"github_work_unit_summary_attempts\".\"request_payload\") <= 393216" + }, + "gh_work_unit_summary_request_times": { + "name": "gh_work_unit_summary_request_times", + "value": "cardinality(\"github_work_unit_summary_attempts\".\"request_started_at\") = \"github_work_unit_summary_attempts\".\"started_requests\"" + }, + "gh_work_unit_summary_metrics": { + "name": "gh_work_unit_summary_metrics", + "value": "(\"github_work_unit_summary_attempts\".\"input_tokens\" IS NULL OR \"github_work_unit_summary_attempts\".\"input_tokens\" >= 0) AND (\"github_work_unit_summary_attempts\".\"output_tokens\" IS NULL OR \"github_work_unit_summary_attempts\".\"output_tokens\" >= 0) AND (\"github_work_unit_summary_attempts\".\"latency_ms\" IS NULL OR \"github_work_unit_summary_attempts\".\"latency_ms\" >= 0)" + } + }, + "isRLSEnabled": true + }, + "public.github_work_unit_summary_daily_usage": { + "name": "github_work_unit_summary_daily_usage", + "schema": "", + "columns": { + "day": { + "name": "day", + "type": "date", + "primaryKey": true, + "notNull": true + }, + "started_requests": { + "name": "started_requests", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": true + }, + "public.github_work_units": { + "name": "github_work_units", + "schema": "", + "columns": { + "activity_anchor_at": { + "name": "activity_anchor_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "activity_at": { + "name": "activity_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "activity_day": { + "name": "activity_day", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "additions": { + "name": "additions", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attribution_mode": { + "name": "attribution_mode", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "branch_lineage_id": { + "name": "branch_lineage_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "content_observed_at": { + "name": "content_observed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "deletions": { + "name": "deletions", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "facts_digest": { + "name": "facts_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "file_count": { + "name": "file_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "first_activity_at": { + "name": "first_activity_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "identity_key": { + "name": "identity_key", + "type": "varchar(180)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "languages": { + "name": "languages", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "last_activity_at": { + "name": "last_activity_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "member_count": { + "name": "member_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "membership_digest": { + "name": "membership_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "newest_commit_repository_id": { + "name": "newest_commit_repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "newest_commit_sha": { + "name": "newest_commit_sha", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "outcome_digest": { + "name": "outcome_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "pull_request_node_id": { + "name": "pull_request_node_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "repository_id": { + "name": "repository_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "summary_evaluation_digest": { + "name": "summary_evaluation_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "summary_evaluated_digest": { + "name": "summary_evaluated_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "summary_input_digest": { + "name": "summary_input_digest", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "visibility": { + "name": "visibility", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "gh_work_units_identity_unique": { + "name": "gh_work_units_identity_unique", + "columns": [ + { + "expression": "identity_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_work_units_pr_unique": { + "name": "gh_work_units_pr_unique", + "columns": [ + { + "expression": "pull_request_node_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"github_work_units\".\"kind\" = 'pull_request'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_work_units_canonical_day_unique": { + "name": "gh_work_units_canonical_day_unique", + "columns": [ + { + "expression": "repository_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "activity_day", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"github_work_units\".\"kind\" = 'canonical_day'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_work_units_branch_unique": { + "name": "gh_work_units_branch_unique", + "columns": [ + { + "expression": "branch_lineage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"github_work_units\".\"kind\" = 'branch'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "gh_work_units_feed_idx": { + "name": "gh_work_units_feed_idx", + "columns": [ + { + "expression": "visibility", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "activity_day", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "activity_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "gh_work_units_repository_fk": { + "name": "gh_work_units_repository_fk", + "tableFrom": "github_work_units", + "tableTo": "github_repositories", + "columnsFrom": ["repository_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gh_work_units_pull_request_fk": { + "name": "gh_work_units_pull_request_fk", + "tableFrom": "github_work_units", + "tableTo": "github_pull_requests", + "columnsFrom": ["pull_request_node_id"], + "columnsTo": ["node_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "gh_work_units_newest_commit_fk": { + "name": "gh_work_units_newest_commit_fk", + "tableFrom": "github_work_units", + "tableTo": "github_commits", + "columnsFrom": ["newest_commit_repository_id", "newest_commit_sha"], + "columnsTo": ["repository_id", "sha"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "gh_work_units_kind": { + "name": "gh_work_units_kind", + "value": "\"github_work_units\".\"kind\" IN ('pull_request', 'canonical_day', 'branch')" + }, + "gh_work_units_owner_shape": { + "name": "gh_work_units_owner_shape", + "value": "(\"github_work_units\".\"kind\" = 'pull_request' AND \"github_work_units\".\"pull_request_node_id\" IS NOT NULL AND \"github_work_units\".\"branch_lineage_id\" IS NULL) OR (\"github_work_units\".\"kind\" = 'canonical_day' AND \"github_work_units\".\"pull_request_node_id\" IS NULL AND \"github_work_units\".\"branch_lineage_id\" IS NULL) OR (\"github_work_units\".\"kind\" = 'branch' AND \"github_work_units\".\"pull_request_node_id\" IS NULL AND \"github_work_units\".\"branch_lineage_id\" IS NOT NULL)" + }, + "gh_work_units_identity": { + "name": "gh_work_units_identity", + "value": "(\"github_work_units\".\"kind\" = 'pull_request' AND \"github_work_units\".\"identity_key\" = 'pr:' || \"github_work_units\".\"pull_request_node_id\") OR (\"github_work_units\".\"kind\" = 'canonical_day' AND \"github_work_units\".\"identity_key\" = 'canonical:' || \"github_work_units\".\"repository_id\" || ':' || \"github_work_units\".\"activity_day\"::text) OR (\"github_work_units\".\"kind\" = 'branch' AND \"github_work_units\".\"identity_key\" = 'branch:' || \"github_work_units\".\"branch_lineage_id\"::text)" + }, + "gh_work_units_attribution_mode": { + "name": "gh_work_units_attribution_mode", + "value": "\"github_work_units\".\"attribution_mode\" IN ('tracked_authored_pr', 'foreign_pr_contribution', 'canonical_owned_composite', 'branch_owned_composite')" + }, + "gh_work_units_kind_attribution": { + "name": "gh_work_units_kind_attribution", + "value": "(\"github_work_units\".\"kind\" = 'pull_request' AND \"github_work_units\".\"attribution_mode\" IN ('tracked_authored_pr', 'foreign_pr_contribution')) OR (\"github_work_units\".\"kind\" = 'canonical_day' AND \"github_work_units\".\"attribution_mode\" = 'canonical_owned_composite') OR (\"github_work_units\".\"kind\" = 'branch' AND \"github_work_units\".\"attribution_mode\" = 'branch_owned_composite')" + }, + "gh_work_units_visibility": { + "name": "gh_work_units_visibility", + "value": "\"github_work_units\".\"visibility\" IN ('public', 'private')" + }, + "gh_work_units_nonnegative_facts": { + "name": "gh_work_units_nonnegative_facts", + "value": "\"github_work_units\".\"member_count\" > 0 AND \"github_work_units\".\"file_count\" >= 0 AND \"github_work_units\".\"additions\" >= 0 AND \"github_work_units\".\"deletions\" >= 0 AND \"github_work_units\".\"revision\" > 0" + }, + "gh_work_units_activity_order": { + "name": "gh_work_units_activity_order", + "value": "\"github_work_units\".\"first_activity_at\" <= \"github_work_units\".\"last_activity_at\" AND \"github_work_units\".\"activity_day\" = (\"github_work_units\".\"activity_at\" AT TIME ZONE 'UTC')::date" + }, + "gh_work_units_digest_shapes": { + "name": "gh_work_units_digest_shapes", + "value": "\"github_work_units\".\"facts_digest\" ~ '^[a-f0-9]{64}$' AND \"github_work_units\".\"membership_digest\" ~ '^[a-f0-9]{64}$' AND (\"github_work_units\".\"outcome_digest\" IS NULL OR \"github_work_units\".\"outcome_digest\" ~ '^[a-f0-9]{64}$') AND (\"github_work_units\".\"summary_evaluation_digest\" IS NULL OR \"github_work_units\".\"summary_evaluation_digest\" ~ '^[a-f0-9]{64}$') AND (\"github_work_units\".\"summary_evaluated_digest\" IS NULL OR \"github_work_units\".\"summary_evaluated_digest\" ~ '^[a-f0-9]{64}$') AND (\"github_work_units\".\"summary_input_digest\" IS NULL OR \"github_work_units\".\"summary_input_digest\" ~ '^[a-f0-9]{64}$')" + }, + "gh_work_units_languages_array": { + "name": "gh_work_units_languages_array", + "value": "\"github_work_units\".\"languages\" IS NULL OR jsonb_typeof(\"github_work_units\".\"languages\") = 'array'" + } + }, + "isRLSEnabled": true + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 1ec284a1..5f0b94f9 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -162,6 +162,13 @@ "when": 1788907570264, "tag": "0022_portable_github_accounts", "breakpoints": true + }, + { + "idx": 23, + "version": "7", + "when": 1790534206181, + "tag": "0023_daily_history", + "breakpoints": true } ] } diff --git a/knip.jsonc b/knip.jsonc deleted file mode 100644 index 2bbbc11c..00000000 --- a/knip.jsonc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "https://unpkg.com/knip@6/schema-jsonc.json", - // Articles are loaded by path at runtime; scripts are standalone entry points. - "entry": ["src/content/blog/**/page.mdx", "scripts/*.ts"], - "ignoreIssues": { - // Retain the upstream API of used registry components, but detect unused files. - "src/components/ui/**": ["exports", "types"], - }, - // Loaded via createRequire(import.meta.url); ships a native Typst executable. - "ignoreDependencies": ["@flukxr/typst-cli"], - // Installed and pinned by mise, not npm. - "ignoreBinaries": ["typstyle"], - "ignoreExportsUsedInFile": true, -} diff --git a/knip.ts b/knip.ts new file mode 100644 index 00000000..67aa7eaa --- /dev/null +++ b/knip.ts @@ -0,0 +1,32 @@ +import type { KnipConfig } from "knip"; + +const config: KnipConfig = ({ production }) => ({ + // `!` keeps real entry points in the production check, where tests do not + // count as callers. Standalone test runners are development-only entries. + entry: [ + "src/content/blog/**/page.mdx!", + "scripts/*.ts!", + "!scripts/test-*.ts!", + ], + project: [ + "**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts,mdx,css}!", + "!tests/**!", + "!scripts/test-*.ts!", + ], + // Include the config's build-time imports, not only Next's route entries. + next: { entry: ["next.config.ts"] }, + // Knip 6 classifies workflow scripts as development-only even if explicitly + // listed above. Check workflows in the default pass; retain script roots here. + "github-actions": production !== true, + ignoreIssues: { + // Preserve the upstream API of registry components, but detect unused files. + "src/components/ui/**": ["exports", "types"], + }, + // Loaded via createRequire(import.meta.url); ships a native Typst executable. + ignoreDependencies: ["@flukxr/typst-cli"], + // Installed and pinned by mise, not npm. + ignoreBinaries: ["typstyle"], + ignoreExportsUsedInFile: true, +}); + +export default config; diff --git a/package.json b/package.json index 0a11e091..f37968f0 100644 --- a/package.json +++ b/package.json @@ -18,14 +18,14 @@ "format:typ": "typstyle -i career", "format:typ:check": "typstyle --check career", "db:generate": "drizzle-kit generate", - "db:migrate": "drizzle-kit migrate", + "db:migrate": "drizzle-kit migrate && bun scripts/migrate-daily-history.ts", "db:studio": "drizzle-kit studio", "codex:backfill": "bun scripts/backfill-codex.ts", "codex:account": "bun scripts/configure-codex-account.ts", "github:sync": "bun scripts/sync-github-commits.ts", "github:verify": "bun scripts/verify-github-work-units.ts", "supabase:cron": "bun scripts/configure-supabase-cron.ts", - "lint:unused": "knip" + "lint:unused": "knip && knip --production" }, "dependencies": { "@ai-sdk/openai": "4.0.41", diff --git a/scripts/configure-codex-account.ts b/scripts/configure-codex-account.ts index cbb0f7a0..51c82e63 100644 --- a/scripts/configure-codex-account.ts +++ b/scripts/configure-codex-account.ts @@ -22,41 +22,65 @@ if (databaseUrl === undefined || databaseUrl.length === 0) { } const authJson = await readFile(path.resolve(codexHome, "auth.json"), "utf-8"); -validateCodexAuthJson(authJson); +const providerAccountId = validateCodexAuthJson(authJson).tokens.account_id; const secretName = `codex_auth_${id}`; const sql = postgres(databaseUrl, { max: 1, prepare: false }); try { await sql`create schema if not exists vault`; await sql`create extension if not exists supabase_vault with schema vault`; - const [secret] = await sql<{ id: string }[]>` - select id::text from vault.secrets where name = ${secretName} limit 1 - `; - await (secret === undefined - ? sql` - select vault.create_secret( - ${authJson}, - ${secretName}, - 'Codex usage dashboard credentials' - ) - ` - : sql` - select vault.update_secret( - ${secret.id}::uuid, - ${authJson}, - ${secretName}, - 'Codex usage dashboard credentials' - ) - `); + await sql.begin(async (transaction) => { + // Account identity and credentials change atomically. A reauthorization never clears history. + const [account] = await transaction< + { + provider_account_id: string | null; + sync_until: Date | null; + has_history: boolean; + }[] + >` + select provider_account_id, sync_until, + snapshot is not null or exists (select 1 from codex_usage_days where account_id = ${id}) as has_history + from codex_accounts where id = ${id} for update + `; + if ( + account?.sync_until !== undefined && + account.sync_until !== null && + new Date(account.sync_until).getTime() > Date.now() + ) { + throw new Error( + "A sync is running. Retry account configuration after it finishes." + ); + } + const [secret] = await transaction< + { id: string; decrypted_secret: string }[] + >` + select id::text, decrypted_secret from vault.decrypted_secrets where name = ${secretName} + `; + const previousIdentity = + account?.provider_account_id ?? + (secret === undefined + ? null + : validateCodexAuthJson(secret.decrypted_secret).tokens.account_id); + if (previousIdentity === null && account?.has_history) { + throw new Error( + "This alias has history but its account identity cannot be verified. Use a new alias." + ); + } + if (previousIdentity !== null && previousIdentity !== providerAccountId) { + throw new Error( + "This alias belongs to a different Codex account. Use a new alias." + ); + } + await transaction` + insert into codex_accounts (id, enabled, provider_account_id) + values (${id}, true, ${providerAccountId}) + on conflict (id) do update set enabled = true, provider_account_id = excluded.provider_account_id + `; + await (secret === undefined + ? transaction`select vault.create_secret(${authJson}, ${secretName}, 'Codex usage dashboard credentials')` + : transaction`select vault.update_secret(${secret.id}::uuid, ${authJson}, ${secretName}, 'Codex usage dashboard credentials')`); + }); - await sql` - insert into codex_accounts (id, enabled) - values (${id}, true) - on conflict (id) do update set - enabled = true, - snapshot = null, - snapshot_at = null - `; process.stdout.write(`Configured Codex stats account ${id}.\n`); } finally { await sql.end({ timeout: 5 }); diff --git a/scripts/configure-supabase-cron.ts b/scripts/configure-supabase-cron.ts index 15a9a3ba..6c8a4ae1 100644 --- a/scripts/configure-supabase-cron.ts +++ b/scripts/configure-supabase-cron.ts @@ -273,6 +273,13 @@ export const configureSupabaseCron = async ( } jobs.push({ name: job.name, jobId: scheduled.jobId }); } + const [cleanup] = await transaction<{ jobId: number }[]>` + select cron.schedule('activity-history-retention', '23 3 * * *', 'select public.cleanup_activity_history()') as "jobId" + `; + if (cleanup === undefined) { + throw new Error("Supabase did not schedule activity retention."); + } + jobs.push({ name: "activity-history-retention", jobId: cleanup.jobId }); return jobs; }); diff --git a/scripts/migrate-daily-history.ts b/scripts/migrate-daily-history.ts new file mode 100644 index 00000000..62b4a7db --- /dev/null +++ b/scripts/migrate-daily-history.ts @@ -0,0 +1,68 @@ +import { eq } from "drizzle-orm"; + +import { codexAccounts, codexUsageDays } from "../src/db/codex-schema"; +import { + liveCodexSnapshot, + partitionCodexHistory, +} from "../src/lib/codex/daily-history"; + +// Match drizzle.config.ts before the database module captures its environment. +if ( + import.meta.main && + (process.env.DATABASE_URL_UNPOOLED?.trim().length ?? 0) > 0 +) { + process.env.DATABASE_URL = process.env.DATABASE_URL_UNPOOLED; +} +const { closeDatabase, getDatabase } = await import("../src/db/client"); +const { publishGitHubActivitySnapshots } = + await import("../src/lib/github-activity-snapshots"); + +// Restartable import: move historical rows before compacting the live snapshot. +export const migrateDailyHistory = async () => { + const accounts = await getDatabase() + .select({ id: codexAccounts.id }) + .from(codexAccounts); + let imported = 0; + for (const { id } of accounts) { + const added = await getDatabase().transaction(async (transaction) => { + let count = 0; + const [account] = await transaction + .select({ snapshot: codexAccounts.snapshot }) + .from(codexAccounts) + .where(eq(codexAccounts.id, id)) + .for("update"); + if (account?.snapshot === undefined || account.snapshot === null) { + return 0; + } + const rows = [...partitionCodexHistory(account.snapshot)].map( + ([day, payload]) => ({ accountId: id, day, payload }) + ); + for (let offset = 0; offset < rows.length; offset += 100) { + const saved = await transaction + .insert(codexUsageDays) + .values(rows.slice(offset, offset + 100)) + .onConflictDoNothing() + .returning({ day: codexUsageDays.day }); + count += saved.length; + } + if (rows.length > 0) { + await transaction + .update(codexAccounts) + .set({ snapshot: liveCodexSnapshot(account.snapshot) }) + .where(eq(codexAccounts.id, id)); + } + return count; + }); + imported += added; + } + const github = await publishGitHubActivitySnapshots(undefined, true); + return { tokenDays: imported, github }; +}; + +if (import.meta.main) { + try { + process.stdout.write(`${JSON.stringify(await migrateDailyHistory())}\n`); + } finally { + await closeDatabase(); + } +} diff --git a/scripts/migrate-production-database.ts b/scripts/migrate-production-database.ts index b15d4c24..918a99c9 100644 --- a/scripts/migrate-production-database.ts +++ b/scripts/migrate-production-database.ts @@ -82,6 +82,7 @@ const runDrizzleMigrations = async (databaseUrl: string) => { const migrationProcess = spawn(process.execPath, ["run", "db:migrate"], { env: { ...process.env, + DATABASE_URL: databaseUrl, DATABASE_URL_UNPOOLED: databaseUrl, }, stdio: "inherit", diff --git a/scripts/test-daily-history-database.ts b/scripts/test-daily-history-database.ts new file mode 100644 index 00000000..505b27f5 --- /dev/null +++ b/scripts/test-daily-history-database.ts @@ -0,0 +1,770 @@ +import assert from "node:assert/strict"; +import { randomUUID } from "node:crypto"; +import { cp, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import { sql as query } from "drizzle-orm"; +import { drizzle } from "drizzle-orm/postgres-js"; +import { migrate } from "drizzle-orm/postgres-js/migrator"; +import postgres from "postgres"; + +import { closeDatabase, getDatabase } from "../src/db/client"; +import { createCodexAccountSnapshot } from "../src/lib/codex/stats"; +import { + claimCodexAccount, + releaseCodexAccount, + saveCodexAccount, +} from "../src/lib/codex/store"; +import { dateKey, WORK_LOG_TIME_ZONE } from "../src/lib/date"; +import { publishGitHubActivitySnapshots } from "../src/lib/github-activity-snapshots"; +import { readPublicGitHubActivityPage } from "../src/lib/github-activity-store"; +import { + claimGitHubCommitsForEnrichment, + claimGitHubPushObservations, + completeGitHubPushObservation, + persistGitHubPullRequestMembership, + persistGitHubPullRequestDiff, +} from "../src/lib/github-activity-worker-store"; +import type { + GitHubPullRequest, + GitHubRepositoryFacts, +} from "../src/lib/github-commits-core"; +import { TRACKED_GITHUB_USER_IDS } from "../src/lib/github-commits-core"; +import { + persistAccountIntake, + readGitHubAccountCheckpoint, +} from "../src/lib/github-commits-store"; +import { persistPullRequestSnapshotInTransaction } from "../src/lib/github-pull-request-store"; +import { + requestGitHubWorkUnitProjection, + completeGitHubWorkUnitProjectionRequest, +} from "../src/lib/github-work-unit-projection-state"; +import { + refreshGitHubWorkUnitProjection, + readGitHubWorkUnitProjectionEvidence, +} from "../src/lib/github-work-unit-store"; +import { GITHUB_WORK_UNIT_SUMMARY_RECIPE } from "../src/lib/github-work-unit-summary"; +import { + claimGitHubWorkUnitSummary, + completeGitHubWorkUnitSummary, +} from "../src/lib/github-work-unit-summary-store"; +import { migrateDailyHistory } from "./migrate-daily-history"; + +const url = new URL(process.env.DATABASE_URL ?? ""); +assert.ok( + ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname) && + /^\/daily_history_[a-f0-9]+$/.test(url.pathname) +); +const sql = postgres(url.toString(), { max: 1 }); +const now = new Date(); +const today = now.toISOString().slice(0, 10); +const yesterday = new Date(now.getTime() - 86_400_000) + .toISOString() + .slice(0, 10); +const oldDay = new Date(now.getTime() - 3 * 86_400_000) + .toISOString() + .slice(0, 10); +const auth = JSON.stringify({ + auth_mode: "chatgpt", + tokens: { + account_id: "test-provider", + access_token: "test-access", + refresh_token: "test-refresh", + }, +}); +const snapshot = createCodexAccountSnapshot( + { + stats: { + daily_usage_buckets: [ + { start_date: oldDay, tokens: 200 }, + { start_date: yesterday, tokens: 30 }, + { start_date: today, tokens: 0 }, + ], + }, + }, + {} +); +try { + const migration = postgres(url.toString(), { + max: 1, + }); + try { + const legacyFolder = await mkdtemp( + path.join(tmpdir(), "activity-migration-") + ); + try { + await cp("drizzle", legacyFolder, { recursive: true }); + const journal = JSON.parse( + await readFile(path.join(legacyFolder, "meta/_journal.json"), "utf-8") + ); + journal.entries = journal.entries.filter( + (entry: { idx: number }) => entry.idx < 23 + ); + await writeFile( + path.join(legacyFolder, "meta/_journal.json"), + JSON.stringify(journal) + ); + await migrate(drizzle(migration), { migrationsFolder: legacyFolder }); + } finally { + await rm(legacyFolder, { recursive: true, force: true }); + } + const currentId = randomUUID(); + const priorId = randomUUID(); + const pushId = randomUUID(); + const shaA = "a".repeat(40), + shaB = "b".repeat(40); + const digest = "c".repeat(64); + await sql`insert into github_repositories(id,full_name) values ('90','example/migration')`; + await sql`insert into github_pull_requests(node_id,repository_id,account,author_user_id,number,created_at,provider_updated_at,state,title,title_snapshot,url,base_sha,head_sha) + values ('migration-pr','90','f0rr0','1',1,now(),now(),'open','Migration','Migration','https://github.com/example/migration/pull/1',${shaA},${shaB})`; + await sql`insert into github_pull_request_versions(id,pull_request_node_id,base_repository_id,base_sha,head_sha,commit_count,is_current,membership_complete,file_facts,file_facts_complete,provider_updated_at) + values (${currentId},'migration-pr','90',${shaA},${shaB},1,true,true,'[{"filename":"a.ts","patch":"+actual patch"}]',true,now()), + (${priorId},'migration-pr','90',${shaA},${shaA},1,false,true,'[]',true,now())`; + await sql`insert into github_pull_request_memberships(version_id,commit_repository_id,commit_sha,position,is_head) + values (${currentId},'90',${shaB},0,true),(${priorId},'90',${shaA},0,true)`; + const [originalEvidence] = + await sql`select file_facts,file_facts_digest from github_pull_request_versions where id=${currentId}`; + await sql`insert into github_push_observations(id,account,after_sha,before_sha,repository_id,repository_name_snapshot,ref_name,source,source_id) + values (${pushId},'f0rr0',${shaB},${"0".repeat(40)},'90','example/migration','refs/heads/main','events','900')`; + await sql`insert into github_push_observation_commits(observation_id,repository_id,sha,position) values (${pushId},'90',${shaB},1),(${pushId},'90',${shaA},0)`; + await sql`insert into github_work_unit_accepted_summaries(identity_key,repository_id,attribution_mode,recipe,outcome_digest,summary_input_digest,outcome,accepted_at) + values ('pr:migration-pr','90','tracked_authored_pr',${GITHUB_WORK_UNIT_SUMMARY_RECIPE},${digest},${digest},'Kept the historical summary',now())`; + const usageBefore = + await sql`select * from github_work_unit_summary_daily_usage order by day`; + await sql`update github_push_observation_commits set repository_id='91' where observation_id=${pushId} and position=0`; + await assert.rejects( + migrate(drizzle(migration), { migrationsFolder: "drizzle" }), + "A corrupt legacy list aborts the whole migration" + ); + assert.equal( + ( + await sql`select to_regclass('github_pull_request_versions') is not null as present` + )[0].present, + true + ); + assert.equal( + ( + await sql`select count(*)::int as n from information_schema.columns where table_name='github_pull_requests' and column_name='snapshot_id'` + )[0].n, + 0, + "DDL also rolls back on failed validation" + ); + await sql`update github_push_observation_commits set repository_id='90' where observation_id=${pushId}`; + await migrate(drizzle(migration), { migrationsFolder: "drizzle" }); + await migrate(drizzle(migration), { migrationsFolder: "drizzle" }); + assert.deepEqual( + ( + await sql`select file_facts,file_facts_digest from github_pull_requests where node_id='migration-pr'` + )[0], + originalEvidence + ); + assert.deepEqual( + ( + await sql`select known_shas from github_push_observations where id=${pushId}` + )[0].known_shas, + [shaA, shaB] + ); + assert.equal( + (await sql`select version_id from github_pull_request_memberships`)[0] + .version_id, + currentId + ); + assert.equal( + ( + await sql`select count(*)::int as n from github_pull_request_memberships` + )[0].n, + 1 + ); + const [accepted] = + await sql`select outcome,started_requests from github_work_unit_summary_attempts where identity_key='pr:migration-pr'`; + assert.equal(accepted.outcome, "Kept the historical summary"); + assert.equal(accepted.started_requests, 0); + assert.deepEqual( + await sql`select * from github_work_unit_summary_daily_usage order by day`, + usageBefore + ); + for (const table of [ + "github_pull_request_versions", + "github_push_observation_commits", + "github_work_unit_accepted_summaries", + ]) { + assert.equal( + (await sql`select to_regclass(${table}) as name`)[0].name, + null + ); + } + await sql`delete from github_pull_requests where node_id='migration-pr'`; + await sql`delete from github_push_observations where id=${pushId}`; + } finally { + await migration.end(); + } + await sql.unsafe(`create schema vault; + create table vault.secrets(id uuid primary key default gen_random_uuid(), name text unique, decrypted_secret text); + create view vault.decrypted_secrets as select * from vault.secrets; + create function vault.update_secret(uuid,text,text,text) returns uuid language sql as 'update vault.secrets set decrypted_secret = $2 where id = $1 returning id';`); + await sql`insert into vault.secrets(name, decrypted_secret) values ('codex_auth_test', ${auth}), ('codex_auth_duplicate', ${auth})`; + await sql`insert into codex_accounts(id,snapshot,snapshot_at) values ('test',${JSON.stringify(snapshot)}::text::jsonb, now())`; + await migrateDailyHistory(); + assert.equal( + (await sql`select snapshot from codex_accounts where id='test'`)[0].snapshot + .dailyUsageBuckets, + null + ); + assert.deepEqual(await migrateDailyHistory(), { + tokenDays: 0, + github: { changed: false, workUnits: 0, issues: 0 }, + }); + const [first, second] = await Promise.all([ + claimCodexAccount("test"), + claimCodexAccount("test"), + ]); + assert.ok( + Number(first !== null) + Number(second !== null) === 1, + "Only one overlapping sync owns the account" + ); + const account = first ?? second; + assert.ok(account); + const corrected = structuredClone(snapshot); + corrected.dailyUsageBuckets = [ + { startDate: oldDay, tokens: 999 }, + { startDate: yesterday, tokens: 40 }, + { startDate: today, tokens: 0 }, + ]; + await saveCodexAccount(account, auth, corrected); + await saveCodexAccount(account, auth, { + ...corrected, + dailyUsageBuckets: null, + cumulativeDailyUsageBuckets: null, + }); + const days = + await sql`select day::text, payload from codex_usage_days order by day`; + assert.equal( + days.find((row) => row.day === oldDay)?.payload.dailyUsageBuckets[0].tokens, + 200 + ); + assert.equal( + days.find((row) => row.day === yesterday)?.payload.dailyUsageBuckets[0] + .tokens, + 40 + ); + await sql`update codex_accounts set sync_token = gen_random_uuid() where id = 'test'`; + await assert.rejects( + saveCodexAccount(account, "invalid-stale-credentials", corrected) + ); + assert.equal( + ( + await sql`select decrypted_secret from vault.secrets where name = 'codex_auth_test'` + )[0].decrypted_secret, + auth + ); + await releaseCodexAccount(account); + await sql`insert into codex_accounts(id) values ('duplicate')`; + await assert.rejects( + claimCodexAccount("duplicate"), + "Duplicate underlying identities cannot count twice" + ); + + await sql`insert into github_repositories(id, full_name, visibility, facts_verified_at) values ('1','example/repo','public',now()), ('2','example/other','public',now())`; + const token = await requestGitHubWorkUnitProjection(getDatabase(), ["1"]); + const newer = await requestGitHubWorkUnitProjection(getDatabase(), ["2"]); + assert.equal(await completeGitHubWorkUnitProjectionRequest(token), false); + assert.equal( + (await sql`select projection_request_token from github_public_feed_head`)[0] + .projection_request_token, + newer + ); + await refreshGitHubWorkUnitProjection(); + assert.ok( + (await sql`select projection_request_token from github_repositories`).every( + (row) => row.projection_request_token === null + ) + ); + + const workUnitId = randomUUID(); + const historicalAt = new Date(now.getTime() - 86_400_000); + const historicalDay = dateKey(historicalAt, WORK_LOG_TIME_ZONE); + const payload = { + id: `${historicalDay}:pr:fixture`, + day: historicalDay, + kind: "pull-request", + activityAt: historicalAt.toISOString(), + repository: { + key: "1", + label: "example/repo", + url: "https://github.com/example/repo", + avatarUrl: null, + }, + destination: { + label: "Open pull request", + url: "https://github.com/example/repo/pull/1", + }, + facts: { + additions: 200, + deletions: 0, + uniqueFileCount: 1, + ownedCommitCount: 1, + languages: [], + dateRange: null, + }, + headline: null, + summary: null, + summarizing: false, + }; + const digest = "a".repeat(64); + await sql`insert into github_activity_snapshots(day, identity_key, repository_id, payload, work_unit_id, work_unit_revision, attribution_mode, outcome_digest, summary_input_digest) + values (${historicalDay}, 'pr:fixture', '1', ${sql.json(payload)}, ${workUnitId}, 1, 'tracked_authored_pr', ${digest}, ${digest})`; + await assert.rejects( + sql`update github_activity_snapshots set payload = jsonb_set(payload, '{facts,additions}', '240')` + ); + await assert.rejects(sql`delete from github_activity_snapshots`); + await sql`insert into github_work_unit_summary_attempts(work_unit_id, revision, identity_key, repository_id, attribution_mode, recipe, outcome_digest, summary_input_digest, request_payload, debounce_until) + values (${workUnitId},1,'pr:fixture','1','tracked_authored_pr',${GITHUB_WORK_UNIT_SUMMARY_RECIPE},${digest},${digest},'{}',now()-interval '1 minute')`; + const claim = await claimGitHubWorkUnitSummary(); + assert.ok( + claim, + "A saved card pins its pending summary after the live work unit disappears" + ); + await completeGitHubWorkUnitSummary(claim, { + outcome: "Added search", + model: "gpt-5.4-nano-2026-03-17", + latencyMs: 1, + inputTokens: 1, + outputTokens: 1, + }); + const [saved] = await sql`select payload from github_activity_snapshots`; + assert.equal(saved.payload.headline, "Added search"); + assert.deepEqual(saved.payload.facts, payload.facts); + await assert.rejects( + sql`update github_activity_snapshots set payload = jsonb_set(payload, '{headline}', '"Changed past"')` + ); + await sql`update github_repositories set visibility = 'private' where id = '1'`; + const page = await readPublicGitHubActivityPage(null); + assert.equal(page.days[0].repositories[0].repository.label, "Private"); + assert.equal(page.days[0].repositories[0].items[0].destination, null); + + const sha = "b".repeat(40); + const facts = [ + { + filename: "src/search.ts", + additions: 1, + deletions: 0, + changes: 1, + status: "added", + previousFilename: null, + binary: false, + patchComplete: true, + patch: "@@ -0,0 +1 @@\n+search", + }, + ]; + await sql`insert into github_commits(repository_id, sha, author_login, message, committed_at, first_observed_at, enrichment_state, pr_discovery_state, file_facts, file_facts_complete) + values ('1',${sha},'f0rr0','Add search',now()-interval '40 days',now()-interval '40 days','complete','complete',${sql.json(facts)},true)`; + const [before] = + await sql`select file_facts_digest from github_commits where sha=${sha}`; + const branchId = randomUUID(); + const branchUnitId = randomUUID(); + const branchIdentity = `branch:${branchId}`; + const branchPayload = { + ...payload, + id: `${historicalDay}:${branchIdentity}`, + kind: "branch", + }; + await sql`insert into github_activity_snapshots(day, identity_key, repository_id, payload, work_unit_id, work_unit_revision, attribution_mode, outcome_digest) + values (${historicalDay},${branchIdentity},'1',${sql.json(branchPayload)},${branchUnitId},1,'branch_owned_composite',${digest})`; + const insertBranch = async () => + await sql`insert into github_work_units(id, identity_key, kind, branch_lineage_id, repository_id, + newest_commit_repository_id, newest_commit_sha, activity_at, activity_anchor_at, activity_day, first_activity_at, last_activity_at, + content_observed_at, attribution_mode, visibility, additions, deletions, file_count, member_count, facts_digest, membership_digest, outcome_digest) + values (${branchUnitId},${branchIdentity},'branch',${branchId},'1','1',${sha},${historicalAt},${historicalAt},${historicalAt.toISOString().slice(0, 10)}, + ${historicalAt},${historicalAt},now(),'branch_owned_composite','public',240,0,1,1,${"b".repeat(64)},${digest},${"b".repeat(64)})`; + await insertBranch(); + await sql`insert into github_work_unit_memberships(work_unit_id, logical_repository_id, logical_sha, position) values (${branchUnitId},'1',${sha},0)`; + assert.equal( + (await sql`select cleanup_activity_history() as result`)[0].result + .commitPatches, + 0, + "Live memberships pin raw patches" + ); + await publishGitHubActivitySnapshots(["1"]); + const branchRows = + await sql`select day::text, payload from github_activity_snapshots where identity_key=${branchIdentity} order by day`; + assert.equal(branchRows.length, 2); + assert.deepEqual( + branchRows.map((row) => row.payload.facts.additions), + [200, 240] + ); + await publishGitHubActivitySnapshots(["1"]); + assert.equal( + ( + await sql`select count(*)::int as n from github_activity_snapshots where identity_key=${branchIdentity}` + )[0].n, + 2 + ); + await sql`update github_work_units set outcome_digest=null, additions=300 where id=${branchUnitId}`; + await publishGitHubActivitySnapshots(["1"]); + assert.equal( + ( + await sql`select payload from github_activity_snapshots where identity_key=${branchIdentity} order by day desc limit 1` + )[0].payload.facts.additions, + 240 + ); + await sql`delete from github_work_units where id=${branchUnitId}`; + await publishGitHubActivitySnapshots(["1"], false, ["1"]); + assert.equal( + ( + await sql`select count(*)::int as n from github_activity_snapshots where identity_key=${branchIdentity}` + )[0].n, + 2 + ); + await publishGitHubActivitySnapshots(["1"]); + assert.equal( + ( + await sql`select count(*)::int as n from github_activity_snapshots where identity_key=${branchIdentity}` + )[0].n, + 1, + "Only today's disappeared ownership is removed" + ); + const [cleanup] = await sql`select cleanup_activity_history() as result`; + assert.equal(cleanup.result.commitPatches, 1); + const [after] = + await sql`select file_facts, file_facts_digest, file_facts_complete from github_commits where sha=${sha}`; + assert.equal(after.file_facts[0].patch, null); + assert.equal(after.file_facts_digest, before.file_facts_digest); + assert.equal(after.file_facts_complete, true); + assert.equal( + (await sql`select cleanup_activity_history() as result`)[0].result + .commitPatches, + 0 + ); + assert.equal( + (await claimGitHubCommitsForEnrichment(1, ["f0rr0"])).length, + 0, + "Retention must not cause a refetch loop" + ); + await insertBranch(); + await sql`insert into github_work_unit_memberships(work_unit_id, logical_repository_id, logical_sha, position) values (${branchUnitId},'1',${sha},0)`; + assert.equal( + (await claimGitHubCommitsForEnrichment(1, ["f0rr0"])).length, + 1, + "A reintroduced commit fetches its patch again" + ); + await sql`update github_commits set file_facts=${sql.json(facts)}, file_facts_pruned_at=null where sha=${sha}`; + assert.equal( + ( + await sql`select file_facts_digest from github_commits where sha=${sha}` + )[0].file_facts_digest, + before.file_facts_digest + ); + await sql`insert into github_pull_requests(node_id, repository_id, account, author_user_id, number, created_at, provider_updated_at, state, title, title_snapshot, url) + values ('fork-pr','2','f0rr0',${TRACKED_GITHUB_USER_IDS.f0rr0},1,now(),now(),'open','Fork work','Fork work','https://github.com/example/other/pull/1')`; + await sql`insert into github_commit_pull_request_associations(commit_repository_id, commit_sha, pull_request_node_id) values ('1',${sha},'fork-pr')`; + for (const repository of ["1", "2"]) { + const scope = await readGitHubWorkUnitProjectionEvidence([repository]); + assert.deepEqual( + scope.input.repositories.map(({ id }) => id), + ["1", "2"], + "Fork dependencies expand in both directions" + ); + } + await sql`insert into github_issues(node_id, repository_id, account, author_user_id, number, created_at, title_snapshot, url_snapshot) + values ('late-issue','2','f0rr0',${TRACKED_GITHUB_USER_IDS.f0rr0},2,${historicalAt},'Late discovery','https://github.com/example/other/issues/2')`; + await publishGitHubActivitySnapshots(["2"]); + const [issue] = + await sql`select day::text from github_activity_snapshots where identity_key='issue:late-issue'`; + assert.equal( + issue?.day, + dateKey(now, WORK_LOG_TIME_ZONE), + "Late issues publish today without changing past pages" + ); + const repository: GitHubRepositoryFacts = { + id: "90", + fullName: "example/migration", + defaultBranch: "main", + htmlUrl: null, + ownerAvatarUrl: null, + ownerId: "1", + ownerLogin: "example", + ownerType: "User", + pushedAt: null, + visibility: "public", + }; + const pr: GitHubPullRequest = { + action: "synchronize", + additions: 200, + deletions: 0, + author: "f0rr0", + authorAccount: "f0rr0", + authorUserId: TRACKED_GITHUB_USER_IDS.f0rr0, + baseRef: "main", + baseRepository: repository, + baseSha: "a".repeat(40), + body: null, + changedFiles: 1, + closedAt: null, + commitCount: 1, + createdAt: now.toISOString(), + draft: false, + headRef: "feature", + headRepository: repository, + headSha: "b".repeat(40), + id: "901", + mergeCommitSha: undefined, + merged: false, + mergedAt: null, + nodeId: "migration-pr", + number: 1, + providerUpdatedAt: now.toISOString(), + repository, + state: "open", + title: "Search", + url: "https://github.com/example/migration/pull/1", + }; + const persist = async ( + value: GitHubPullRequest, + authority: "authoritative" | "observed" = "authoritative" + ) => + await getDatabase().transaction( + async (tx) => + await persistPullRequestSnapshotInTransaction( + tx, + "f0rr0", + value, + { authority, refreshMembership: true }, + new Date() + ) + ); + const firstPr = await persist(pr); + assert.ok(firstPr); + assert.equal( + await persistGitHubPullRequestMembership( + firstPr, + pr.headSha, + [pr.headSha], + true + ), + true + ); + assert.equal( + await persistGitHubPullRequestDiff(firstPr, pr.baseSha, pr.headSha, facts), + true + ); + const repeated = await persist(pr); + assert.equal(repeated?.versionId, firstPr.versionId); + assert.equal(repeated?.diffRefreshRequired, false); + assert.equal(repeated?.membershipRefreshRequired, false); + const secondPr = await persist({ ...pr, headSha: "c".repeat(40) }); + assert.ok(secondPr); + assert.notEqual(secondPr.versionId, firstPr.versionId); + assert.equal( + await persistGitHubPullRequestDiff(firstPr, pr.baseSha, pr.headSha, facts), + false + ); + const restored = await persist(pr); + assert.ok(restored); + assert.notEqual( + restored.versionId, + firstPr.versionId, + "A -> B -> A does not resurrect a stale lease" + ); + assert.equal( + await persistGitHubPullRequestMembership( + firstPr, + pr.headSha, + [pr.headSha], + true + ), + false + ); + assert.equal( + await persistGitHubPullRequestMembership( + restored, + pr.headSha, + [pr.headSha, pr.headSha], + true + ), + false + ); + const rebased = await persist({ ...pr, baseSha: "d".repeat(40) }); + assert.ok(rebased); + assert.notEqual(rebased.versionId, restored.versionId); + assert.equal( + await persistGitHubPullRequestDiff(restored, pr.baseSha, pr.headSha, facts), + false + ); + assert.equal( + await persist(pr, "observed"), + null, + "Equal-time webhook cannot replace a different authoritative base" + ); + assert.equal( + await persist({ + ...pr, + providerUpdatedAt: new Date(now.getTime() - 1000).toISOString(), + }), + null + ); + const emptyPr = await persist({ ...pr, commitCount: 0, changedFiles: 0 }); + assert.ok(emptyPr); + assert.equal( + await persistGitHubPullRequestMembership(emptyPr, pr.headSha, [], true), + true + ); + assert.equal( + await persistGitHubPullRequestDiff(emptyPr, pr.baseSha, pr.headSha, []), + true + ); + + const mergedPr = await persist({ + ...pr, + commitCount: 0, + changedFiles: 0, + state: "closed", + closedAt: now.toISOString(), + merged: true, + mergedAt: now.toISOString(), + mergeCommitSha: null, + }); + assert.equal( + mergedPr?.versionId, + emptyPr.versionId, + "Merge metadata does not discard unchanged evidence" + ); + const reopenedPr = await persist({ ...pr, commitCount: 0, changedFiles: 0 }); + assert.equal(reopenedPr?.versionId, emptyPr.versionId); + assert.equal( + ( + await sql`select merge_snapshot from github_pull_requests where node_id=${pr.nodeId}` + )[0].merge_snapshot, + false + ); + const reusedId = randomUUID(); + const reusedDigest = "c".repeat(64); + await sql`insert into github_work_units(id,identity_key,kind,pull_request_node_id,repository_id,newest_commit_repository_id,newest_commit_sha, + activity_at,activity_anchor_at,activity_day,first_activity_at,last_activity_at,content_observed_at,attribution_mode,visibility, + additions,deletions,file_count,member_count,facts_digest,membership_digest,outcome_digest,summary_input_digest,summary_evaluation_digest,summary_evaluated_digest) + values (${reusedId},'pr:migration-pr','pull_request','migration-pr','90','1',${sha},${now},${now},${today},${now},${now},${now},'tracked_authored_pr','public',200,0,1,1, + ${reusedDigest},${reusedDigest},${reusedDigest},${reusedDigest},${reusedDigest},${reusedDigest})`; + await sql`insert into github_work_unit_summary_attempts(work_unit_id,revision,identity_key,repository_id,attribution_mode,recipe,outcome_digest,summary_input_digest,request_payload,debounce_until) + values (${reusedId},1,'pr:migration-pr','90','tracked_authored_pr',${GITHUB_WORK_UNIT_SUMMARY_RECIPE},${reusedDigest},${reusedDigest},'{}',now()-interval '1 minute')`; + const usageBeforeReuse = + await sql`select * from github_work_unit_summary_daily_usage order by day`; + assert.equal( + await claimGitHubWorkUnitSummary(), + null, + "An imported accepted outcome is reused without another paid request" + ); + const [reusedAttempt] = + await sql`select state,outcome,started_requests from github_work_unit_summary_attempts where work_unit_id=${reusedId}`; + assert.equal(reusedAttempt.state, "accepted"); + assert.equal(reusedAttempt.outcome, "Kept the historical summary"); + assert.equal(reusedAttempt.started_requests, 0); + assert.deepEqual( + await sql`select * from github_work_unit_summary_daily_usage order by day`, + usageBeforeReuse + ); + await refreshGitHubWorkUnitProjection(); + assert.equal( + ( + await sql`select count(*)::int as n from github_work_units where id=${reusedId}` + )[0].n, + 0 + ); + assert.equal( + ( + await sql`select state from github_work_unit_summary_attempts where work_unit_id=${reusedId}` + )[0].state, + "accepted", + "Zero-start accepted summaries survive removal of live work" + ); + const push = { + before: "0".repeat(40), + head: pr.headSha, + commitShas: [pr.baseSha, pr.headSha], + pushedBy: "f0rr0" as const, + ref: "refs/heads/feature", + repository, + size: 2, + }; + const intake = async (commitShas = push.commitShas) => + await persistAccountIntake({ + account: "f0rr0", + events: [ + { + id: "901", + occurredAt: now.toISOString(), + issue: null, + pullRequest: null, + push: { ...push, commitShas }, + }, + ], + expectedCheckpoint: await readGitHubAccountCheckpoint("f0rr0"), + gap: null, + latestEventId: "901", + }); + await assert.rejects( + intake([pr.headSha, pr.headSha]), + "Duplicate SHAs are rejected before storage" + ); + await assert.rejects( + intake(["invalid", pr.headSha]), + "Malformed SHAs are rejected before storage" + ); + assert.equal((await intake()).knownCommits, 2); + assert.equal((await intake()).pushes, 0); + await assert.rejects( + intake([pr.headSha, pr.baseSha]), + "Conflicting order must not replace durable evidence" + ); + const [pushClaim] = await claimGitHubPushObservations(1, ["f0rr0"]); + assert.ok(pushClaim !== undefined); + assert.deepEqual(pushClaim.knownShas, push.commitShas); + await sql`update github_push_observations set source='refs',expected_commit_count=null,known_shas=array[${pr.headSha}] where id=${pushClaim.id}`; + assert.equal( + (await intake()).pushes, + 1, + "Exact event evidence promotes an incomplete ref observation" + ); + assert.equal( + ( + await completeGitHubPushObservation(pushClaim, { + commitShas: push.commitShas, + commits: [], + }) + ).stale, + true, + "Promotion invalidates an in-flight claim" + ); + const [promotedClaim] = await claimGitHubPushObservations(1, ["f0rr0"]); + assert.ok(promotedClaim !== undefined); + assert.deepEqual(promotedClaim.knownShas, push.commitShas); + + assert.equal( + ( + await completeGitHubPushObservation(promotedClaim, { + commitShas: push.commitShas, + commits: [], + }) + ).stale, + false + ); + assert.equal( + ( + await completeGitHubPushObservation(promotedClaim, { + commitShas: push.commitShas, + commits: [], + }) + ).stale, + true + ); + assert.deepEqual( + ( + await sql`select known_shas from github_push_observations where id=${pushClaim.id}` + )[0].known_shas, + push.commitShas + ); + await getDatabase().execute(query`select 1`); + process.stdout.write("daily history database checks passed\n"); +} finally { + await closeDatabase(); + await sql.end(); +} diff --git a/src/app/api/cron/codex-stats/route.ts b/src/app/api/cron/codex-stats/route.ts index 9a534d72..c3b4b2de 100644 --- a/src/app/api/cron/codex-stats/route.ts +++ b/src/app/api/cron/codex-stats/route.ts @@ -14,7 +14,9 @@ export async function POST(request: Request) { try { const result = await syncCodexAccounts(); - revalidateTag("public-codex-stats", { expire: 0 }); + if (result.updated > 0) { + revalidateTag("public-codex-stats", { expire: 0 }); + } return Response.json({ ok: true, result }); } catch (error) { const errorName = reportOperationalError("codex_stats", error); diff --git a/src/app/api/github/activity/route.ts b/src/app/api/github/activity/route.ts index cbe0dfbf..9dd63407 100644 --- a/src/app/api/github/activity/route.ts +++ b/src/app/api/github/activity/route.ts @@ -1,6 +1,5 @@ import { decodeGitHubActivityCursor } from "@/lib/github-activity-cursor"; import { getGitHubActivityPage } from "@/lib/github-activity-feed"; -import { GitHubActivityOrderingChangedError } from "@/lib/github-activity-store"; import { reportOperationalError } from "@/lib/operational-error"; export const dynamic = "force-dynamic"; @@ -30,12 +29,6 @@ export async function GET(request: Request) { headers: { "Cache-Control": "private, no-store" }, }); } catch (error) { - if (error instanceof GitHubActivityOrderingChangedError) { - return Response.json( - { ok: false }, - { headers: { "Cache-Control": "no-store" }, status: 409 } - ); - } reportOperationalError("github_activity_page", error); return Response.json( { ok: false }, diff --git a/src/components/github-activity-days.tsx b/src/components/github-activity-days.tsx index beacbec8..dfb9cf5e 100644 --- a/src/components/github-activity-days.tsx +++ b/src/components/github-activity-days.tsx @@ -17,10 +17,7 @@ import { TooltipTrigger, } from "@/components/site-tooltip"; import { dateKey, formatDate, WORK_LOG_TIME_ZONE } from "@/lib/date"; -import { - getVisibleGitHubActivityDays, - localizeGitHubActivityDays, -} from "@/lib/github-activity-feed-core"; +import { getVisibleGitHubActivityDays } from "@/lib/github-activity-feed-core"; import type { PublicGitHubActivityDay, PublicGitHubActivityItem, @@ -176,6 +173,17 @@ function WorkUnitRow({

{item.summary}

)} + {item.destination === null ? null : ( + + View on GitHub ↗ + + )} @@ -278,18 +286,6 @@ function GitHubActivityDay({ const workUnits = day.repositories .flatMap(({ items }) => items) .filter((item) => item.kind !== "issue-opened"); - const commitCount = workUnits.reduce( - (total, item) => total + item.facts.ownedCommitCount, - 0 - ); - const additions = workUnits.reduce( - (total, item) => total + item.facts.additions, - 0 - ); - const deletions = workUnits.reduce( - (total, item) => total + item.facts.deletions, - 0 - ); return (
@@ -303,24 +299,18 @@ function GitHubActivityDay({
-
Commits across repositories
+
Updates across repositories
- {countFormatter.format(commitCount)}{" "} - {commitCount === 1 ? "commit" : "commits"} across{" "} + {countFormatter.format(workUnits.length)}{" "} + {workUnits.length === 1 ? "update" : "updates"} across{" "} {countFormatter.format(repositoryCount)}{" "} {repositoryCount === 1 ? "repo" : "repos"}
-
-
Authored line churn
-
- -
-
    @@ -347,9 +337,8 @@ export function GitHubActivityDays({ preview?: boolean; now: string; }>) { - const localDays = localizeGitHubActivityDays(days, WORK_LOG_TIME_ZONE); const today = dateKey(now, WORK_LOG_TIME_ZONE); - const activeDays = getVisibleGitHubActivityDays(localDays, today); + const activeDays = getVisibleGitHubActivityDays(days, today); const visibleDays = preview ? activeDays.slice(0, 1) : activeDays; return ( diff --git a/src/components/github-timeline-pager.tsx b/src/components/github-timeline-pager.tsx index 05c68f22..24f1078a 100644 --- a/src/components/github-timeline-pager.tsx +++ b/src/components/github-timeline-pager.tsx @@ -31,11 +31,9 @@ export function GitHubTimelinePager({ preview: boolean; now: string; }>) { - const { orderingRevision } = initialPage; const { feedRevision, markLatestAvailable } = useGitHubActivityLive(); const [cursor, setCursor] = useState(initialPage.nextCursor); const [error, setError] = useState(false); - const [generationChanged, setGenerationChanged] = useState(false); const [isPending, startTransition] = useTransition(); const [pages, setPages] = useState([]); const [status, setStatus] = useState(""); @@ -52,11 +50,6 @@ export function GitHubTimelinePager({ const response = await fetch( `/api/github/activity?cursor=${encodeURIComponent(requestedCursor)}` ); - if (response.status === 409) { - setGenerationChanged(true); - markLatestAvailable(); - return; - } if (!response.ok) { throw new Error("The activity page could not be loaded."); } @@ -64,11 +57,6 @@ export function GitHubTimelinePager({ if (!validPage(page)) { throw new Error("The activity page was invalid."); } - if (page.orderingRevision !== orderingRevision) { - setGenerationChanged(true); - markLatestAvailable(); - return; - } if (page.head.feedRevision !== feedRevision) { markLatestAvailable(); } @@ -94,7 +82,7 @@ export function GitHubTimelinePager({ now={now} /> - {preview || cursor === null || generationChanged ? null : ( + {preview || cursor === null ? null : (