Skip to content

Commit f44dfcf

Browse files
committed
refactor(better-auth): improve field type normalization and migration logic
- Enhanced `normalizeBetterAuthFieldType` function for clearer type handling. - Updated `planMigration` function to use a more structured approach for determining field types. - Adjusted comments for better clarity on type normalization logic.
1 parent 358a798 commit f44dfcf

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

packages/better-auth/src/migrate.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import type { createRawFetch } from "./odata";
88
type BetterAuthSchema = Record<string, { fields: Record<string, DBFieldAttribute>; order: number }>;
99

1010
function normalizeBetterAuthFieldType(fieldType: unknown): string {
11-
if (typeof fieldType === "string") return fieldType;
12-
if (Array.isArray(fieldType)) return fieldType.map(String).join("|");
11+
if (typeof fieldType === "string") {
12+
return fieldType;
13+
}
14+
if (Array.isArray(fieldType)) {
15+
return fieldType.map(String).join("|");
16+
}
1317
return String(fieldType);
1418
}
1519

@@ -106,8 +110,12 @@ export async function planMigration(
106110
// Normalize it to a string so our FM mapping logic remains stable.
107111
// Use .includes() for all checks to handle array types like ["boolean", "null"] → "boolean|null"
108112
const t = normalizeBetterAuthFieldType(field.type);
109-
const type: "varchar" | "numeric" | "timestamp" =
110-
t.includes("boolean") || t.includes("number") ? "numeric" : t.includes("date") ? "timestamp" : "varchar";
113+
let type: "varchar" | "numeric" | "timestamp" = "varchar";
114+
if (t.includes("boolean") || t.includes("number")) {
115+
type = "numeric";
116+
} else if (t.includes("date")) {
117+
type = "timestamp";
118+
}
111119
return {
112120
name: field.fieldName ?? key,
113121
type,

packages/fmodata/tests/e2e/e2e.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import {
1616
} from "@proofkit/fmodata";
1717
import { afterEach, assert, describe, expect, expectTypeOf, it } from "vitest";
1818
import { z } from "zod/v4";
19-
import { apiKey, contacts, contactsTOWithIds, database, password, serverUrl, username, users } from "./setup";
2019
import { mockResponses } from "../fixtures/responses";
2120
import { jsonCodec } from "../utils/helpers";
2221
import { createMockFetch, simpleMock } from "../utils/mock-fetch";
22+
import { apiKey, contacts, contactsTOWithIds, database, password, serverUrl, username, users } from "./setup";
2323

2424
if (!serverUrl) {
2525
throw new Error("FMODATA_SERVER_URL environment variable is required");

packages/typegen/vitest.config.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { defineConfig } from "vitest/config";
77

88
export default defineConfig({
99
test: {
10-
testTimeout: 15_000, // 15 seconds for unit tests
11-
exclude: [
12-
"**/node_modules/**",
13-
"**/dist/**",
14-
"tests/e2e/**", // E2E tests require live FM server, run separately with test:e2e
15-
],
10+
testTimeout: 15_000, // 15 seconds, since we're making a network call to FM
11+
setupFiles: ["./tests/setupEnv.ts"], // Add setup file
12+
// Exclude E2E tests from default test runs
13+
// Run E2E tests with: pnpm test:e2e
14+
exclude: ["**/node_modules/**", "**/dist/**", "tests/e2e/**"],
1615
},
1716
});

scripts/ralph-once.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
claude --dangerously-skip-permissions "\
4-
1. Run 'bd ready' to find available work. \
4+
1. Run 'bv --robot-triage' to find available work. \
55
2. Pick ONE task and run 'bd update <id> --status=in_progress'. \
66
3. Run 'bd show <id>' to understand the task. \
77
4. Implement the task. \

0 commit comments

Comments
 (0)