fix(db): 使用应用层 crypto.randomUUID 替代数据库默认生成,彻底解决主键 null 报错
This commit is contained in:
parent
7dbfd24cb1
commit
eba5a68495
@ -1,7 +1,7 @@
|
|||||||
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric } from "drizzle-orm/pg-core";
|
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric } from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
export const users = pgTable("users", {
|
export const users = pgTable("users", {
|
||||||
id: uuid("id").primaryKey().defaultRandom(),
|
id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||||
username: varchar("username", { length: 50 }).notNull().unique(),
|
username: varchar("username", { length: 50 }).notNull().unique(),
|
||||||
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||||
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
|
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
|
||||||
@ -16,7 +16,7 @@ export const assetTypeEnum = pgEnum("asset_type_enum", [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export const assets = pgTable("assets", {
|
export const assets = pgTable("assets", {
|
||||||
id: uuid("id").primaryKey().defaultRandom(),
|
id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||||
symbol: varchar("symbol", { length: 20 }).notNull().unique(),
|
symbol: varchar("symbol", { length: 20 }).notNull().unique(),
|
||||||
type: assetTypeEnum("type").notNull(),
|
type: assetTypeEnum("type").notNull(),
|
||||||
baseCurrency: varchar("base_currency", { length: 10 }).notNull(),
|
baseCurrency: varchar("base_currency", { length: 10 }).notNull(),
|
||||||
@ -33,7 +33,7 @@ export const transactionTypeEnum = pgEnum("transaction_type_enum", [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export const transactions = pgTable("transactions", {
|
export const transactions = pgTable("transactions", {
|
||||||
id: uuid("id").primaryKey().defaultRandom(),
|
id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||||
assetId: uuid("asset_id")
|
assetId: uuid("asset_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => assets.id),
|
.references(() => assets.id),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user