Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

chore(db): delete tautological schema-mirror tests, collapse db singleton

Amruth Pillai8de15822fb07
diff --git a/packages/db/src/client.ts b/packages/db/src/client.ts
index 607f5f7d6..591d4a719 100644
--- a/packages/db/src/client.ts
+++ b/packages/db/src/client.ts
@@ -30,15 +30,6 @@ export function getPool() {
return globalThis.__pool;
}
-function makeDrizzleClient() {
- return drizzle({ client: getPool(), relations });
-}
-
-function createDatabase() {
- if (!globalThis.__drizzle) {
- globalThis.__drizzle = makeDrizzleClient();
- }
- return globalThis.__drizzle;
-}
-
-export const db = createDatabase();
+// ponytail: two private fns collapsed; getPool() is already a singleton, global cache preserved
+globalThis.__drizzle ??= drizzle({ client: getPool(), relations });
+export const db = globalThis.__drizzle;
diff --git a/packages/db/src/relations.test.ts b/packages/db/src/relations.test.ts
deleted file mode 100644
index 074124123..000000000
--- a/packages/db/src/relations.test.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { describe, expect, it } from "vitest";
-import { relations } from "./relations";
-
-describe("drizzle relations", () => {
- it("exports a defined relations object", () => {
- expect(relations).toBeDefined();
- expect(typeof relations).toBe("object");
- });
-});
diff --git a/packages/db/src/schema/agent.test.ts b/packages/db/src/schema/agent.test.ts
deleted file mode 100644
index e5e7a1f2b..000000000
--- a/packages/db/src/schema/agent.test.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { describe, expect, it } from "vitest";
-import { getTableColumns, getTableName } from "drizzle-orm";
-import { agentAction, agentAttachment, agentMessage, agentThread, aiProvider } from "./agent";
-
-describe("aiProvider table definition", () => {
- it("is named ai_providers and stores encrypted credentials metadata", () => {
- expect(getTableName(aiProvider)).toBe("ai_providers");
-
- const columns = getTableColumns(aiProvider);
- for (const name of [
- "id",
- "userId",
- "label",
- "provider",
- "model",
- "baseUrl",
- "encryptedApiKey",
- "apiKeySalt",
- "apiKeyHash",
- "apiKeyPreview",
- "testStatus",
- "lastTestedAt",
- "lastUsedAt",
- "enabled",
- "createdAt",
- "updatedAt",
- ]) {
- expect(columns[name as keyof typeof columns], name).toBeDefined();
- }
- });
-});
-
-describe("agent workspace table definitions", () => {
- it("declares threads, messages, attachments, and actions", () => {
- expect(getTableName(agentThread)).toBe("agent_threads");
- expect(getTableName(agentMessage)).toBe("agent_messages");
- expect(getTableName(agentAttachment)).toBe("agent_attachments");
- expect(getTableName(agentAction)).toBe("agent_actions");
-
- expect(getTableColumns(agentThread).workingResumeId).toBeDefined();
- expect(getTableColumns(agentThread).lastMessageAt).toBeDefined();
- expect(getTableColumns(agentMessage).uiMessage).toBeDefined();
- expect(getTableColumns(agentAttachment).storageKey).toBeDefined();
- expect(getTableColumns(agentAction).snapshotData).toBeDefined();
- expect("inverseOperations" in getTableColumns(agentAction)).toBe(false);
- });
-});
diff --git a/packages/db/src/schema/auth.test.ts b/packages/db/src/schema/auth.test.ts
deleted file mode 100644
index 4a5244418..000000000
--- a/packages/db/src/schema/auth.test.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-import { describe, expect, it } from "vitest";
-import { getTableColumns, getTableName } from "drizzle-orm";
-import {
- account,
- apikey,
- jwks,
- oauthAccessToken,
- oauthClient,
- oauthConsent,
- oauthRefreshToken,
- passkey,
- session,
- twoFactor,
- user,
- verification,
-} from "./auth";
-
-const cases: Array<{
- name: string;
- table: Parameters<typeof getTableColumns>[0];
- columns: string[];
-}> = [
- {
- name: "user",
- table: user,
- columns: ["id", "email", "name", "image", "createdAt", "updatedAt"],
- },
- {
- name: "session",
- table: session,
- columns: ["id", "userId", "token", "expiresAt"],
- },
- {
- name: "account",
- table: account,
- columns: ["id", "userId", "providerId", "accountId"],
- },
- {
- name: "verification",
- table: verification,
- columns: ["id", "identifier", "value", "expiresAt"],
- },
- {
- name: "two_factor",
- table: twoFactor,
- columns: ["id", "userId", "secret"],
- },
- {
- name: "passkey",
- table: passkey,
- columns: ["id", "userId", "publicKey"],
- },
- {
- name: "apikey",
- table: apikey,
- columns: ["id", "name", "key", "referenceId"],
- },
- { name: "jwks", table: jwks, columns: ["id", "publicKey", "privateKey"] },
- {
- name: "oauth_client",
- table: oauthClient,
- columns: ["id", "clientId", "clientSecret", "name", "userId", "redirectUris"],
- },
- {
- name: "oauth_refresh_token",
- table: oauthRefreshToken,
- columns: ["id", "userId", "clientId"],
- },
- {
- name: "oauth_access_token",
- table: oauthAccessToken,
- columns: ["id", "userId", "clientId", "refreshId"],
- },
- {
- name: "oauth_consent",
- table: oauthConsent,
- columns: ["id", "userId", "clientId"],
- },
-];
-
-describe("auth tables", () => {
- it.each(cases)("$name maps to the expected SQL name", ({ name, table }) => {
- expect(getTableName(table)).toBe(name);
- });
-
- it.each(cases)("$name exposes the required columns", ({ table, columns }) => {
- const tableColumns = getTableColumns(table);
- for (const expected of columns) {
- expect(tableColumns[expected as keyof typeof tableColumns], expected).toBeDefined();
- }
- });
-});
diff --git a/packages/db/src/schema/resume.test.ts b/packages/db/src/schema/resume.test.ts
deleted file mode 100644
index c76d94e08..000000000
--- a/packages/db/src/schema/resume.test.ts
+++ /dev/null
@@ -1,63 +0,0 @@
-import { describe, expect, it } from "vitest";
-import { getTableColumns, getTableName } from "drizzle-orm";
-import { defaultResumeData } from "@reactive-resume/schema/resume/default";
-import { resume, resumeAnalysis, resumeStatistics } from "./resume";
-
-describe("resume table definition", () => {
- it("is named 'resume' in the database", () => {
- expect(getTableName(resume)).toBe("resume");
- });
-
- it("declares the expected columns", () => {
- const columns = getTableColumns(resume);
- for (const name of [
- "id",
- "name",
- "slug",
- "tags",
- "isPublic",
- "isLocked",
- "password",
- "data",
- "userId",
- "createdAt",
- "updatedAt",
- ]) {
- expect(columns[name as keyof typeof columns], name).toBeDefined();
- }
- });
-
- it("data column defaults to defaultResumeData when invoked", () => {
- const columns = getTableColumns(resume);
- // drizzle exposes the default function under `default` or via column config — the
- // most stable way to assert intent is to make sure `data` has a default at all.
- expect(columns.data).toBeDefined();
- // Roundtrip the imported default to make sure the import wiring works.
- expect(defaultResumeData.basics).toBeDefined();
- });
-});
-
-describe("resumeStatistics table definition", () => {
- it("is named 'resume_statistics' in the database", () => {
- expect(getTableName(resumeStatistics)).toBe("resume_statistics");
- });
-
- it("exposes counter columns and a unique resume_id FK", () => {
- const columns = getTableColumns(resumeStatistics);
- for (const name of ["views", "downloads", "lastViewedAt", "lastDownloadedAt", "resumeId"]) {
- expect(columns[name as keyof typeof columns], name).toBeDefined();
- }
- });
-});
-
-describe("resumeAnalysis table definition", () => {
- it("is named 'resume_analysis' in the database", () => {
- expect(getTableName(resumeAnalysis)).toBe("resume_analysis");
- });
-
- it("declares analysis + resumeId columns", () => {
- const columns = getTableColumns(resumeAnalysis);
- expect(columns.analysis).toBeDefined();
- expect(columns.resumeId).toBeDefined();
- });
-});