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
5 changes: 4 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ jobs:
uses: jakejarvis/wait-action@v0.1.0
with:
time: '5s'


- name: Apply Manual DB migrations
run: npx ts-node ./prisma/manual_migrations.ts

- name: Apply DB migrations
run: npx prisma migrate up -c --experimental

Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@types/cache-manager": "^2.10.3",
"@types/express": "^4.17.7",
"@types/jest": "26.0.14",
"@types/lodash": "^4.14.168",
"@types/node": "^14.0.27",
"@types/passport-jwt": "^3.0.3",
"@types/passport-local": "^1.0.33",
Expand Down
3 changes: 3 additions & 0 deletions prisma/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ set -e

echo Start applying migrations...

# apply manual migration
npx ts-node manual_migrations.ts

# apply migration
npx prisma migrate up -c --auto-approve --experimental

Expand Down
83 changes: 83 additions & 0 deletions prisma/manual_migrations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient({
// log: ['query'],
});

async function dbSchemaExists(): Promise<boolean> {
return prisma.$queryRaw`SELECT EXISTS
(
SELECT 1
FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name = '_Migration'
)`
.catch(() => false)
.then((result) => (result as Array<{ exists: boolean }>).shift()?.exists);
}

async function shouldSkipMigration(migrationKey: string): Promise<boolean> {
return prisma.$queryRaw`
SELECT revision, status from "public"."_Migration"
WHERE "name" like ${`%${migrationKey}%`}
AND "status" = 'MigrationSuccess'
LIMIT 1`.then((migration) => migration?.length > 0);
}

//https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker/issues/243
async function setEmptyTestVariationTags_github_243() {
const migrationKey = 'github_243';
if (await shouldSkipMigration(migrationKey)) {
console.info(`Skipping migration ${migrationKey}...`);
return;
}
console.info(`Going to apply migration ${migrationKey}...`);
const testVariations = await prisma.testVariation.findMany({
where: {
OR: [
{
os: null,
},
{
device: null,
},
{
browser: null,
},
{
viewport: null,
},
],
},
});

return Promise.all(
testVariations.map((testVariation) =>
prisma.testVariation.update({
where: { id: testVariation.id },
data: {
os: testVariation.os ?? '',
device: testVariation.device ?? '',
browser: testVariation.browser ?? '',
viewport: testVariation.viewport ?? '',
},
})
)
).then(() => console.info(`Finished migration ${migrationKey}`));
}

async function manualMigrations() {
await prisma.$connect();
if (await dbSchemaExists()) {
console.info('Apply migrations...');
await setEmptyTestVariationTags_github_243();
} else {
console.info('DB schema not found. Skipping manual migrations...');
}

await prisma.$disconnect();
}

manualMigrations()
.catch((e) => console.error('Cannot run manual migrations:', e))
.finally(async () => await prisma.$disconnect());
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Migration `20210405171118-github_243-set-empty-test-variation-tags-instead-of-null`

This migration has been generated by Pavel Strunkin at 4/5/2021, 8:11:18 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

```sql
ALTER TABLE "TestVariation" ALTER COLUMN "browser" SET NOT NULL,
ALTER COLUMN "browser" SET DEFAULT E'',
ALTER COLUMN "device" SET NOT NULL,
ALTER COLUMN "device" SET DEFAULT E'',
ALTER COLUMN "os" SET NOT NULL,
ALTER COLUMN "os" SET DEFAULT E'',
ALTER COLUMN "viewport" SET NOT NULL,
ALTER COLUMN "viewport" SET DEFAULT E''
```

## Changes

```diff
diff --git schema.prisma schema.prisma
migration 20210228121726-test-run--nullable-test-variation-id..20210405171118-github_243-set-empty-test-variation-tags-instead-of-null
--- datamodel.dml
+++ datamodel.dml
@@ -3,9 +3,9 @@
}
datasource db {
provider = "postgresql"
- url = "***"
+ url = "***"
}
model Build {
id String @id @default(uuid())
@@ -71,12 +71,12 @@
model TestVariation {
id String @id @default(uuid())
name String
branchName String @default("master")
- browser String?
- device String?
- os String?
- viewport String?
+ browser String @default("")
+ device String @default("")
+ os String @default("")
+ viewport String @default("")
baselineName String?
ignoreAreas String @default("[]")
projectId String
project Project @relation(fields: [projectId], references: [id])
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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 @default("")
device String @default("")
os String @default("")
viewport String @default("")
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
autoApproved
}
Loading