feat(db): 新增 exchange_rates 汇率表,支持联合主键与基础交叉汇率数据
This commit is contained in:
+12
-1
@@ -1,4 +1,4 @@
|
||||
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric } from "drizzle-orm/pg-core";
|
||||
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric, uniqueIndex } from "drizzle-orm/pg-core";
|
||||
|
||||
export const users = pgTable("users", {
|
||||
id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
@@ -51,3 +51,14 @@ export const transactions = pgTable("transactions", {
|
||||
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
|
||||
.defaultNow(),
|
||||
});
|
||||
|
||||
export const exchangeRates = pgTable("exchange_rates", {
|
||||
id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
fromCurrency: varchar("from_currency", { length: 10 }).notNull(),
|
||||
toCurrency: varchar("to_currency", { length: 10 }).notNull(),
|
||||
rate: numeric("rate", { precision: 20, scale: 8 }).notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" })
|
||||
.defaultNow(),
|
||||
}, (table) => [
|
||||
uniqueIndex("currency_pair_idx").on(table.fromCurrency, table.toCurrency),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user