数据源修改

This commit is contained in:
cheney
2026-08-06 15:24:55 +08:00
parent b10b1c44db
commit ec15f40323
24 changed files with 2289 additions and 131 deletions
@@ -0,0 +1,24 @@
-- 经济指标: 明细数据拆到独立表, 兼容年/季/月/日频率
-- 第一步: 建 IndicatorPoint 表 + Indicator 加元数据列 (data 列暂保留, 由迁移脚本搬运后删除)
-- CreateTable
CREATE TABLE `IndicatorPoint` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`indicatorId` INTEGER NOT NULL,
`period` VARCHAR(191) NOT NULL,
`value` DOUBLE NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL,
UNIQUE INDEX `IndicatorPoint_indicatorId_period_key`(`indicatorId`, `period`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AlterTable: 元数据列 (data JSON 拆出)
ALTER TABLE `Indicator` ADD COLUMN `title` VARCHAR(191) NOT NULL DEFAULT '',
ADD COLUMN `unit` VARCHAR(191) NOT NULL DEFAULT '',
ADD COLUMN `source` VARCHAR(191) NOT NULL DEFAULT '',
ADD COLUMN `frequency` VARCHAR(191) NOT NULL DEFAULT 'month';
-- AddForeignKey
ALTER TABLE `IndicatorPoint` ADD CONSTRAINT `IndicatorPoint_indicatorId_fkey` FOREIGN KEY (`indicatorId`) REFERENCES `Indicator`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,3 @@
-- 第二步: 明细数据已迁移到 IndicatorPoint, 删除 Indicator.data JSON 列
-- AlterTable
ALTER TABLE `Indicator` DROP COLUMN `data`;
@@ -0,0 +1,2 @@
-- 指标隐藏标记: 数据与获取脚本保留, 前端展示过滤 hidden=true
ALTER TABLE `Indicator` ADD COLUMN `hidden` BOOLEAN NOT NULL DEFAULT false;
+24 -5
View File
@@ -41,12 +41,29 @@ model Strategy {
}
model Indicator {
id Int @id @default(autoincrement())
name String
id Int @id @default(autoincrement())
name String @unique
groupName String
data Json
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @default("")
unit String @default("")
source String @default("")
frequency String @default("month") // year | quarter | month | day
hidden Boolean @default(false) // true = 数据/脚本保留, 但不在前端展示
points IndicatorPoint[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model IndicatorPoint {
id Int @id @default(autoincrement())
indicatorId Int
indicator Indicator @relation(fields: [indicatorId], references: [id], onDelete: Cascade)
period String // "2024" | "2024-Q1" | "2024-01" | "2024-01-15"
value Float
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([indicatorId, period])
}
model Econ_SowInventory {
@@ -66,3 +83,5 @@ model ScraperCache {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}