feat(db): 新增 portfolio_snapshots 表与每日快照记录 Action

This commit is contained in:
2026-04-29 11:37:11 +08:00
parent 955b01fd79
commit 4c4e6ab565
6 changed files with 525 additions and 1 deletions
+14 -1
View File
@@ -1,4 +1,4 @@
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric, uniqueIndex } from "drizzle-orm/pg-core";
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric, uniqueIndex, date } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
@@ -65,3 +65,16 @@ export const exchangeRates = pgTable("exchange_rates", {
}, (table) => [
uniqueIndex("currency_pair_idx").on(table.fromCurrency, table.toCurrency),
]);
export const portfolioSnapshots = pgTable("portfolio_snapshots", {
id: uuid("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
date: date("date", { mode: "string" }).notNull().unique(),
totalValueCny: numeric("total_value_cny", { precision: 36, scale: 18 }).notNull(),
totalCostCny: numeric("total_cost_cny", { precision: 36, scale: 18 }).notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
.defaultNow()
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: "date" })
.defaultNow()
.notNull(),
});