Skip to content

Commit

Permalink
Merge pull request #1503 from argos-ci/remove-validation-status
Browse files Browse the repository at this point in the history
refactor: remove `validationStatus` from screenshot_diffs table
  • Loading branch information
gregberge authored Jan 3, 2025
2 parents 1ecf42d + c6237db commit 606c276
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {import('knex').Knex} knex
*/
export const up = async (knex) => {
await knex.schema.alterTable("screenshot_diffs", async (table) => {
table.dropColumn("validationStatus");
});
};

/**
* @param {import('knex').Knex} knex
*/
export const down = async (knex) => {
await knex.schema.alterTable("screenshot_diffs", async (table) => {
table.string("validationStatus").notNullable();
});
};
4 changes: 2 additions & 2 deletions apps/backend/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@ CREATE TABLE public.screenshot_diffs (
"compareScreenshotId" bigint,
score numeric(10,5),
"jobStatus" public.job_status,
"validationStatus" character varying(255) NOT NULL,
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"s3Id" character varying(255),
Expand Down Expand Up @@ -3007,4 +3006,5 @@ INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('2024120
INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20241201222408_gitlab-last-loggedat.js', 1, NOW());
INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20241215091232_project-default-role.js', 1, NOW());
INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20241231154644_build-status.js', 1, NOW());
INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20250102150800_build-review.js', 1, NOW());
INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20250102150800_build-review.js', 1, NOW());
INSERT INTO public.knex_migrations(name, batch, migration_time) VALUES ('20250103090503_remove-validation-status-column.js', 1, NOW());
9 changes: 0 additions & 9 deletions apps/backend/src/build/createBuildDiffs.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,39 +158,34 @@ describe("#createBuildDiffs", () => {
baseScreenshotId: null,
compareScreenshotId: newScreenshot!.id,
jobStatus: "complete",
validationStatus: "unknown",
stabilityScore: null,
});
expect(addDiffWithoutFile).toMatchObject({
buildId: build.id,
baseScreenshotId: null,
compareScreenshotId: newScreenshotWithoutFile!.id,
jobStatus: "pending",
validationStatus: "unknown",
stabilityScore: null,
});
expect(updatedDiff).toMatchObject({
buildId: build.id,
baseScreenshotId: classicDiffBaseScreenshot!.id,
compareScreenshotId: classicDiffCompareScreenshot!.id,
jobStatus: "pending",
validationStatus: "unknown",
stabilityScore: null,
});
expect(removedDiff).toMatchObject({
buildId: build.id,
baseScreenshotId: removedScreenshot!.id,
compareScreenshotId: null,
jobStatus: "complete",
validationStatus: "unknown",
score: null,
});
expect(noFileBaseScreenshotDiff).toMatchObject({
buildId: build.id,
baseScreenshotId: noFileBaseScreenshotBase!.id,
compareScreenshotId: noFileBaseScreenshotCompare!.id,
jobStatus: "pending",
validationStatus: "unknown",
score: null,
stabilityScore: null,
});
Expand All @@ -199,7 +194,6 @@ describe("#createBuildDiffs", () => {
baseScreenshotId: noFileCompareScreenshotBase!.id,
compareScreenshotId: noFileCompareScreenshotCompare!.id,
jobStatus: "pending",
validationStatus: "unknown",
score: null,
stabilityScore: null,
});
Expand All @@ -208,7 +202,6 @@ describe("#createBuildDiffs", () => {
baseScreenshotId: sameFileScreenshotBase!.id,
compareScreenshotId: sameFileScreenshotCompare!.id,
jobStatus: "complete",
validationStatus: "unknown",
stabilityScore: null,
});
});
Expand Down Expand Up @@ -277,15 +270,13 @@ describe("#createBuildDiffs", () => {
baseScreenshotId: null,
compareScreenshotId: newScreenshot!.id,
jobStatus: "complete",
validationStatus: "unknown",
stabilityScore: null,
});
expect(diffs[1]).toMatchObject({
buildId: build.id,
baseScreenshotId: null,
compareScreenshotId: newScreenshotWithoutFile!.id,
jobStatus: "pending",
validationStatus: "unknown",
stabilityScore: null,
});
});
Expand Down
2 changes: 0 additions & 2 deletions apps/backend/src/build/createBuildDiffs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export async function createBuildDiffs(build: Build) {
compareScreenshot,
}),
score: sameFileId ? 0 : null,
validationStatus: "unknown" as const,
testId: compareScreenshot.testId,
};
});
Expand All @@ -173,7 +172,6 @@ export async function createBuildDiffs(build: Build) {
compareScreenshotId: null,
jobStatus: "complete" as const,
score: null,
validationStatus: "unknown" as const,
})) ?? [];

const allInserts = [...inserts, ...removedScreenshots];
Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/build/job.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ describe("build", () => {
const diffs = await ScreenshotDiff.query().where("buildId", build.id);
expect(diffs).toHaveLength(1);
expect(diffs[0]).toHaveProperty("jobStatus", "complete");
expect(diffs[0]).toHaveProperty("validationStatus", "unknown");
expect(diffs[0]).toHaveProperty("score", null);
expect(diffs[0]).toHaveProperty("s3Id", null);
});
Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/database/models/ScreenshotDiff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const baseData = {
baseScreenshotId: "1",
compareScreenshotId: "2",
jobStatus: "pending",
validationStatus: "unknown",
};

describe("models/ScreenshotDiff", () => {
Expand Down
12 changes: 1 addition & 11 deletions apps/backend/src/database/models/ScreenshotDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ export class ScreenshotDiff extends Model {
static override tableName = "screenshot_diffs";

static override jsonSchema = mergeSchemas(timestampsSchema, jobModelSchema, {
required: [
"buildId",
"baseScreenshotId",
"compareScreenshotId",
"validationStatus",
],
required: ["buildId", "baseScreenshotId", "compareScreenshotId"],
properties: {
buildId: { type: "string" },
baseScreenshotId: { type: ["string", "null"] },
Expand All @@ -32,10 +27,6 @@ export class ScreenshotDiff extends Model {
fileId: { type: ["string", "null"] },
score: { type: ["number", "null"], minimum: 0, maximum: 1 },
stabilityScore: { type: ["number", "null"], minimum: 0, maximum: 100 },
validationStatus: {
type: "string",
enum: ["unknown", "accepted", "rejected"],
},
testId: { type: ["string", "null"] },
group: { type: ["string", "null"] },
},
Expand All @@ -49,7 +40,6 @@ export class ScreenshotDiff extends Model {
score!: number | null;
stabilityScore!: number | null;
jobStatus!: JobStatus;
validationStatus!: "unknown" | "accepted" | "rejected";
testId!: string | null;
group!: string | null;

Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/database/seeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ export async function seed() {
compareScreenshotId: screenshots[1]!.id,
score: null,
jobStatus: "complete" as const,
validationStatus: "unknown" as const,
s3Id: "penelope-diff-transparent.png",
createdAt: now,
updatedAt: now,
Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/database/testing/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export const ScreenshotDiff = defineFactory(models.ScreenshotDiff, () => ({
baseScreenshotId: Screenshot.associate("id"),
compareScreenshotId: Screenshot.associate("id"),
jobStatus: "complete",
validationStatus: "unknown",
score: 0,
}));

Expand Down
16 changes: 4 additions & 12 deletions apps/backend/src/graphql/definitions/Build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import gqlTag from "graphql-tag";

import { pushBuildNotification } from "@/build-notification/index.js";
import { Build, BuildReview, ScreenshotDiff } from "@/database/models/index.js";
import { transaction } from "@/database/transaction.js";

import {
IBaseBranchResolution,
Expand Down Expand Up @@ -311,17 +310,10 @@ export const resolvers: IResolvers = {
throw forbidden("You cannot approve or reject this build");
}

await transaction(async (trx) => {
await Promise.all([
ScreenshotDiff.query(trx)
.where({ buildId })
.patch({ validationStatus }),
BuildReview.query(trx).insert({
buildId,
userId: auth.user.id,
state: validationStatus === "accepted" ? "approved" : "rejected",
}),
]);
await BuildReview.query().insert({
buildId,
userId: auth.user.id,
state: validationStatus === "accepted" ? "approved" : "rejected",
});

// That might be better suited into a $afterUpdate hook.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ describe("#computeScreenshotDiff", () => {
baseScreenshotId: baseScreenshot.id,
compareScreenshotId: compareScreenshot.id,
jobStatus: "pending",
validationStatus: "unknown",
testId: test.id,
});
});
Expand Down Expand Up @@ -153,7 +152,6 @@ describe("#computeScreenshotDiff", () => {
baseScreenshotId: baseScreenshot.id,
compareScreenshotId: compareScreenshot.id,
jobStatus: "pending",
validationStatus: "unknown",
});
});

Expand Down

0 comments on commit 606c276

Please sign in to comment.