@better-auth/cli 1.4.0-beta.4 → 1.4.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +37 -25
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -2277,9 +2277,9 @@ const generateDrizzleSchema = async ({
2277
2277
  mysql: field.bigint ? `bigint('${name}', { mode: 'number' })` : `int('${name}')`
2278
2278
  },
2279
2279
  date: {
2280
- sqlite: `integer('${name}', { mode: 'timestamp' })`,
2280
+ sqlite: `integer('${name}', { mode: 'timestamp_ms' })`,
2281
2281
  pg: `timestamp('${name}')`,
2282
- mysql: `timestamp('${name}')`
2282
+ mysql: `timestamp('${name}', { fsp: 3 })`
2283
2283
  },
2284
2284
  "number[]": {
2285
2285
  sqlite: `integer('${name}').array()`,
@@ -2307,7 +2307,7 @@ const generateDrizzleSchema = async ({
2307
2307
  if (databaseType === "pg") {
2308
2308
  id = `serial("id").primaryKey()`;
2309
2309
  } else if (databaseType === "sqlite") {
2310
- id = `int("id").primaryKey()`;
2310
+ id = `integer("id", { mode: "number" }).primaryKey({ autoIncrement: true })`;
2311
2311
  } else {
2312
2312
  id = `int("id").autoincrement().primaryKey()`;
2313
2313
  }
@@ -2327,11 +2327,16 @@ const generateDrizzleSchema = async ({
2327
2327
  id: ${id},
2328
2328
  ${Object.keys(fields).map((field) => {
2329
2329
  const attr = fields[field];
2330
- let type = getType(field, attr);
2330
+ const fieldName = attr.fieldName || field;
2331
+ let type = getType(fieldName, attr);
2331
2332
  if (attr.defaultValue !== null && typeof attr.defaultValue !== "undefined") {
2332
2333
  if (typeof attr.defaultValue === "function") {
2333
2334
  if (attr.type === "date" && attr.defaultValue.toString().includes("new Date()")) {
2334
- type += `.defaultNow()`;
2335
+ if (databaseType === "sqlite") {
2336
+ type += `.default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`)`;
2337
+ } else {
2338
+ type += `.defaultNow()`;
2339
+ }
2335
2340
  } else {
2336
2341
  type += `.$defaultFn(${attr.defaultValue})`;
2337
2342
  }
@@ -2346,10 +2351,10 @@ const generateDrizzleSchema = async ({
2346
2351
  type += `.$onUpdate(${attr.onUpdate})`;
2347
2352
  }
2348
2353
  }
2349
- return `${field}: ${type}${attr.required ? ".notNull()" : ""}${attr.unique ? ".unique()" : ""}${attr.references ? `.references(()=> ${getModelName(
2354
+ return `${fieldName}: ${type}${attr.required ? ".notNull()" : ""}${attr.unique ? ".unique()" : ""}${attr.references ? `.references(()=> ${getModelName(
2350
2355
  tables[attr.references.model]?.modelName || attr.references.model,
2351
2356
  adapter.options
2352
- )}.${attr.references.field}, { onDelete: '${attr.references.onDelete || "cascade"}' })` : ""}`;
2357
+ )}.${fields[attr.references.field]?.fieldName || attr.references.field}, { onDelete: '${attr.references.onDelete || "cascade"}' })` : ""}`;
2353
2358
  }).join(",\n ")}
2354
2359
  });`;
2355
2360
  code += `
@@ -2370,7 +2375,8 @@ function generateImport({
2370
2375
  tables,
2371
2376
  options
2372
2377
  }) {
2373
- let imports = [];
2378
+ const rootImports = [];
2379
+ const coreImports = [];
2374
2380
  let hasBigint = false;
2375
2381
  let hasJson = false;
2376
2382
  for (const table of Object.values(tables)) {
@@ -2381,12 +2387,14 @@ function generateImport({
2381
2387
  if (hasJson && hasBigint) break;
2382
2388
  }
2383
2389
  const useNumberId = options.advanced?.database?.useNumberId;
2384
- imports.push(`${databaseType}Table`);
2385
- imports.push(
2390
+ coreImports.push(`${databaseType}Table`);
2391
+ coreImports.push(
2386
2392
  databaseType === "mysql" ? "varchar, text" : databaseType === "pg" ? "text" : "text"
2387
2393
  );
2388
- imports.push(hasBigint ? databaseType !== "sqlite" ? "bigint" : "" : "");
2389
- imports.push(databaseType !== "sqlite" ? "timestamp, boolean" : "");
2394
+ coreImports.push(
2395
+ hasBigint ? databaseType !== "sqlite" ? "bigint" : "" : ""
2396
+ );
2397
+ coreImports.push(databaseType !== "sqlite" ? "timestamp, boolean" : "");
2390
2398
  if (databaseType === "mysql") {
2391
2399
  const hasNonBigintNumber = Object.values(tables).some(
2392
2400
  (table) => Object.values(table.fields).some(
@@ -2395,7 +2403,7 @@ function generateImport({
2395
2403
  );
2396
2404
  const needsInt = !!useNumberId || hasNonBigintNumber;
2397
2405
  if (needsInt) {
2398
- imports.push("int");
2406
+ coreImports.push("int");
2399
2407
  }
2400
2408
  } else if (databaseType === "pg") {
2401
2409
  const hasNonBigintNumber = Object.values(tables).some(
@@ -2410,17 +2418,26 @@ function generateImport({
2410
2418
  );
2411
2419
  const needsInteger = hasNonBigintNumber || options.advanced?.database?.useNumberId && hasFkToId;
2412
2420
  if (needsInteger) {
2413
- imports.push("integer");
2421
+ coreImports.push("integer");
2414
2422
  }
2415
2423
  } else {
2416
- imports.push("integer");
2424
+ coreImports.push("integer");
2417
2425
  }
2418
- imports.push(useNumberId ? databaseType === "pg" ? "serial" : "" : "");
2426
+ coreImports.push(useNumberId ? databaseType === "pg" ? "serial" : "" : "");
2419
2427
  if (hasJson) {
2420
- if (databaseType === "pg") imports.push("jsonb");
2421
- if (databaseType === "mysql") imports.push("json");
2428
+ if (databaseType === "pg") coreImports.push("jsonb");
2429
+ if (databaseType === "mysql") coreImports.push("json");
2422
2430
  }
2423
- return `import { ${imports.map((x) => x.trim()).filter((x) => x !== "").join(", ")} } from "drizzle-orm/${databaseType}-core";
2431
+ const hasSQLiteTimestamp = databaseType === "sqlite" && Object.values(tables).some(
2432
+ (table) => Object.values(table.fields).some(
2433
+ (field) => field.type === "date" && field.defaultValue && typeof field.defaultValue === "function" && field.defaultValue.toString().includes("new Date()")
2434
+ )
2435
+ );
2436
+ if (hasSQLiteTimestamp) {
2437
+ rootImports.push("sql");
2438
+ }
2439
+ return `${rootImports.length > 0 ? `import { ${rootImports.join(", ")} } from "drizzle-orm";
2440
+ ` : ""}import { ${coreImports.map((x) => x.trim()).filter((x) => x !== "").join(", ")} } from "drizzle-orm/${databaseType}-core";
2424
2441
  `;
2425
2442
  }
2426
2443
  function getModelName(modelName, options) {
@@ -2509,10 +2526,7 @@ const generatePrismaSchema = async ({
2509
2526
  builder.model(modelName).field("id", "String").attribute("id").attribute(`map("_id")`);
2510
2527
  } else {
2511
2528
  if (options.advanced?.database?.useNumberId) {
2512
- const col = builder.model(modelName).field("id", "Int").attribute("id");
2513
- if (provider !== "sqlite") {
2514
- col.attribute("default(autoincrement())");
2515
- }
2529
+ builder.model(modelName).field("id", "Int").attribute("id").attribute("default(autoincrement())");
2516
2530
  } else {
2517
2531
  builder.model(modelName).field("id", "String").attribute("id");
2518
2532
  }
@@ -2547,8 +2561,6 @@ const generatePrismaSchema = async ({
2547
2561
  if (provider === "mongodb") {
2548
2562
  fieldBuilder.attribute(`map("_id")`);
2549
2563
  }
2550
- } else if (fieldName !== field) {
2551
- fieldBuilder.attribute(`map("${field}")`);
2552
2564
  }
2553
2565
  if (attr.unique) {
2554
2566
  builder.model(modelName).blockAttribute(`unique([${fieldName}])`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/cli",
3
- "version": "1.4.0-beta.4",
3
+ "version": "1.4.0-beta.6",
4
4
  "description": "The CLI for Better Auth",
5
5
  "module": "dist/index.mjs",
6
6
  "repository": {
@@ -56,7 +56,7 @@
56
56
  "tinyexec": "^0.3.2",
57
57
  "yocto-spinner": "^0.2.3",
58
58
  "zod": "^4.1.5",
59
- "better-auth": "1.4.0-beta.4"
59
+ "better-auth": "1.4.0-beta.6"
60
60
  },
61
61
  "files": [
62
62
  "dist"