mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-12 14:05:08 +10:00
chore(db): delete tautological schema-mirror tests, collapse db singleton
- Delete 4 test files (auth/resume/agent schema mirrors + relations type check) that re-assert Drizzle table/column names copied verbatim from the schema files. - Collapse makeDrizzleClient() + createDatabase() into a two-line module-level singleton; preserves globalThis.__drizzle caching behaviour. Claude-Session: https://claude.ai/code/session_012Bnvt1MghwHj4qQRxuQUGa
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user