Files
loki/drizzle/0098_project_packages.sql
CatoandClaude Opus 5.5 064586c63b Packages: see what every project is built from (#1180)
* feat(packages): read what each project is built from

The fleet's shared-package catalogue is read from the fleet brief's one fetch
of bitbaum/fleet registers/packages.json (no second fetch; the snapshot now
carries the catalogue too). A new sync reads each project's package.json and
lockfile at its default-branch head through the existing GitHub token rules,
keeps the dependencies that are fleet packages (npm ranges, npm aliases, git
tags and shas, monorepo paths) and stores them as observations:

- project_packages: one row per (project, package) — spec, resolved version,
  source, commit, observed time
- project_package_scans: one row per project — last read, head sha,
  catalogue fingerprint, outcome — so an unchanged repo costs one request and
  a repo that could not be read keeps its rows and says why

POST /api/packages/sync reads all of the caller's projects (or one), four at
a time, never failing all for one. Latest versions come from npm or the
package repo's highest semver tag, cached, with a page deadline and the
register's version as a labelled fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M6u11m24oVkG98wAVbN7nf

* feat(packages): Packages pages and "Built from" on every project

- /packages (under Fleet): every fleet package with its latest version, how
  many of your projects use it and how many are behind; searchable
- /packages/[slug]: what it is, install command, repository, and your
  projects on it with version and status, behind first; an unlisted slug
  explains itself instead of 404ing
- Project Story tab: "Built from" lists the project's fleet packages with a
  behind badge linking to the package page
- Pages read the repositories again on arrival when the data is over six
  hours old; Refresh does it on demand; failed reads are named with a reason

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M6u11m24oVkG98wAVbN7nf

* docs(packages): changelog entry and the Packages view in CLAUDE.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M6u11m24oVkG98wAVbN7nf

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-14 01:57:07 -07:00

36 lines
2.4 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Migration: project_packages + project_package_scans — which fleet packages each
-- project is built from, as last read from its repository (src/lib/packages/sync.ts).
--
-- Generated by `pnpm run db:generate`, then trimmed to the two new tables: the
-- schema snapshot was last written at 0082, so drizzle-kit also re-emitted the
-- changes of the hand-written 0083–0097 (already applied). meta/0098_snapshot.json
-- is the full current schema, so the next `db:generate` diffs from here.
-- Create-only: no existing table is touched.
CREATE TABLE "project_package_scans" (
"project_id" uuid PRIMARY KEY NOT NULL,
"user_id" uuid NOT NULL,
"commit_sha" text,
"catalogue_key" text,
"outcome" text NOT NULL,
"detail" text,
"scanned_at" timestamp with time zone DEFAULT now() NOT NULL
);--> statement-breakpoint
CREATE TABLE "project_packages" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" uuid NOT NULL,
"project_id" uuid NOT NULL,
"package_name" text NOT NULL,
"spec" text NOT NULL,
"version" text,
"source" text NOT NULL,
"observed_at" timestamp with time zone DEFAULT now() NOT NULL,
"commit_sha" text
);--> statement-breakpoint
ALTER TABLE "project_package_scans" ADD CONSTRAINT "project_package_scans_project_id_user_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."user_projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project_package_scans" ADD CONSTRAINT "project_package_scans_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project_packages" ADD CONSTRAINT "project_packages_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "project_packages" ADD CONSTRAINT "project_packages_project_id_user_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."user_projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_project_package_scans_user" ON "project_package_scans" USING btree ("user_id","scanned_at");--> statement-breakpoint
CREATE UNIQUE INDEX "uq_project_packages_project_package" ON "project_packages" USING btree ("project_id","package_name");--> statement-breakpoint
CREATE INDEX "idx_project_packages_user_package" ON "project_packages" USING btree ("user_id","package_name");