fix(api): 重构多市场日期解析并引入 upsert,彻底解决日期错位与重复写入问题

This commit is contained in:
2026-05-02 13:38:01 +08:00
parent 7ded5b7837
commit c243ba4f35
3 changed files with 60 additions and 52 deletions
+4 -2
View File
@@ -1,4 +1,4 @@
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric, uniqueIndex, date } from "drizzle-orm/pg-core";
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric, uniqueIndex, unique, date } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
@@ -86,11 +86,13 @@ export const assetPricesHistory = pgTable("asset_prices_history", {
.references(() => assets.id),
price: numeric("price", { precision: 36, scale: 18 }).notNull(),
date: date("date", { mode: "string" }).notNull(),
updateTime: timestamp("update_time", { withTimezone: true, mode: "date" })
.defaultNow(),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
.defaultNow()
.notNull(),
}, (table) => [
uniqueIndex("asset_price_date_idx").on(table.assetId, table.date),
unique().on(table.assetId, table.date),
]);
export const exchangeRatesHistory = pgTable("exchange_rates_history", {