import { sql } from "drizzle-orm"; import { boolean, index, jsonb, pgTable, text, timestamp, } from "drizzle-orm/pg-core"; import type { MigrationItemKind } from "./migrationItemRunTable.js"; export type MigrationItemEventStatus = "succeeded" | "skipped" | "failed"; export type MigrationItemPreview = { id?: string | null; name?: string | null; email?: string | null; }; export type MigrationItemEventResponse = Record | null; export const migrationItemEvents = pgTable( "migration_item_events", { migration_item_event_id: text().primaryKey().notNull(), timestamp: timestamp({ withTimezone: true }).notNull().default(sql`now()`), org_id: text().notNull(), env: text().notNull(), migration_internal_id: text().notNull(), migration_run_id: text().notNull(), dry_run: boolean().notNull(), item_kind: text().$type().notNull(), item_id: text().notNull(), item_preview: jsonb().$type(), status: text().$type().notNull(), response: jsonb().$type(), }, (table) => [ index("migration_item_events_lookup_idx").on( table.org_id, table.env, table.migration_internal_id, table.migration_run_id, table.item_kind, table.item_id, table.timestamp, ), index("migration_item_events_latest_idx").on( table.org_id, table.env, table.migration_internal_id, table.migration_run_id, table.timestamp, ), ], ); export type MigrationItemEvent = typeof migrationItemEvents.$inferSelect; export type MigrationItemEventInsert = typeof migrationItemEvents.$inferInsert;