fix(cli): timestamp in schema for Drizzle with SQLite (#4622)

This commit is contained in:
zy1p
2025-09-29 22:18:51 -04:00
committed by Alex Yang
parent 9907798400
commit 981458338d
5 changed files with 76 additions and 76 deletions

View File

@@ -104,7 +104,7 @@ export const generateDrizzleSchema: SchemaGenerator = async ({
: `int('${name}')`, : `int('${name}')`,
}, },
date: { date: {
sqlite: `integer('${name}', { mode: 'timestamp' })`, sqlite: `integer('${name}', { mode: 'timestamp_ms' })`,
pg: `timestamp('${name}')`, pg: `timestamp('${name}')`,
mysql: `timestamp('${name}')`, mysql: `timestamp('${name}')`,
}, },
@@ -170,7 +170,7 @@ export const generateDrizzleSchema: SchemaGenerator = async ({
attr.defaultValue.toString().includes("new Date()") attr.defaultValue.toString().includes("new Date()")
) { ) {
if (databaseType === "sqlite") { if (databaseType === "sqlite") {
type += `.default(sql\`(current_timestamp)\`)`; type += `.default(sql\`(cast(unixepoch('subsecond') * 1000 as integer))\`)`;
} else { } else {
type += `.defaultNow()`; type += `.defaultNow()`;
} }

View File

@@ -9,11 +9,11 @@ export const custom_user = sqliteTable("custom_user", {
.default(false) .default(false)
.notNull(), .notNull(),
image: text("image"), image: text("image"),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
twoFactorEnabled: integer("two_factor_enabled", { mode: "boolean" }).default( twoFactorEnabled: integer("two_factor_enabled", { mode: "boolean" }).default(
@@ -25,12 +25,12 @@ export const custom_user = sqliteTable("custom_user", {
export const custom_session = sqliteTable("custom_session", { export const custom_session = sqliteTable("custom_session", {
id: int("id").primaryKey(), id: int("id").primaryKey(),
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
token: text("token").notNull().unique(), token: text("token").notNull().unique(),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
ipAddress: text("ip_address"), ipAddress: text("ip_address"),
@@ -51,17 +51,17 @@ export const custom_account = sqliteTable("custom_account", {
refreshToken: text("refresh_token"), refreshToken: text("refresh_token"),
idToken: text("id_token"), idToken: text("id_token"),
accessTokenExpiresAt: integer("access_token_expires_at", { accessTokenExpiresAt: integer("access_token_expires_at", {
mode: "timestamp", mode: "timestamp_ms",
}), }),
refreshTokenExpiresAt: integer("refresh_token_expires_at", { refreshTokenExpiresAt: integer("refresh_token_expires_at", {
mode: "timestamp", mode: "timestamp_ms",
}), }),
scope: text("scope"), scope: text("scope"),
password: text("password"), password: text("password"),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });
@@ -70,12 +70,12 @@ export const custom_verification = sqliteTable("custom_verification", {
id: int("id").primaryKey(), id: int("id").primaryKey(),
identifier: text("identifier").notNull(), identifier: text("identifier").notNull(),
value: text("value").notNull(), value: text("value").notNull(),
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });

View File

@@ -9,23 +9,23 @@ export const custom_user = sqliteTable("custom_user", {
.default(false) .default(false)
.notNull(), .notNull(),
image: text("image"), image: text("image"),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });
export const custom_session = sqliteTable("custom_session", { export const custom_session = sqliteTable("custom_session", {
id: int("id").primaryKey(), id: int("id").primaryKey(),
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
token: text("token").notNull().unique(), token: text("token").notNull().unique(),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
ipAddress: text("ip_address"), ipAddress: text("ip_address"),
@@ -46,17 +46,17 @@ export const custom_account = sqliteTable("custom_account", {
refreshToken: text("refresh_token"), refreshToken: text("refresh_token"),
idToken: text("id_token"), idToken: text("id_token"),
accessTokenExpiresAt: integer("access_token_expires_at", { accessTokenExpiresAt: integer("access_token_expires_at", {
mode: "timestamp", mode: "timestamp_ms",
}), }),
refreshTokenExpiresAt: integer("refresh_token_expires_at", { refreshTokenExpiresAt: integer("refresh_token_expires_at", {
mode: "timestamp", mode: "timestamp_ms",
}), }),
scope: text("scope"), scope: text("scope"),
password: text("password"), password: text("password"),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });
@@ -65,12 +65,12 @@ export const custom_verification = sqliteTable("custom_verification", {
id: int("id").primaryKey(), id: int("id").primaryKey(),
identifier: text("identifier").notNull(), identifier: text("identifier").notNull(),
value: text("value").notNull(), value: text("value").notNull(),
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });
@@ -87,6 +87,6 @@ export const passkey = sqliteTable("passkey", {
deviceType: text("device_type").notNull(), deviceType: text("device_type").notNull(),
backedUp: integer("backed_up", { mode: "boolean" }).notNull(), backedUp: integer("backed_up", { mode: "boolean" }).notNull(),
transports: text("transports"), transports: text("transports"),
createdAt: integer("created_at", { mode: "timestamp" }), createdAt: integer("created_at", { mode: "timestamp_ms" }),
aaguid: text("aaguid"), aaguid: text("aaguid"),
}); });

View File

@@ -9,23 +9,23 @@ export const custom_user = sqliteTable("custom_user", {
.default(false) .default(false)
.notNull(), .notNull(),
image: text("image"), image: text("image"),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });
export const custom_session = sqliteTable("custom_session", { export const custom_session = sqliteTable("custom_session", {
id: text("id").primaryKey(), id: text("id").primaryKey(),
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
token: text("token").notNull().unique(), token: text("token").notNull().unique(),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
ipAddress: text("ip_address"), ipAddress: text("ip_address"),
@@ -46,17 +46,17 @@ export const custom_account = sqliteTable("custom_account", {
refreshToken: text("refresh_token"), refreshToken: text("refresh_token"),
idToken: text("id_token"), idToken: text("id_token"),
accessTokenExpiresAt: integer("access_token_expires_at", { accessTokenExpiresAt: integer("access_token_expires_at", {
mode: "timestamp", mode: "timestamp_ms",
}), }),
refreshTokenExpiresAt: integer("refresh_token_expires_at", { refreshTokenExpiresAt: integer("refresh_token_expires_at", {
mode: "timestamp", mode: "timestamp_ms",
}), }),
scope: text("scope"), scope: text("scope"),
password: text("password"), password: text("password"),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });
@@ -65,12 +65,12 @@ export const custom_verification = sqliteTable("custom_verification", {
id: text("id").primaryKey(), id: text("id").primaryKey(),
identifier: text("identifier").notNull(), identifier: text("identifier").notNull(),
value: text("value").notNull(), value: text("value").notNull(),
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });
@@ -87,6 +87,6 @@ export const passkey = sqliteTable("passkey", {
deviceType: text("device_type").notNull(), deviceType: text("device_type").notNull(),
backedUp: integer("backed_up", { mode: "boolean" }).notNull(), backedUp: integer("backed_up", { mode: "boolean" }).notNull(),
transports: text("transports"), transports: text("transports"),
createdAt: integer("created_at", { mode: "timestamp" }), createdAt: integer("created_at", { mode: "timestamp_ms" }),
aaguid: text("aaguid"), aaguid: text("aaguid"),
}); });

View File

@@ -9,11 +9,11 @@ export const custom_user = sqliteTable("custom_user", {
.default(false) .default(false)
.notNull(), .notNull(),
image: text("image"), image: text("image"),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
twoFactorEnabled: integer("two_factor_enabled", { mode: "boolean" }).default( twoFactorEnabled: integer("two_factor_enabled", { mode: "boolean" }).default(
@@ -25,12 +25,12 @@ export const custom_user = sqliteTable("custom_user", {
export const custom_session = sqliteTable("custom_session", { export const custom_session = sqliteTable("custom_session", {
id: text("id").primaryKey(), id: text("id").primaryKey(),
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
token: text("token").notNull().unique(), token: text("token").notNull().unique(),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
ipAddress: text("ip_address"), ipAddress: text("ip_address"),
@@ -51,17 +51,17 @@ export const custom_account = sqliteTable("custom_account", {
refreshToken: text("refresh_token"), refreshToken: text("refresh_token"),
idToken: text("id_token"), idToken: text("id_token"),
accessTokenExpiresAt: integer("access_token_expires_at", { accessTokenExpiresAt: integer("access_token_expires_at", {
mode: "timestamp", mode: "timestamp_ms",
}), }),
refreshTokenExpiresAt: integer("refresh_token_expires_at", { refreshTokenExpiresAt: integer("refresh_token_expires_at", {
mode: "timestamp", mode: "timestamp_ms",
}), }),
scope: text("scope"), scope: text("scope"),
password: text("password"), password: text("password"),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });
@@ -70,12 +70,12 @@ export const custom_verification = sqliteTable("custom_verification", {
id: text("id").primaryKey(), id: text("id").primaryKey(),
identifier: text("identifier").notNull(), identifier: text("identifier").notNull(),
value: text("value").notNull(), value: text("value").notNull(),
expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(), expiresAt: integer("expires_at", { mode: "timestamp_ms" }).notNull(),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.notNull(), .notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }) updatedAt: integer("updated_at", { mode: "timestamp_ms" })
.default(sql`(current_timestamp)`) .default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)
.$onUpdate(() => /* @__PURE__ */ new Date()) .$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(), .notNull(),
}); });