feat(db): 新增金融資產枚舉與核心資產表 (assets)
This commit is contained in:
parent
a592c18ba3
commit
e2ada5cb9d
9
drizzle/0001_brown_lucky_pierre.sql
Normal file
9
drizzle/0001_brown_lucky_pierre.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
CREATE TYPE "public"."asset_type_enum" AS ENUM('STOCK', 'CRYPTO', 'CASH');--> statement-breakpoint
|
||||||
|
CREATE TABLE "assets" (
|
||||||
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"symbol" varchar(20) NOT NULL,
|
||||||
|
"type" "asset_type_enum" NOT NULL,
|
||||||
|
"base_currency" varchar(10) NOT NULL,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now(),
|
||||||
|
CONSTRAINT "assets_symbol_unique" UNIQUE("symbol")
|
||||||
|
);
|
||||||
130
drizzle/meta/0001_snapshot.json
Normal file
130
drizzle/meta/0001_snapshot.json
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
{
|
||||||
|
"id": "efb1ef58-df53-4e36-b691-ee9811c3ab36",
|
||||||
|
"prevId": "1fc34e1e-d311-443f-bd56-87246c2025ea",
|
||||||
|
"version": "7",
|
||||||
|
"dialect": "postgresql",
|
||||||
|
"tables": {
|
||||||
|
"public.assets": {
|
||||||
|
"name": "assets",
|
||||||
|
"schema": "",
|
||||||
|
"columns": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"type": "uuid",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"default": "gen_random_uuid()"
|
||||||
|
},
|
||||||
|
"symbol": {
|
||||||
|
"name": "symbol",
|
||||||
|
"type": "varchar(20)",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"name": "type",
|
||||||
|
"type": "asset_type_enum",
|
||||||
|
"typeSchema": "public",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"base_currency": {
|
||||||
|
"name": "base_currency",
|
||||||
|
"type": "varchar(10)",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "timestamp with time zone",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"default": "now()"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {
|
||||||
|
"assets_symbol_unique": {
|
||||||
|
"name": "assets_symbol_unique",
|
||||||
|
"nullsNotDistinct": false,
|
||||||
|
"columns": [
|
||||||
|
"symbol"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"policies": {},
|
||||||
|
"checkConstraints": {},
|
||||||
|
"isRLSEnabled": false
|
||||||
|
},
|
||||||
|
"public.users": {
|
||||||
|
"name": "users",
|
||||||
|
"schema": "",
|
||||||
|
"columns": {
|
||||||
|
"id": {
|
||||||
|
"name": "id",
|
||||||
|
"type": "uuid",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"default": "gen_random_uuid()"
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"name": "username",
|
||||||
|
"type": "varchar(50)",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"password_hash": {
|
||||||
|
"name": "password_hash",
|
||||||
|
"type": "varchar(255)",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
|
"created_at": {
|
||||||
|
"name": "created_at",
|
||||||
|
"type": "timestamp with time zone",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"default": "now()"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {
|
||||||
|
"users_username_unique": {
|
||||||
|
"name": "users_username_unique",
|
||||||
|
"nullsNotDistinct": false,
|
||||||
|
"columns": [
|
||||||
|
"username"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"policies": {},
|
||||||
|
"checkConstraints": {},
|
||||||
|
"isRLSEnabled": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"enums": {
|
||||||
|
"public.asset_type_enum": {
|
||||||
|
"name": "asset_type_enum",
|
||||||
|
"schema": "public",
|
||||||
|
"values": [
|
||||||
|
"STOCK",
|
||||||
|
"CRYPTO",
|
||||||
|
"CASH"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"schemas": {},
|
||||||
|
"sequences": {},
|
||||||
|
"roles": {},
|
||||||
|
"policies": {},
|
||||||
|
"views": {},
|
||||||
|
"_meta": {
|
||||||
|
"columns": {},
|
||||||
|
"schemas": {},
|
||||||
|
"tables": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,6 +8,13 @@
|
|||||||
"when": 1777286818794,
|
"when": 1777286818794,
|
||||||
"tag": "0000_abandoned_titania",
|
"tag": "0000_abandoned_titania",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 1,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1777288158234,
|
||||||
|
"tag": "0001_brown_lucky_pierre",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { pgTable, uuid, varchar, timestamp } from "drizzle-orm/pg-core";
|
import { pgTable, uuid, varchar, timestamp, pgEnum } from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
export const users = pgTable("users", {
|
export const users = pgTable("users", {
|
||||||
id: uuid("id").primaryKey().defaultRandom(),
|
id: uuid("id").primaryKey().defaultRandom(),
|
||||||
@ -8,3 +8,18 @@ export const users = pgTable("users", {
|
|||||||
.defaultNow()
|
.defaultNow()
|
||||||
.notNull(),
|
.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(),
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user