Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions packages/agent-directory/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ export {
AGENT_DEFINITION_ENTRY_PATH,
RetiredWorkflowEnvelopeError,
} from "./definition-asset";
export {
agentDirectoryMigrations,
applyAgentDirectoryMigrations,
type AgentDirectoryMigration,
type ApplyAgentDirectoryMigrationsReport,
} from "./migrations";
export {
CreateAgentDefinitionInput,
RestoreDefinitionInput,
Expand Down
111 changes: 0 additions & 111 deletions packages/agent-directory/src/migrations.ts

This file was deleted.

84 changes: 0 additions & 84 deletions packages/agent-directory/test/migrations.test.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/agent-directory/test/routes.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { generateKeyPair } from "@intx/crypto";
import type { RequireGrant, TenantEnv } from "@intx/hub-api";

import { dbTargetFromUrl } from "../../../scripts/db-setup";
import { applyAgentDirectoryMigrations } from "../src/migrations";
import { createAgentDefinitionRoutes } from "../src/routes";
import type { PinnedSkillIndexResolver } from "../src/routes";
import type { DefinitionAssetHistory } from "../src/definition-history";
Expand Down Expand Up @@ -158,8 +157,6 @@ describeIfDb("agent-directory routes against a real assetService", () => {
if (databaseUrl === undefined) {
throw new Error("DATABASE_URL is unset — describeIfDb should skip");
}
await applyAgentDirectoryMigrations(databaseUrl);

const handle = createDB(dbTargetFromUrl(databaseUrl));
db = handle.db;
close = handle.close;
Expand Down
2 changes: 1 addition & 1 deletion packages/cron/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export interface ApplyCronMigrationsReport {
/**
* Apply `cronMigrations` against `databaseUrl`, idempotently: a migration
* already recorded in this package's own ledger is skipped, never re-run.
* Mirrors `@corbits/inbox`'s `applyInboxMigrations` shape.
* Package-owned ledger, transactional apply.
*/
export async function applyCronMigrations(
databaseUrl: string,
Expand Down
7 changes: 1 addition & 6 deletions packages/inbox/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@ export {
createWorkbenchMailboxDelivery,
type CreateWorkbenchMailboxDeliveryOpts,
} from "./delivery";
export {
applyInboxMigrations,
applyMailboxMigrations,
type ApplyInboxMigrationsReport,
type ApplyMailboxMigrationsReport,
} from "./migrations";
export { applyMailboxMigrations, type ApplyMailboxMigrationsReport } from "./migrations";
117 changes: 4 additions & 113 deletions packages/inbox/src/migrations.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
// Two independent migration stories for `@corbits/inbox`:
//
// - `applyMailboxMigrations`: a URL-shaped wrapper around
// `@corbits/mailbox`'s own `runMailboxMigrations`, so scripts/db-setup.ts
// can apply it the same way it applies every other installed package's
// migrations. That package keeps its own ledger inside the `mailbox`
// schema.
// - `applyInboxMigrations`: this package's own product table history.
// CL-7208 added `inbox.snooze` for a snooze's `until` timestamp;
// CL-8185 drops it forward — snooze is gone per owner ruling.
// Bookkeeping uses its own ledger table, following the same pattern as
// the deleted `@workbench/onboarding`'s `migrations.ts`, so this package's migration
// history stays extractable on its own.

// A URL-shaped wrapper around `@corbits/mailbox`'s own
// `runMailboxMigrations`, so scripts/db-setup.ts can apply it the same
// way it applies every other installed package's migrations. That
// package keeps its own ledger inside the `mailbox` schema.
import { createMailboxDb, runMailboxMigrations } from "@corbits/mailbox";
import postgres from "postgres";

export interface ApplyMailboxMigrationsReport {
applied: string[];
Expand All @@ -39,101 +28,3 @@ export async function applyMailboxMigrations(
await close();
}
}

export interface InboxMigration {
name: string;
sql: string;
}

const SCHEMA = "inbox";
const LEDGER_TABLE = "inbox_migrations";

export const inboxMigrations: readonly InboxMigration[] = [
{
name: "0001_snooze",
sql: `
CREATE TABLE IF NOT EXISTS "inbox"."snooze" (
"tenant_id" text NOT NULL,
"principal_id" text NOT NULL,
"message_id" text NOT NULL,
"until" timestamptz NOT NULL,
PRIMARY KEY ("tenant_id", "principal_id", "message_id")
);
CREATE INDEX IF NOT EXISTS "inbox_snooze_until_idx" ON "inbox"."snooze" ("until");
`,
},
// CL-8185: snooze is dropped per owner ruling — no web UI ever grew an
// affordance for it, and the hub's own unsnooze sweep is deleted
// alongside this migration. Forward-drop, never a backfill: any row
// still here just meant an item was hidden until its `until` passed,
// which the row's own deletion (not its message) restores to visible.
{
name: "0002_drop_snooze",
sql: `DROP TABLE IF EXISTS "inbox"."snooze";`,
},
];

function quoteIdentifier(name: string): string {
return `"${name.replace(/"/g, '""')}"`;
}

function quoteQualified(schema: string, name: string): string {
return `${quoteIdentifier(schema)}.${quoteIdentifier(name)}`;
}

export interface ApplyInboxMigrationsReport {
applied: string[];
alreadyApplied: string[];
}

/**
* Apply `inboxMigrations` against `databaseUrl`, idempotently: a migration
* already recorded in the ledger is skipped, never re-run. Failures are
* loud — the migration name and the underlying error are both surfaced.
*/
export async function applyInboxMigrations(
databaseUrl: string,
): Promise<ApplyInboxMigrationsReport> {
const sql = postgres(databaseUrl, { max: 1, onnotice: () => undefined });
try {
await sql.unsafe(`CREATE SCHEMA IF NOT EXISTS ${quoteIdentifier(SCHEMA)}`);
await sql.unsafe(
`CREATE TABLE IF NOT EXISTS ${quoteQualified(SCHEMA, LEDGER_TABLE)} (` +
`name text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())`,
);

const applied: string[] = [];
const alreadyApplied: string[] = [];

for (const migration of inboxMigrations) {
const existing = await sql.unsafe(
`SELECT 1 FROM ${quoteQualified(SCHEMA, LEDGER_TABLE)} WHERE name = $1`,
[migration.name],
);
if (existing.length > 0) {
alreadyApplied.push(migration.name);
continue;
}
try {
await sql.begin(async (tx) => {
await tx.unsafe(migration.sql);
await tx.unsafe(
`INSERT INTO ${quoteQualified(SCHEMA, LEDGER_TABLE)} (name) VALUES ($1)`,
[migration.name],
);
});
applied.push(migration.name);
} catch (error) {
throw new Error(
`@corbits/inbox migration ${JSON.stringify(migration.name)} failed: ` +
`${error instanceof Error ? error.message : String(error)}`,
{ cause: error },
);
}
}

return { applied, alreadyApplied };
} finally {
await sql.end({ timeout: 5 });
}
}
Loading
Loading