Skip to content

Commit f8e71b5

Browse files
authored
243 updated main vs feature compare (#118)
1 parent 109d3b0 commit f8e71b5

File tree

24 files changed

+824
-508
lines changed

24 files changed

+824
-508
lines changed

.github/workflows/workflow.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ jobs:
4040
uses: jakejarvis/[email protected]
4141
with:
4242
time: '5s'
43-
43+
44+
- name: Apply Manual DB migrations
45+
run: npx ts-node ./prisma/manual_migrations.ts
46+
4447
- name: Apply DB migrations
4548
run: npx prisma migrate up -c --experimental
4649

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@types/cache-manager": "^2.10.3",
5959
"@types/express": "^4.17.7",
6060
"@types/jest": "26.0.14",
61+
"@types/lodash": "^4.14.168",
6162
"@types/node": "^14.0.27",
6263
"@types/passport-jwt": "^3.0.3",
6364
"@types/passport-local": "^1.0.33",

prisma/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ set -e
55

66
echo Start applying migrations...
77

8+
# apply manual migration
9+
npx ts-node manual_migrations.ts
10+
811
# apply migration
912
npx prisma migrate up -c --auto-approve --experimental
1013

prisma/manual_migrations.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { PrismaClient } from '@prisma/client';
2+
3+
const prisma = new PrismaClient({
4+
// log: ['query'],
5+
});
6+
7+
async function dbSchemaExists(): Promise<boolean> {
8+
return prisma.$queryRaw`SELECT EXISTS
9+
(
10+
SELECT 1
11+
FROM information_schema.tables
12+
WHERE table_schema = 'public'
13+
AND table_name = '_Migration'
14+
)`
15+
.catch(() => false)
16+
.then((result) => (result as Array<{ exists: boolean }>).shift()?.exists);
17+
}
18+
19+
async function shouldSkipMigration(migrationKey: string): Promise<boolean> {
20+
return prisma.$queryRaw`
21+
SELECT revision, status from "public"."_Migration"
22+
WHERE "name" like ${`%${migrationKey}%`}
23+
AND "status" = 'MigrationSuccess'
24+
LIMIT 1`.then((migration) => migration?.length > 0);
25+
}
26+
27+
//https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker/issues/243
28+
async function setEmptyTestVariationTags_github_243() {
29+
const migrationKey = 'github_243';
30+
if (await shouldSkipMigration(migrationKey)) {
31+
console.info(`Skipping migration ${migrationKey}...`);
32+
return;
33+
}
34+
console.info(`Going to apply migration ${migrationKey}...`);
35+
const testVariations = await prisma.testVariation.findMany({
36+
where: {
37+
OR: [
38+
{
39+
os: null,
40+
},
41+
{
42+
device: null,
43+
},
44+
{
45+
browser: null,
46+
},
47+
{
48+
viewport: null,
49+
},
50+
],
51+
},
52+
});
53+
54+
return Promise.all(
55+
testVariations.map((testVariation) =>
56+
prisma.testVariation.update({
57+
where: { id: testVariation.id },
58+
data: {
59+
os: testVariation.os ?? '',
60+
device: testVariation.device ?? '',
61+
browser: testVariation.browser ?? '',
62+
viewport: testVariation.viewport ?? '',
63+
},
64+
})
65+
)
66+
).then(() => console.info(`Finished migration ${migrationKey}`));
67+
}
68+
69+
async function manualMigrations() {
70+
await prisma.$connect();
71+
if (await dbSchemaExists()) {
72+
console.info('Apply migrations...');
73+
await setEmptyTestVariationTags_github_243();
74+
} else {
75+
console.info('DB schema not found. Skipping manual migrations...');
76+
}
77+
78+
await prisma.$disconnect();
79+
}
80+
81+
manualMigrations()
82+
.catch((e) => console.error('Cannot run manual migrations:', e))
83+
.finally(async () => await prisma.$disconnect());
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Migration `20210405171118-github_243-set-empty-test-variation-tags-instead-of-null`
2+
3+
This migration has been generated by Pavel Strunkin at 4/5/2021, 8:11:18 PM.
4+
You can check out the [state of the schema](./schema.prisma) after the migration.
5+
6+
## Database Steps
7+
8+
```sql
9+
ALTER TABLE "TestVariation" ALTER COLUMN "browser" SET NOT NULL,
10+
ALTER COLUMN "browser" SET DEFAULT E'',
11+
ALTER COLUMN "device" SET NOT NULL,
12+
ALTER COLUMN "device" SET DEFAULT E'',
13+
ALTER COLUMN "os" SET NOT NULL,
14+
ALTER COLUMN "os" SET DEFAULT E'',
15+
ALTER COLUMN "viewport" SET NOT NULL,
16+
ALTER COLUMN "viewport" SET DEFAULT E''
17+
```
18+
19+
## Changes
20+
21+
```diff
22+
diff --git schema.prisma schema.prisma
23+
migration 20210228121726-test-run--nullable-test-variation-id..20210405171118-github_243-set-empty-test-variation-tags-instead-of-null
24+
--- datamodel.dml
25+
+++ datamodel.dml
26+
@@ -3,9 +3,9 @@
27+
}
28+
datasource db {
29+
provider = "postgresql"
30+
- url = "***"
31+
+ url = "***"
32+
}
33+
model Build {
34+
id String @id @default(uuid())
35+
@@ -71,12 +71,12 @@
36+
model TestVariation {
37+
id String @id @default(uuid())
38+
name String
39+
branchName String @default("master")
40+
- browser String?
41+
- device String?
42+
- os String?
43+
- viewport String?
44+
+ browser String @default("")
45+
+ device String @default("")
46+
+ os String @default("")
47+
+ viewport String @default("")
48+
baselineName String?
49+
ignoreAreas String @default("[]")
50+
projectId String
51+
project Project @relation(fields: [projectId], references: [id])
52+
```
53+
54+
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 @default("")
76+
device String @default("")
77+
os String @default("")
78+
viewport String @default("")
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+
autoApproved
123+
}

0 commit comments

Comments
 (0)