54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { pgTable, uuid, varchar, timestamp, pgEnum, numeric } from "drizzle-orm/pg-core";
|
|
|
|
export const users = pgTable("users", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
username: varchar("username", { length: 50 }).notNull().unique(),
|
|
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
|
createdAt: timestamp("created_at", { withTimezone: true, mode: "date" })
|
|
.defaultNow()
|
|
.notNull(),
|
|
});
|
|
|
|
export const assetTypeEnum = pgEnum("asset_type_enum", [
|
|
"STOCK",
|
|
"CRYPTO",
|
|
"CASH",
|
|
]);
|
|
|
|
export const assets = pgTable("assets", {
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
symbol: varchar("symbol", { length: 20 }).notNull().unique(),
|
|
type: assetTypeEnum("type").notNull(),
|
|
baseCurrency: varchar("base_currency", { length: 10 }).notNull(),
|
|
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(),
|
|
});
|