feat(db): 新增 portfolio_snapshots 表与每日快照记录 Action
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
CREATE TABLE "exchange_rates" (
|
||||
"id" uuid PRIMARY KEY NOT NULL,
|
||||
"from_currency" varchar(10) NOT NULL,
|
||||
"to_currency" varchar(10) NOT NULL,
|
||||
"rate" numeric(20, 8) NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "portfolio_snapshots" (
|
||||
"id" uuid PRIMARY KEY NOT NULL,
|
||||
"date" date NOT NULL,
|
||||
"total_value_cny" numeric(36, 18) NOT NULL,
|
||||
"total_cost_cny" numeric(36, 18) NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT "portfolio_snapshots_date_unique" UNIQUE("date")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "assets" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "users" ALTER COLUMN "id" DROP DEFAULT;--> statement-breakpoint
|
||||
ALTER TABLE "assets" ADD COLUMN "name" varchar(100);--> statement-breakpoint
|
||||
ALTER TABLE "assets" ADD COLUMN "exchange" varchar(10) DEFAULT 'US';--> statement-breakpoint
|
||||
ALTER TABLE "assets" ADD COLUMN "latest_price" numeric(36, 18) DEFAULT '0' NOT NULL;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "currency_pair_idx" ON "exchange_rates" USING btree ("from_currency","to_currency");
|
||||
@@ -0,0 +1,375 @@
|
||||
{
|
||||
"id": "26b392bf-03db-4f71-86d5-395d5c07fae5",
|
||||
"prevId": "18d8b1e1-2700-4d54-adf8-493d526d5bf5",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"tables": {
|
||||
"public.assets": {
|
||||
"name": "assets",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"symbol": {
|
||||
"name": "symbol",
|
||||
"type": "varchar(20)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "varchar(100)",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"type": {
|
||||
"name": "type",
|
||||
"type": "asset_type_enum",
|
||||
"typeSchema": "public",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"exchange": {
|
||||
"name": "exchange",
|
||||
"type": "varchar(10)",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "'US'"
|
||||
},
|
||||
"base_currency": {
|
||||
"name": "base_currency",
|
||||
"type": "varchar(10)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"latest_price": {
|
||||
"name": "latest_price",
|
||||
"type": "numeric(36, 18)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'0'"
|
||||
},
|
||||
"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.exchange_rates": {
|
||||
"name": "exchange_rates",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"from_currency": {
|
||||
"name": "from_currency",
|
||||
"type": "varchar(10)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"to_currency": {
|
||||
"name": "to_currency",
|
||||
"type": "varchar(10)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"rate": {
|
||||
"name": "rate",
|
||||
"type": "numeric(20, 8)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"currency_pair_idx": {
|
||||
"name": "currency_pair_idx",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "from_currency",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
},
|
||||
{
|
||||
"expression": "to_currency",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": true,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.portfolio_snapshots": {
|
||||
"name": "portfolio_snapshots",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"date": {
|
||||
"name": "date",
|
||||
"type": "date",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"total_value_cny": {
|
||||
"name": "total_value_cny",
|
||||
"type": "numeric(36, 18)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"total_cost_cny": {
|
||||
"name": "total_cost_cny",
|
||||
"type": "numeric(36, 18)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "now()"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {
|
||||
"portfolio_snapshots_date_unique": {
|
||||
"name": "portfolio_snapshots_date_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"date"
|
||||
]
|
||||
}
|
||||
},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.transactions": {
|
||||
"name": "transactions",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"asset_id": {
|
||||
"name": "asset_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"tx_type": {
|
||||
"name": "tx_type",
|
||||
"type": "transaction_type_enum",
|
||||
"typeSchema": "public",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"quantity": {
|
||||
"name": "quantity",
|
||||
"type": "numeric(36, 18)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"price": {
|
||||
"name": "price",
|
||||
"type": "numeric(36, 18)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"fee": {
|
||||
"name": "fee",
|
||||
"type": "numeric(36, 18)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'0'"
|
||||
},
|
||||
"tx_currency": {
|
||||
"name": "tx_currency",
|
||||
"type": "varchar(10)",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"exchange_rate": {
|
||||
"name": "exchange_rate",
|
||||
"type": "numeric(20, 8)",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'1'"
|
||||
},
|
||||
"executed_at": {
|
||||
"name": "executed_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"transactions_asset_id_assets_id_fk": {
|
||||
"name": "transactions_asset_id_assets_id_fk",
|
||||
"tableFrom": "transactions",
|
||||
"tableTo": "assets",
|
||||
"columnsFrom": [
|
||||
"asset_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
},
|
||||
"public.users": {
|
||||
"name": "users",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"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"
|
||||
]
|
||||
},
|
||||
"public.transaction_type_enum": {
|
||||
"name": "transaction_type_enum",
|
||||
"schema": "public",
|
||||
"values": [
|
||||
"BUY",
|
||||
"SELL",
|
||||
"DIVIDEND",
|
||||
"AIRDROP",
|
||||
"FEE"
|
||||
]
|
||||
}
|
||||
},
|
||||
"schemas": {},
|
||||
"sequences": {},
|
||||
"roles": {},
|
||||
"policies": {},
|
||||
"views": {},
|
||||
"_meta": {
|
||||
"columns": {},
|
||||
"schemas": {},
|
||||
"tables": {}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,13 @@
|
||||
"when": 1777289592183,
|
||||
"tag": "0002_rapid_invaders",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "7",
|
||||
"when": 1777433725731,
|
||||
"tag": "0003_watery_xorn",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user