Skip to content

Commit feab48e

Browse files
committed
chore: use models to generate seeds
1 parent e308a2f commit feab48e

File tree

10 files changed

+520
-579
lines changed

10 files changed

+520
-579
lines changed

apps/backend/db/seeds/seeds.js

Lines changed: 0 additions & 546 deletions
This file was deleted.

apps/backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"db:drop": "knex-scripts drop",
1616
"db:dump": "pnpm run db:migrate:latest && knex-scripts dump",
1717
"db:load": "knex-scripts load",
18-
"db:seed": "knex seed:run",
18+
"db:seed": "node dist/database/bin/run-seed.js",
1919
"db:truncate": "knex-scripts truncate",
2020
"db:migrate:latest": "knex migrate:latest",
2121
"db:migrate:rollback": "knex migrate:rollback",

apps/backend/src/build/concludeBuild.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,26 @@ export async function concludeBuild(input: {
2525
if (conclusion === null) {
2626
return;
2727
}
28-
const [, buildNotification] = await transaction(async (trx) => {
29-
return Promise.all([
30-
Build.query(trx).findById(buildId).patch({
31-
conclusion,
32-
stats,
33-
}),
34-
notify
35-
? BuildNotification.query(trx).insert({
36-
buildId,
37-
type: getNotificationType(conclusion),
38-
jobStatus: "pending",
39-
})
40-
: null,
41-
]);
42-
});
43-
if (buildNotification) {
28+
if (notify) {
29+
const [, buildNotification] = await transaction(async (trx) => {
30+
return Promise.all([
31+
Build.query(trx).findById(buildId).patch({
32+
conclusion,
33+
stats,
34+
}),
35+
BuildNotification.query(trx).insert({
36+
buildId,
37+
type: getNotificationType(conclusion),
38+
jobStatus: "pending",
39+
}),
40+
]);
41+
});
4442
await buildNotificationJob.push(buildNotification.id);
43+
} else {
44+
await Build.query().findById(buildId).patch({
45+
conclusion,
46+
stats,
47+
});
4548
}
4649
}
4750

apps/backend/src/config/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,6 @@ const config = convict({
286286
default: join(__dirname, "../../db/migrations"),
287287
},
288288
},
289-
seeds: {
290-
directory: {
291-
doc: "Seeds directory",
292-
format: String,
293-
default: join(__dirname, "../../db/seeds"),
294-
},
295-
},
296289
client: {
297290
doc: "Knex client",
298291
format: String,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { seed } from "../seeds";
2+
3+
await seed();
4+
console.log("Seeding complete");
5+
process.exit(0);

apps/backend/src/database/models/Build.e2e.test.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ describe("models/Build", () => {
143143
describe("with complete job", () => {
144144
describe("and one in error screenshot diff", () => {
145145
it("should be error", async () => {
146-
build = await factory.Build.create();
146+
build = await factory.Build.create({
147+
jobStatus: "complete",
148+
conclusion: null,
149+
stats: null,
150+
});
147151
await factory.ScreenshotDiff.createMany(2, [
148152
{ buildId: build.id, jobStatus: "complete" },
149153
{ buildId: build.id, jobStatus: "error" },
@@ -154,7 +158,11 @@ describe("models/Build", () => {
154158

155159
describe("and one pending screenshot diff", () => {
156160
it("should be pending", async () => {
157-
build = await factory.Build.create();
161+
build = await factory.Build.create({
162+
jobStatus: "complete",
163+
conclusion: null,
164+
stats: null,
165+
});
158166
await factory.ScreenshotDiff.createMany(2, [
159167
{ buildId: build.id, jobStatus: "complete" },
160168
{ buildId: build.id, jobStatus: "pending" },
@@ -165,7 +173,11 @@ describe("models/Build", () => {
165173

166174
describe("and one in progress screenshot diff", () => {
167175
it("should be progress", async () => {
168-
build = await factory.Build.create();
176+
build = await factory.Build.create({
177+
jobStatus: "complete",
178+
conclusion: null,
179+
stats: null,
180+
});
169181
await factory.ScreenshotDiff.createMany(2, [
170182
{ buildId: build.id, jobStatus: "complete" },
171183
{ buildId: build.id, jobStatus: "progress" },
@@ -176,7 +188,11 @@ describe("models/Build", () => {
176188

177189
describe("with complete screenshot diffs", () => {
178190
it("should be error", async () => {
179-
build = await factory.Build.create();
191+
build = await factory.Build.create({
192+
jobStatus: "complete",
193+
conclusion: null,
194+
stats: null,
195+
});
180196
await factory.ScreenshotDiff.createMany(2, [
181197
{ buildId: build.id, jobStatus: "complete" },
182198
{ buildId: build.id, jobStatus: "complete" },

apps/backend/src/database/models/Plan.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export class Plan extends Model {
1919
properties: {
2020
name: { type: "string" },
2121
includedScreenshots: { type: "number" },
22-
githubPlanId: { type: "number" },
23-
stripeProductId: { type: "string" },
22+
githubPlanId: { type: ["number", "null"] },
23+
stripeProductId: { type: ["string", "null"] },
2424
usageBased: { type: "boolean" },
2525
githubSsoIncluded: { type: "boolean" },
2626
fineGrainedAccessControlIncluded: { type: "boolean" },
@@ -29,8 +29,8 @@ export class Plan extends Model {
2929

3030
name!: string;
3131
includedScreenshots!: number;
32-
githubPlanId!: number;
33-
stripeProductId!: string;
32+
githubPlanId!: number | null;
33+
stripeProductId!: string | null;
3434
usageBased!: boolean;
3535
githubSsoIncluded!: boolean;
3636
fineGrainedAccessControlIncluded!: boolean;

0 commit comments

Comments
 (0)