Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat(backup): add the four stage models to MODEL_SPECS, INSERT_ORDER and the Zod schema, export stage-type status by value, drop Interview
Khuram Niaz854d3cffee0d
diff --git a/__tests__/backupExport.spec.ts b/__tests__/backupExport.spec.tsindex 3757df0..27676ee 100644--- a/__tests__/backupExport.spec.ts+++ b/__tests__/backupExport.spec.ts@@ -20,8 +20,10 @@ vi.mock("@/lib/db", () => {"company", "jobTitle", "location", "jobSource", "tag", "activityType","profile", "file", "resume", "contactInfo", "summary", "resumeSection","workExperience", "education", "licenseOrCertification", "otherSection",- "skill", "coverLetter", "automation", "job", "note", "interview",- "contact", "contactRole", "jobContact", "task", "activity", "question", "automationRun", "userSettings",+ "skill", "coverLetter", "automation", "job", "note",+ "contact", "contactRole", "jobContact", "jobStageType", "jobStage",+ "jobStageInterviewer", "jobStagePrepQuestion",+ "task", "activity", "question", "automationRun", "userSettings",]) {mock[key] = delegate();}@@ -115,6 +117,42 @@ describe("collectBackupData", () => {expect(data.Question[0]).not.toHaveProperty("tags");});+ // D3: a raw statusId points at nothing after a restore into a fresh database.+ it("replaces JobStageType.statusId with the status value and drops createdBy", async () => {+ mockDb.jobStageType.findMany.mockResolvedValueOnce([+ {+ id: "t1",+ label: "Final / Onsite Interview",+ value: "final / onsite interview",+ statusId: "status-row-1",+ Status: { value: "interview" },+ sortOrder: 6,+ createdBy: "user-1",+ },+ ]);++ const data = await collectBackupData("user-1");++ expect(data.JobStageType[0].statusValue).toBe("interview");+ expect(data.JobStageType[0]).not.toHaveProperty("statusId");+ expect(data.JobStageType[0]).not.toHaveProperty("Status");+ expect(data.JobStageType[0]).not.toHaveProperty("createdBy");+ });++ // A seeded Withdrawn stage type predates any withdrawn job, so scoping this+ // read to the user's jobs alone would leave its statusValue unresolvable.+ it("reads the statuses reached by a stage type as well as by a job", async () => {+ await collectBackupData("user-1");+ const call = (db as unknown as { jobStatus: { findMany: ReturnType<typeof vi.fn> } })+ .jobStatus.findMany.mock.calls[0][0];+ expect(call.where).toEqual({+ OR: [+ { jobs: { some: { userId: "user-1" } } },+ { stageTypes: { some: { createdBy: "user-1" } } },+ ],+ });+ });+it("carries the referenced job statuses as label/value pairs", async () => {(db as unknown as { jobStatus: { findMany: ReturnType<typeof vi.fn> } }).jobStatus.findMany.mockResolvedValueOnce([diff --git a/__tests__/backupImportGuards.spec.ts b/__tests__/backupImportGuards.spec.tsindex d63c800..b25992f 100644--- a/__tests__/backupImportGuards.spec.ts+++ b/__tests__/backupImportGuards.spec.ts@@ -30,8 +30,10 @@ vi.mock("@/lib/db", () => {"company", "jobTitle", "location", "jobSource", "tag", "activityType","profile", "file", "resume", "contactInfo", "summary", "resumeSection","workExperience", "education", "licenseOrCertification", "otherSection",- "skill", "coverLetter", "automation", "job", "note", "interview",- "contact", "contactRole", "jobContact", "task", "activity", "question", "userSettings",+ "skill", "coverLetter", "automation", "job", "note",+ "contact", "contactRole", "jobContact", "jobStageType", "jobStage",+ "jobStageInterviewer", "jobStagePrepQuestion",+ "task", "activity", "question", "userSettings","chatConversation",]) {mock[key] = counted();diff --git a/__tests__/backupOrdering.spec.ts b/__tests__/backupOrdering.spec.tsindex 6ddb3d5..272a4ce 100644--- a/__tests__/backupOrdering.spec.ts+++ b/__tests__/backupOrdering.spec.ts@@ -66,7 +66,6 @@ describe("backup ordering", () => {it("remaps both of Contact's company FKs, not just the current employer", () => {expect(MODEL_SPECS.Contact.fks).toEqual({- interviewId: "Interview",companyId: "Company",locationId: "Location",workedAtCompanyId: "Company",@@ -74,12 +73,13 @@ describe("backup ordering", () => {});});- it("marks exactly the seven lookup models, all owned by createdBy", () => {+ it("marks exactly the eight lookup models, all owned by createdBy", () => {expect([...LOOKUP_MODELS].sort()).toEqual(["ActivityType","Company","ContactRole","JobSource",+ "JobStageType","JobTitle","Location","Tag",@@ -107,11 +107,41 @@ describe("backup ordering", () => {expect(MODEL_SPECS.ContactInfo.scope("u1")).toEqual({resume: { profile: { userId: "u1" } },});- expect(MODEL_SPECS.Interview.scope("u1")).toEqual({ job: { userId: "u1" } });expect(MODEL_SPECS.AutomationRun.scope("u1")).toEqual({automation: { userId: "u1" },});});++ it("has dropped the vestigial Interview model entirely", () => {+ expect(MODEL_SPECS).not.toHaveProperty("Interview");+ expect(INSERT_ORDER).not.toContain("Interview" as BackupModel);+ expect(MODEL_SPECS.Contact.fks).not.toHaveProperty("interviewId");+ });++ // JobStageType is a lookup like ContactRole: without that flag a restore+ // into an account that already holds the seeded types would double them.+ it("treats JobStageType as a lookup and the rest as owned-through-Job", () => {+ expect(MODEL_SPECS.JobStageType.lookup).toBe(true);+ expect(LOOKUP_MODELS).toContain("JobStageType" as BackupModel);+ expect(MODEL_SPECS.JobStage.lookup).toBeUndefined();+ expect(MODEL_SPECS.JobStage.scope("u1")).toEqual({ Job: { userId: "u1" } });+ expect(MODEL_SPECS.JobStageInterviewer.scope("u1")).toEqual({+ Stage: { Job: { userId: "u1" } },+ });+ expect(MODEL_SPECS.JobStagePrepQuestion.scope("u1")).toEqual({+ Stage: { Job: { userId: "u1" } },+ });+ });++ it("inserts the stage models after Job, Contact and Question", () => {+ const at = (m: BackupModel) => INSERT_ORDER.indexOf(m);+ expect(at("JobStageType")).toBeLessThan(at("JobStage"));+ expect(at("Job")).toBeLessThan(at("JobStage"));+ expect(at("Contact")).toBeLessThan(at("JobStageInterviewer"));+ expect(at("Question")).toBeLessThan(at("JobStagePrepQuestion"));+ expect(at("JobStage")).toBeLessThan(at("JobStageInterviewer"));+ expect(at("JobStage")).toBeLessThan(at("JobStagePrepQuestion"));+ });});describe("emptiness models", () => {diff --git a/__tests__/backupSchema.spec.ts b/__tests__/backupSchema.spec.tsindex 9a20319..744e2a4 100644--- a/__tests__/backupSchema.spec.ts+++ b/__tests__/backupSchema.spec.ts@@ -102,3 +102,80 @@ describe("data schema", () => {expect(parsed.jobStatuses[0].value).toBe("new");});});++describe("stage groups", () => {+ // Zod strips unknown keys, so an older file carrying Interview and+ // interviewId still imports — which is right for a model with zero reads.+ it("silently drops a legacy Interview group and Contact.interviewId", () => {+ const parsed = BackupDataSchema.parse({+ Interview: [{ id: "i1", createdAt: "2026-01-01T00:00:00.000Z", jobId: "j1" }],+ Contact: [+ {+ id: "c1",+ name: "Pat",+ email: null,+ createdAt: "2026-01-01T00:00:00.000Z",+ interviewId: "i1",+ },+ ],+ });+ expect(parsed).not.toHaveProperty("Interview");+ expect(parsed.Contact[0]).not.toHaveProperty("interviewId");+ });++ it("defaults every stage group to an empty array", () => {+ const parsed = BackupDataSchema.parse({});+ expect(parsed.JobStageType).toEqual([]);+ expect(parsed.JobStage).toEqual([]);+ expect(parsed.JobStageInterviewer).toEqual([]);+ expect(parsed.JobStagePrepQuestion).toEqual([]);+ });++ // D3: JobStatus ids differ between installs, so the status crosses by name.+ it("carries a stage type's parent status by value, not by id", () => {+ const parsed = BackupDataSchema.parse({+ JobStageType: [+ {+ id: "t1",+ label: "Final / Onsite Interview",+ value: "final / onsite interview",+ statusValue: "interview",+ sortOrder: 6,+ },+ ],+ });+ expect(parsed.JobStageType[0].statusValue).toBe("interview");+ expect(parsed.JobStageType[0]).not.toHaveProperty("statusId");+ });++ it("rejects a stage type that carries no statusValue", () => {+ expect(() =>+ BackupDataSchema.parse({+ JobStageType: [{ id: "t1", label: "X", value: "x", sortOrder: 0 }],+ }),+ ).toThrow();+ });++ it("accepts a stage with a null occurredAt and a full stage alike", () => {+ const parsed = BackupDataSchema.parse({+ JobStage: [+ {+ id: "s1",+ jobId: "j1",+ stageTypeId: "t1",+ occurredAt: null,+ isCurrent: true,+ outcome: null,+ notes: null,+ durationMins: null,+ format: null,+ location: null,+ createdAt: "2026-01-01T00:00:00.000Z",+ updatedAt: "2026-01-01T00:00:00.000Z",+ },+ ],+ });+ expect(parsed.JobStage[0].occurredAt).toBeNull();+ expect(parsed.JobStage[0].isCurrent).toBe(true);+ });+});diff --git a/src/lib/backup/export.ts b/src/lib/backup/export.tsindex ebe00fb..0db3ea0 100644--- a/src/lib/backup/export.ts+++ b/src/lib/backup/export.ts@@ -9,12 +9,13 @@ import { isResumeFilePath } from "@/lib/resumeFiles";type Row = Record<string, unknown>;-// Job and Question need their tag ids, which are not columns; everything else-// reads as-is. Prisma's implicit m2m tables are not models, so this include is-// the only way the join rows reach the file at all.-const TAG_INCLUDE: Partial<Record<BackupModel, Record<string, unknown>>> = {+// Job and Question need their tag ids and JobStageType needs its status value;+// none of the three is a plain column. Prisma's implicit m2m tables are not+// models, so this include is the only way the join rows reach the file at all.+const ROW_INCLUDE: Partial<Record<BackupModel, Record<string, unknown>>> = {Job: { Status: { select: { value: true } }, tags: { select: { id: true } } },Question: { tags: { select: { id: true } } },+ JobStageType: { Status: { select: { value: true } } },};function stripOwnership(model: BackupModel, row: Row): Row {@@ -32,7 +33,7 @@ export async function collectBackupData(userId: string): Promise<BackupData> {const delegate = (db as unknown as Record<string, { findMany: (a: unknown) => Promise<Row[]> }>)[spec.delegate];- const include = TAG_INCLUDE[model];+ const include = ROW_INCLUDE[model];return delegate.findMany(include ? { where: spec.scope(userId), include } : { where: spec.scope(userId) },);@@ -49,7 +50,12 @@ export async function collectBackupData(userId: string): Promise<BackupData> {select: { defaultResumeId: true },}),db.jobStatus.findMany({- where: { jobs: { some: { userId } } },+ // Statuses reached by a job OR by a stage type: a seeded Withdrawn stage+ // type long predates any withdrawn job, and its statusValue has to+ // resolve on import.+ where: {+ OR: [{ jobs: { some: { userId } } }, { stageTypes: { some: { createdBy: userId } } }],+ },select: { label: true, value: true },}),];@@ -76,6 +82,13 @@ export async function collectBackupData(userId: string): Promise<BackupData> {return { ...rest, statusValue: Status.value };}+ if (model === "JobStageType") {+ const { statusId, Status, ...rest } = clean as Row & {+ Status: { value: string };+ };+ return { ...rest, statusValue: Status.value };+ }+if (model === "Question") {const { tags, ...rest } = clean as Row & { tags: { id: string }[] };for (const tag of tags ?? []) {diff --git a/src/lib/backup/idmap.ts b/src/lib/backup/idmap.tsindex f69019e..6c60144 100644--- a/src/lib/backup/idmap.ts+++ b/src/lib/backup/idmap.ts@@ -16,7 +16,6 @@ const OPTIONAL_FKS = new Set<string>(["Job.resumeId","Job.coverLetterId","Job.automationId",- "Contact.interviewId","Contact.companyId","Contact.locationId","Contact.workedAtCompanyId",diff --git a/src/lib/backup/ordering.ts b/src/lib/backup/ordering.tsindex c39709a..ff1e193 100644--- a/src/lib/backup/ordering.ts+++ b/src/lib/backup/ordering.ts@@ -24,10 +24,13 @@ export type BackupModel =| "Automation"| "Job"| "Note"- | "Interview"| "Contact"| "ContactRole"| "JobContact"+ | "JobStageType"+ | "JobStage"+ | "JobStageInterviewer"+ | "JobStagePrepQuestion"| "Task"| "Activity"| "Question"@@ -139,12 +142,10 @@ export const MODEL_SPECS: Record<BackupModel, ModelSpec> = {scope: byUser,},Note: { delegate: "note", owner: "userId", fks: { jobId: "Job" }, scope: byUser },- Interview: { delegate: "interview", fks: { jobId: "Job" }, scope: (userId) => ({ job: { userId } }) },Contact: {delegate: "contact",owner: "createdBy",fks: {- interviewId: "Interview",companyId: "Company",locationId: "Location",workedAtCompanyId: "Company",@@ -166,6 +167,32 @@ export const MODEL_SPECS: Record<BackupModel, ModelSpec> = {fks: { jobId: "Job", contactId: "Contact", roleId: "ContactRole" },scope: (userId) => ({ Job: { userId } }),},+ // A lookup like ContactRole, so a restore into an account that already holds+ // the seeded stage types does not double them. `fks` is empty on purpose:+ // JobStatus is global and never a BackupModel, so statusId crosses as a+ // natural key (D3), exactly as Job.statusId does.+ JobStageType: {+ delegate: "jobStageType",+ owner: "createdBy",+ lookup: true,+ fks: {},+ scope: byCreatedBy,+ },+ JobStage: {+ delegate: "jobStage",+ fks: { jobId: "Job", stageTypeId: "JobStageType" },+ scope: (userId) => ({ Job: { userId } }),+ },+ JobStageInterviewer: {+ delegate: "jobStageInterviewer",+ fks: { stageId: "JobStage", contactId: "Contact" },+ scope: (userId) => ({ Stage: { Job: { userId } } }),+ },+ JobStagePrepQuestion: {+ delegate: "jobStagePrepQuestion",+ fks: { stageId: "JobStage", questionId: "Question" },+ scope: (userId) => ({ Stage: { Job: { userId } } }),+ },Task: {delegate: "task",owner: "userId",@@ -210,12 +237,18 @@ export const INSERT_ORDER: BackupModel[] = ["Automation","Job","Note",- "Interview","Contact","JobContact",+ // Ahead of the stage models: JobStagePrepQuestion.questionId points here, and+ // its Restrict also means the reversed DELETE_ORDER has to clear prep rows+ // before questions.+ "Question",+ "JobStageType",+ "JobStage",+ "JobStageInterviewer",+ "JobStagePrepQuestion","Task","Activity",- "Question","AutomationRun","UserSettings",];diff --git a/src/lib/backup/schema.ts b/src/lib/backup/schema.tsindex fa6bb14..9bbb2f1 100644--- a/src/lib/backup/schema.ts+++ b/src/lib/backup/schema.ts@@ -20,6 +20,7 @@ const dt = z.coerce.date();const optDt = z.coerce.date().nullable();const int = z.number().int();const optInt = z.number().int().nullable();+const bool = z.boolean();// The watchlist columns are optional, not just nullable: a backup taken before// they existed has no such key, and undefined leaves Prisma on the default.@@ -223,9 +224,7 @@ const Note = z.object({updatedAt: dt,});-const Interview = z.object({ id, createdAt: dt, jobId: id });--// Everything past `interviewId` is `.optional()` as well as nullable: a backup+// Everything past `createdAt` is `.optional()` as well as nullable: a backup// taken before the contacts feature has no such key, and undefined leaves// Prisma on the column default.const Contact = z.object({@@ -233,7 +232,6 @@ const Contact = z.object({name: str,email: optStr,createdAt: dt,- interviewId: optId,title: optStr.optional(),phone: optStr.optional(),linkedinUrl: optStr.optional(),@@ -259,6 +257,47 @@ const JobContact = z.object({createdAt: dt,});+// statusValue, not statusId: JobStatus is global, never a BackupModel, and its+// ids differ between installs. Mirrors how Job crosses (D3).+const JobStageType = z.object({+ id,+ label: str,+ value: str,+ statusValue: str,+ sortOrder: int,+});++const JobStage = z.object({+ id,+ jobId: id,+ stageTypeId: id,+ occurredAt: optDt,+ isCurrent: bool,+ outcome: optStr,+ notes: optStr,+ durationMins: optInt,+ format: optStr,+ location: optStr,+ createdAt: dt,+ updatedAt: dt,+});++const JobStageInterviewer = z.object({+ id,+ stageId: id,+ contactId: id,+ createdAt: dt,+});++const JobStagePrepQuestion = z.object({+ id,+ stageId: id,+ questionId: id,+ asked: bool,+ askedAt: optDt,+ createdAt: dt,+});+const Task = z.object({id,title: str,@@ -346,9 +385,12 @@ export const BackupDataSchema = z.object({Automation: group(Automation),Job: group(Job),Note: group(Note),- Interview: group(Interview),Contact: group(Contact),JobContact: group(JobContact),+ JobStageType: group(JobStageType),+ JobStage: group(JobStage),+ JobStageInterviewer: group(JobStageInterviewer),+ JobStagePrepQuestion: group(JobStagePrepQuestion),Task: group(Task),Activity: group(Activity),Question: group(Question),