Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Migration `20210118201534-build--project-id---ci-build-id-constraint`

This migration has been generated by Pavel Strunkin at 1/18/2021, 10:15:34 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

```sql
DROP INDEX "Build.ciBuildId_unique"

CREATE UNIQUE INDEX "Build.projectId_ciBuildId_unique" ON "Build"("projectId", "ciBuildId")
```

## Changes

```diff
diff --git schema.prisma schema.prisma
migration 20201201211711-test-run--temp-ignore-areas-added..20210118201534-build--project-id---ci-build-id-constraint
--- datamodel.dml
+++ datamodel.dml
@@ -1,17 +1,16 @@
generator client {
- provider = "prisma-client-js"
- previewFeatures = ["atomicNumberOperations"]
+ provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
- url = "***"
+ url = "***"
}
model Build {
id String @id @default(uuid())
- ciBuildId String? @unique
+ ciBuildId String?
number Int?
branchName String?
status String?
testRuns TestRun[]
@@ -21,8 +20,10 @@
createdAt DateTime @default(now())
user User? @relation(fields: [userId], references: [id])
userId String?
isRunning Boolean?
+
+ @@unique([projectId, ciBuildId])
}
model Project {
id String @id @default(uuid())
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = "***"
}

model Build {
id String @id @default(uuid())
ciBuildId String?
number Int?
branchName String?
status String?
testRuns TestRun[]
projectId String
project Project @relation(fields: [projectId], references: [id])
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
user User? @relation(fields: [userId], references: [id])
userId String?
isRunning Boolean?

@@unique([projectId, ciBuildId])
}

model Project {
id String @id @default(uuid())
name String
mainBranchName String @default("master")
builds Build[]
buildsCounter Int @default(0)
testVariations TestVariation[]
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())

@@unique([name])
}

model TestRun {
id String @id @default(uuid())
imageName String
diffName String?
diffPercent Float?
diffTollerancePercent Float @default(0)
pixelMisMatchCount Int?
status TestStatus
buildId String
build Build @relation(fields: [buildId], references: [id])
testVariationId String
testVariation TestVariation @relation(fields: [testVariationId], references: [id])
merge Boolean @default(false)
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
// Test variation data
name String @default("")
browser String?
device String?
os String?
viewport String?
baselineName String?
comment String?
baseline Baseline?
branchName String @default("master")
baselineBranchName String?
ignoreAreas String @default("[]")
tempIgnoreAreas String @default("[]")
}

model TestVariation {
id String @id @default(uuid())
name String
branchName String @default("master")
browser String?
device String?
os String?
viewport String?
baselineName String?
ignoreAreas String @default("[]")
projectId String
project Project @relation(fields: [projectId], references: [id])
testRuns TestRun[]
baselines Baseline[]
comment String?
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())

@@unique([projectId, name, browser, device, os, viewport, branchName])
}

model Baseline {
id String @id @default(uuid())
baselineName String
testVariationId String
testVariation TestVariation @relation(fields: [testVariationId], references: [id])
testRunId String?
testRun TestRun? @relation(fields: [testRunId], references: [id])
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
}

model User {
id String @id @default(uuid())
email String @unique
password String
firstName String?
lastName String?
apiKey String @unique
isActive Boolean @default(true)
builds Build[]
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
}

enum TestStatus {
failed
new
ok
unresolved
approved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "DeleteDirective",
"location": {
"path": {
"tag": "Field",
"model": "Build",
"field": "ciBuildId"
},
"directive": "unique"
}
},
{
"tag": "CreateDirective",
"location": {
"path": {
"tag": "Model",
"model": "Build",
"arguments": [
{
"name": "",
"value": "[projectId, ciBuildId]"
}
]
},
"directive": "unique"
}
}
]
}
3 changes: 2 additions & 1 deletion prisma/migrations/migrate.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
20200909223305-test-variation-project-id-added-into-unique-constraint
20201007145002-builds-counter
20201115155739-ci-build-id-added
20201201211711-test-run--temp-ignore-areas-added
20201201211711-test-run--temp-ignore-areas-added
20210118201534-build--project-id---ci-build-id-constraint
4 changes: 3 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ datasource db {

model Build {
id String @id @default(uuid())
ciBuildId String? @unique
ciBuildId String?
number Int?
branchName String?
status String?
Expand All @@ -21,6 +21,8 @@ model Build {
user User? @relation(fields: [userId], references: [id])
userId String?
isRunning Boolean?

@@unique([projectId, ciBuildId])
}

model Project {
Expand Down
11 changes: 4 additions & 7 deletions src/builds/builds.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ describe('BuildsService', () => {
expect(projectFindOneMock).toHaveBeenCalledWith(createBuildDto.project);
expect(buildFindUniqueMock).toHaveBeenCalledWith({
where: {
ciBuildId: createBuildDto.ciBuildId,
projectId_ciBuildId: {
projectId: project.id,
ciBuildId: createBuildDto.ciBuildId,
},
},
});
expect(projectUpdateMock).toHaveBeenCalledWith({
Expand Down Expand Up @@ -254,12 +257,6 @@ describe('BuildsService', () => {

const result = await service.create(createBuildDto);

expect(projectFindOneMock).toHaveBeenCalledWith(createBuildDto.project);
expect(buildFindUniqueMock).toHaveBeenCalledWith({
where: {
ciBuildId: createBuildDto.ciBuildId,
},
});
expect(result).toBe(buildDto);
});
});
Expand Down
5 changes: 4 additions & 1 deletion src/builds/builds.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export class BuildsService {
if (createBuildDto.ciBuildId) {
build = await this.prismaService.build.findUnique({
where: {
ciBuildId: createBuildDto.ciBuildId,
projectId_ciBuildId: {
projectId: project.id,
ciBuildId: createBuildDto.ciBuildId,
},
},
});
}
Expand Down