|
| 1 | +generator client { |
| 2 | + provider = "prisma-client-js" |
| 3 | +} |
| 4 | + |
| 5 | +datasource db { |
| 6 | + provider = "sqlite" |
| 7 | + url = env("DATABASE_URL") |
| 8 | +} |
| 9 | + |
| 10 | +// 当前一个工程中只有一个项目 |
| 11 | +model Project { |
| 12 | + id Int @id @default(autoincrement()) |
| 13 | + name String @unique |
| 14 | + description String? |
| 15 | + sum Int? |
| 16 | + charts Int @default(0) // 是否已经生成项目级别图表,0 未生成,1 已生成 |
| 17 | + more String? // json |
| 18 | + version String |
| 19 | + create_time String |
| 20 | + update_time String |
| 21 | +
|
| 22 | + Experiment Experiment[] |
| 23 | + Namespace Namespace[] |
| 24 | + Chart Chart[] |
| 25 | +
|
| 26 | + @@map("project") |
| 27 | +} |
| 28 | + |
| 29 | +model Experiment { |
| 30 | + id Int @id @default(autoincrement()) |
| 31 | + run_id String @unique |
| 32 | + name String |
| 33 | + description String? |
| 34 | + sort Int // >=0 |
| 35 | + status Int @default(0) // 实验状态 -1: crushed, 0: running, 1: finished |
| 36 | + show Int @default(0) // 实验可见性 0: 不可见,1: 可见 |
| 37 | + light String? |
| 38 | + dark String? |
| 39 | + more String? // json |
| 40 | + version String |
| 41 | + create_time String |
| 42 | + update_time String |
| 43 | +
|
| 44 | + project_id Int |
| 45 | + Project Project @relation(fields: [project_id], references: [id]) |
| 46 | + Namespace Namespace[] |
| 47 | + Chart Chart[] |
| 48 | + Tag Tag[] |
| 49 | +
|
| 50 | + @@unique([project_id, name]) |
| 51 | + @@unique([project_id, sort]) |
| 52 | + @@map("experiment") |
| 53 | +} |
| 54 | + |
| 55 | +// 一个实验/项目下可以有多个命名空间 |
| 56 | +model Namespace { |
| 57 | + id Int @id @default(autoincrement()) |
| 58 | + name String |
| 59 | + description String? |
| 60 | + sort Int // >=0, 索引越小,排序越靠前 |
| 61 | + more String // json |
| 62 | + create_time String |
| 63 | + update_time String |
| 64 | +
|
| 65 | + // 一个命名空间只能属于项目或实验 |
| 66 | + project_id Int? |
| 67 | + experiment_id Int? |
| 68 | + Project Project? @relation(fields: [project_id], references: [id]) |
| 69 | + Experiment Experiment? @relation(fields: [experiment_id], references: [id]) |
| 70 | + Display Display[] |
| 71 | +
|
| 72 | + @@unique([project_id, name]) |
| 73 | + @@unique([experiment_id, name]) |
| 74 | + @@map("namespace") |
| 75 | +} |
| 76 | + |
| 77 | +model Chart { |
| 78 | + id Int @id @default(autoincrement()) |
| 79 | + name String |
| 80 | + description String? |
| 81 | + system Int @default(1) // 是否为创建tag时自动生成的图表, -1: 删除的自动生成的图表; 0: 否; 1: 是; 系统图表不可删除,只能改为-1 |
| 82 | + type String // 由创建者决定 |
| 83 | + reference String @default("step") // 由创建者决定 |
| 84 | + config String? // json |
| 85 | + more String? // json |
| 86 | + create_time String |
| 87 | + update_time String |
| 88 | +
|
| 89 | + project_id Int? |
| 90 | + experiment_id Int? |
| 91 | + Project Project? @relation(fields: [project_id], references: [id]) |
| 92 | + Experiment Experiment? @relation(fields: [experiment_id], references: [id]) |
| 93 | + Display Display[] |
| 94 | + Source Source[] |
| 95 | +
|
| 96 | + @@unique([project_id, name]) |
| 97 | + @@unique([experiment_id, name]) |
| 98 | + @@map("chart") |
| 99 | +} |
| 100 | + |
| 101 | +// 中间表,namespace 和 chart,设计排序和排序可变 |
| 102 | +model Display { |
| 103 | + id Int @id @default(autoincrement()) |
| 104 | + sort Int // 索引越小,排序越靠前,索引>=0 |
| 105 | + more String? // json |
| 106 | + create_time String |
| 107 | + update_time String |
| 108 | +
|
| 109 | + namespace_id Int |
| 110 | + chart_id Int |
| 111 | + Namespace Namespace @relation(fields: [namespace_id], references: [id]) |
| 112 | + Chart Chart @relation(fields: [chart_id], references: [id]) |
| 113 | +
|
| 114 | + @@unique([namespace_id, chart_id]) |
| 115 | + @@map("display") |
| 116 | +} |
| 117 | + |
| 118 | +model Source { |
| 119 | + id Int @id @default(autoincrement()) |
| 120 | + sort Int @default(0) // 值越小越靠前 |
| 121 | + error String? // json |
| 122 | + more String? // json |
| 123 | + create_time String |
| 124 | + update_time String |
| 125 | +
|
| 126 | + chart_id Int |
| 127 | + Chart Chart @relation(fields: [chart_id], references: [id]) |
| 128 | + tag_id Int |
| 129 | + Tag Tag @relation(fields: [tag_id], references: [id]) |
| 130 | +
|
| 131 | + @@unique([chart_id, tag_id]) |
| 132 | + @@map("source") |
| 133 | +} |
| 134 | + |
| 135 | +// 与实验关联 |
| 136 | +model Tag { |
| 137 | + id Int @id @default(autoincrement()) |
| 138 | + name String @unique |
| 139 | + type String |
| 140 | + description String? |
| 141 | + system Int @default(0) // 0: 用户生成,1: 系统生成 |
| 142 | + more String? // json |
| 143 | + create_time String |
| 144 | + update_time String |
| 145 | +
|
| 146 | + experiment_id Int |
| 147 | + Experiment Experiment @relation(fields: [experiment_id], references: [id]) |
| 148 | + Source Source[] |
| 149 | +
|
| 150 | + @@unique([experiment_id, name]) |
| 151 | + @@map("tag") |
| 152 | +} |
0 commit comments