Add agent config revisions, issue-approval links, and robust migration reconciliation
Add agent_config_revisions table for tracking agent configuration changes with rollback support. Add issue_approvals junction table linking issues to approvals. New migrations (0005, 0006) for permissions column and new tables. Rework migration client with statement-level idempotency checks (table/column/index/constraint existence) so migrations can be safely retried against partially-migrated databases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
28
packages/db/src/schema/agent_config_revisions.ts
Normal file
28
packages/db/src/schema/agent_config_revisions.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { pgTable, uuid, text, timestamp, jsonb, index } from "drizzle-orm/pg-core";
|
||||
import { companies } from "./companies.js";
|
||||
import { agents } from "./agents.js";
|
||||
|
||||
export const agentConfigRevisions = pgTable(
|
||||
"agent_config_revisions",
|
||||
{
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
companyId: uuid("company_id").notNull().references(() => companies.id),
|
||||
agentId: uuid("agent_id").notNull().references(() => agents.id, { onDelete: "cascade" }),
|
||||
createdByAgentId: uuid("created_by_agent_id").references(() => agents.id, { onDelete: "set null" }),
|
||||
createdByUserId: text("created_by_user_id"),
|
||||
source: text("source").notNull().default("patch"),
|
||||
rolledBackFromRevisionId: uuid("rolled_back_from_revision_id"),
|
||||
changedKeys: jsonb("changed_keys").$type<string[]>().notNull().default([]),
|
||||
beforeConfig: jsonb("before_config").$type<Record<string, unknown>>().notNull(),
|
||||
afterConfig: jsonb("after_config").$type<Record<string, unknown>>().notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => ({
|
||||
companyAgentCreatedIdx: index("agent_config_revisions_company_agent_created_idx").on(
|
||||
table.companyId,
|
||||
table.agentId,
|
||||
table.createdAt,
|
||||
),
|
||||
agentCreatedIdx: index("agent_config_revisions_agent_created_idx").on(table.agentId, table.createdAt),
|
||||
}),
|
||||
);
|
||||
@@ -1,11 +1,13 @@
|
||||
export { companies } from "./companies.js";
|
||||
export { agents } from "./agents.js";
|
||||
export { agentConfigRevisions } from "./agent_config_revisions.js";
|
||||
export { agentApiKeys } from "./agent_api_keys.js";
|
||||
export { agentRuntimeState } from "./agent_runtime_state.js";
|
||||
export { agentWakeupRequests } from "./agent_wakeup_requests.js";
|
||||
export { projects } from "./projects.js";
|
||||
export { goals } from "./goals.js";
|
||||
export { issues } from "./issues.js";
|
||||
export { issueApprovals } from "./issue_approvals.js";
|
||||
export { issueComments } from "./issue_comments.js";
|
||||
export { heartbeatRuns } from "./heartbeat_runs.js";
|
||||
export { heartbeatRunEvents } from "./heartbeat_run_events.js";
|
||||
|
||||
23
packages/db/src/schema/issue_approvals.ts
Normal file
23
packages/db/src/schema/issue_approvals.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { pgTable, uuid, text, timestamp, index, primaryKey } from "drizzle-orm/pg-core";
|
||||
import { companies } from "./companies.js";
|
||||
import { issues } from "./issues.js";
|
||||
import { approvals } from "./approvals.js";
|
||||
import { agents } from "./agents.js";
|
||||
|
||||
export const issueApprovals = pgTable(
|
||||
"issue_approvals",
|
||||
{
|
||||
companyId: uuid("company_id").notNull().references(() => companies.id),
|
||||
issueId: uuid("issue_id").notNull().references(() => issues.id, { onDelete: "cascade" }),
|
||||
approvalId: uuid("approval_id").notNull().references(() => approvals.id, { onDelete: "cascade" }),
|
||||
linkedByAgentId: uuid("linked_by_agent_id").references(() => agents.id, { onDelete: "set null" }),
|
||||
linkedByUserId: text("linked_by_user_id"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
(table) => ({
|
||||
pk: primaryKey({ columns: [table.issueId, table.approvalId], name: "issue_approvals_pk" }),
|
||||
issueIdx: index("issue_approvals_issue_idx").on(table.issueId),
|
||||
approvalIdx: index("issue_approvals_approval_idx").on(table.approvalId),
|
||||
companyIdx: index("issue_approvals_company_idx").on(table.companyId),
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user