Skip to content

Commit 0a5b99f

Browse files
authored
fix: ciBuildId ignores project scope (#91)
Closes Visual-Regression-Tracker/Visual-Regression-Tracker#183
1 parent 5b92f28 commit 0a5b99f

File tree

7 files changed

+219
-10
lines changed

7 files changed

+219
-10
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Migration `20210118201534-build--project-id---ci-build-id-constraint`
2+
3+
This migration has been generated by Pavel Strunkin at 1/18/2021, 10:15:34 PM.
4+
You can check out the [state of the schema](./schema.prisma) after the migration.
5+
6+
## Database Steps
7+
8+
```sql
9+
DROP INDEX "Build.ciBuildId_unique"
10+
11+
CREATE UNIQUE INDEX "Build.projectId_ciBuildId_unique" ON "Build"("projectId", "ciBuildId")
12+
```
13+
14+
## Changes
15+
16+
```diff
17+
diff --git schema.prisma schema.prisma
18+
migration 20201201211711-test-run--temp-ignore-areas-added..20210118201534-build--project-id---ci-build-id-constraint
19+
--- datamodel.dml
20+
+++ datamodel.dml
21+
@@ -1,17 +1,16 @@
22+
generator client {
23+
- provider = "prisma-client-js"
24+
- previewFeatures = ["atomicNumberOperations"]
25+
+ provider = "prisma-client-js"
26+
}
27+
datasource db {
28+
provider = "postgresql"
29+
- url = "***"
30+
+ url = "***"
31+
}
32+
model Build {
33+
id String @id @default(uuid())
34+
- ciBuildId String? @unique
35+
+ ciBuildId String?
36+
number Int?
37+
branchName String?
38+
status String?
39+
testRuns TestRun[]
40+
@@ -21,8 +20,10 @@
41+
createdAt DateTime @default(now())
42+
user User? @relation(fields: [userId], references: [id])
43+
userId String?
44+
isRunning Boolean?
45+
+
46+
+ @@unique([projectId, ciBuildId])
47+
}
48+
model Project {
49+
id String @id @default(uuid())
50+
```
51+
52+
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
generator client {
2+
provider = "prisma-client-js"
3+
}
4+
5+
datasource db {
6+
provider = "postgresql"
7+
url = "***"
8+
}
9+
10+
model Build {
11+
id String @id @default(uuid())
12+
ciBuildId String?
13+
number Int?
14+
branchName String?
15+
status String?
16+
testRuns TestRun[]
17+
projectId String
18+
project Project @relation(fields: [projectId], references: [id])
19+
updatedAt DateTime @updatedAt
20+
createdAt DateTime @default(now())
21+
user User? @relation(fields: [userId], references: [id])
22+
userId String?
23+
isRunning Boolean?
24+
25+
@@unique([projectId, ciBuildId])
26+
}
27+
28+
model Project {
29+
id String @id @default(uuid())
30+
name String
31+
mainBranchName String @default("master")
32+
builds Build[]
33+
buildsCounter Int @default(0)
34+
testVariations TestVariation[]
35+
updatedAt DateTime @updatedAt
36+
createdAt DateTime @default(now())
37+
38+
@@unique([name])
39+
}
40+
41+
model TestRun {
42+
id String @id @default(uuid())
43+
imageName String
44+
diffName String?
45+
diffPercent Float?
46+
diffTollerancePercent Float @default(0)
47+
pixelMisMatchCount Int?
48+
status TestStatus
49+
buildId String
50+
build Build @relation(fields: [buildId], references: [id])
51+
testVariationId String
52+
testVariation TestVariation @relation(fields: [testVariationId], references: [id])
53+
merge Boolean @default(false)
54+
updatedAt DateTime @updatedAt
55+
createdAt DateTime @default(now())
56+
// Test variation data
57+
name String @default("")
58+
browser String?
59+
device String?
60+
os String?
61+
viewport String?
62+
baselineName String?
63+
comment String?
64+
baseline Baseline?
65+
branchName String @default("master")
66+
baselineBranchName String?
67+
ignoreAreas String @default("[]")
68+
tempIgnoreAreas String @default("[]")
69+
}
70+
71+
model TestVariation {
72+
id String @id @default(uuid())
73+
name String
74+
branchName String @default("master")
75+
browser String?
76+
device String?
77+
os String?
78+
viewport String?
79+
baselineName String?
80+
ignoreAreas String @default("[]")
81+
projectId String
82+
project Project @relation(fields: [projectId], references: [id])
83+
testRuns TestRun[]
84+
baselines Baseline[]
85+
comment String?
86+
updatedAt DateTime @updatedAt
87+
createdAt DateTime @default(now())
88+
89+
@@unique([projectId, name, browser, device, os, viewport, branchName])
90+
}
91+
92+
model Baseline {
93+
id String @id @default(uuid())
94+
baselineName String
95+
testVariationId String
96+
testVariation TestVariation @relation(fields: [testVariationId], references: [id])
97+
testRunId String?
98+
testRun TestRun? @relation(fields: [testRunId], references: [id])
99+
updatedAt DateTime @updatedAt
100+
createdAt DateTime @default(now())
101+
}
102+
103+
model User {
104+
id String @id @default(uuid())
105+
email String @unique
106+
password String
107+
firstName String?
108+
lastName String?
109+
apiKey String @unique
110+
isActive Boolean @default(true)
111+
builds Build[]
112+
updatedAt DateTime @updatedAt
113+
createdAt DateTime @default(now())
114+
}
115+
116+
enum TestStatus {
117+
failed
118+
new
119+
ok
120+
unresolved
121+
approved
122+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"version": "0.3.14-fixed",
3+
"steps": [
4+
{
5+
"tag": "DeleteDirective",
6+
"location": {
7+
"path": {
8+
"tag": "Field",
9+
"model": "Build",
10+
"field": "ciBuildId"
11+
},
12+
"directive": "unique"
13+
}
14+
},
15+
{
16+
"tag": "CreateDirective",
17+
"location": {
18+
"path": {
19+
"tag": "Model",
20+
"model": "Build",
21+
"arguments": [
22+
{
23+
"name": "",
24+
"value": "[projectId, ciBuildId]"
25+
}
26+
]
27+
},
28+
"directive": "unique"
29+
}
30+
}
31+
]
32+
}

prisma/migrations/migrate.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
20200909223305-test-variation-project-id-added-into-unique-constraint
1212
20201007145002-builds-counter
1313
20201115155739-ci-build-id-added
14-
20201201211711-test-run--temp-ignore-areas-added
14+
20201201211711-test-run--temp-ignore-areas-added
15+
20210118201534-build--project-id---ci-build-id-constraint

prisma/schema.prisma

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ datasource db {
99

1010
model Build {
1111
id String @id @default(uuid())
12-
ciBuildId String? @unique
12+
ciBuildId String?
1313
number Int?
1414
branchName String?
1515
status String?
@@ -21,6 +21,8 @@ model Build {
2121
user User? @relation(fields: [userId], references: [id])
2222
userId String?
2323
isRunning Boolean?
24+
25+
@@unique([projectId, ciBuildId])
2426
}
2527

2628
model Project {

src/builds/builds.service.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ describe('BuildsService', () => {
215215
expect(projectFindOneMock).toHaveBeenCalledWith(createBuildDto.project);
216216
expect(buildFindUniqueMock).toHaveBeenCalledWith({
217217
where: {
218-
ciBuildId: createBuildDto.ciBuildId,
218+
projectId_ciBuildId: {
219+
projectId: project.id,
220+
ciBuildId: createBuildDto.ciBuildId,
221+
},
219222
},
220223
});
221224
expect(projectUpdateMock).toHaveBeenCalledWith({
@@ -254,12 +257,6 @@ describe('BuildsService', () => {
254257

255258
const result = await service.create(createBuildDto);
256259

257-
expect(projectFindOneMock).toHaveBeenCalledWith(createBuildDto.project);
258-
expect(buildFindUniqueMock).toHaveBeenCalledWith({
259-
where: {
260-
ciBuildId: createBuildDto.ciBuildId,
261-
},
262-
});
263260
expect(result).toBe(buildDto);
264261
});
265262
});

src/builds/builds.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ export class BuildsService {
5959
if (createBuildDto.ciBuildId) {
6060
build = await this.prismaService.build.findUnique({
6161
where: {
62-
ciBuildId: createBuildDto.ciBuildId,
62+
projectId_ciBuildId: {
63+
projectId: project.id,
64+
ciBuildId: createBuildDto.ciBuildId,
65+
},
6366
},
6467
});
6568
}

0 commit comments

Comments
 (0)