feat(db): 新增交易流水表 (transactions) 并锁定极致金融精度
This commit is contained in:
+29
-1
@@ -1,4 +1,4 @@
|
||||
import { pgTable, uuid, varchar, timestamp, pgEnum } from "drizzle-orm/pg-core";
|
||||
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric } from "drizzle-orm/pg-core";
|
||||
|
||||
export const users = pgTable("users", {
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
@@ -23,3 +23,31 @@ export const assets = pgTable("assets", {
|
||||
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
|
||||
.defaultNow(),
|
||||
});
|
||||
|
||||
export const transactionTypeEnum = pgEnum("transaction_type_enum", [
|
||||
"BUY",
|
||||
"SELL",
|
||||
"DIVIDEND",
|
||||
"AIRDROP",
|
||||
"FEE",
|
||||
]);
|
||||
|
||||
export const transactions = pgTable("transactions", {
|
||||
id: uuid("id").primaryKey(),
|
||||
assetId: uuid("asset_id")
|
||||
.notNull()
|
||||
.references(() => assets.id),
|
||||
txType: transactionTypeEnum("tx_type").notNull(),
|
||||
quantity: numeric("quantity", { precision: 36, scale: 18 }).notNull(),
|
||||
price: numeric("price", { precision: 36, scale: 18 }).notNull(),
|
||||
fee: numeric("fee", { precision: 36, scale: 18 })
|
||||
.notNull()
|
||||
.default("0"),
|
||||
txCurrency: varchar("tx_currency", { length: 10 }).notNull(),
|
||||
exchangeRate: numeric("exchange_rate", { precision: 20, scale: 8 })
|
||||
.notNull()
|
||||
.default("1"),
|
||||
executedAt: timestamp("executed_at", { withTimezone: true }).notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
|
||||
.defaultNow(),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user