fix(api): 重构多市场日期解析并引入 upsert,彻底解决日期错位与重复写入问题
This commit is contained in:
+4
-2
@@ -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", {
|
||||
|
||||
Reference in New Issue
Block a user