Add indexing job model

This commit is contained in:
Lukasz Ostrowski 2023-06-07 12:56:23 +02:00
parent d84744bfab
commit 2bd659a1b4
5 changed files with 83 additions and 17 deletions

View file

@ -2,23 +2,22 @@
"name": "saleor-app-search",
"version": "1.9.3",
"scripts": {
"dev:app": "pnpm generate && NODE_OPTIONS='--inspect' next dev",
"build:app": "pnpm generate && next build",
"start:app": "next start",
"build": "concurrently \"pnpm build:app\" \"pnpm build:worker\"",
"build:app": "pnpm generate && next build",
"build:worker": "pnpm generate && tsup src/worker/runner.ts --outDir worker-dist",
"dev": "concurrently \"pnpm dev:app\" \"pnpm dev:worker\"",
"lint": "next lint",
"lint:fix": "eslint --fix .",
"dev:app": "pnpm generate && NODE_OPTIONS='--inspect' next dev",
"dev:worker": "pnpm generate && tsx src/worker/runner.ts --watch",
"fetch-schema": "curl https://raw.githubusercontent.com/saleor/saleor/${npm_package_saleor_schemaVersion}/saleor/graphql/schema.graphql > graphql/schema.graphql",
"generate": "graphql-codegen && npm run prisma:generate",
"test": "vitest",
"dev:worker": "pnpm generate && tsx src/worker/runner.ts --watch",
"build:worker": "pnpm generate && tsup src/worker/runner.ts --outDir worker-dist",
"lint": "next lint",
"lint:fix": "eslint --fix .",
"prisma:generate": "prisma generate",
"start:app": "next start",
"start:worker": "node worker-dist/runner.js",
"prisma:generate": "prisma generate"
"test": "vitest"
},
"dependencies": {
"graphile-worker": "^0.13.0",
"@hookform/resolvers": "^3.1.0",
"@prisma/client": "^4.15.0",
"@saleor/app-sdk": "0.39.1",
@ -32,21 +31,22 @@
"algoliasearch": "4.14.2",
"clsx": "^1.2.1",
"debug": "^4.3.4",
"dotenv": "^16.1.4",
"graphile-worker": "^0.13.0",
"graphql": "16.6.0",
"graphql-tag": "^2.12.6",
"next": "13.3.0",
"next-urql": "4.0.0",
"pino": "^8.14.1",
"pino-pretty": "^10.0.0",
"prisma": "^4.15.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-helmet": "^6.1.0",
"react-hook-form": "^7.43.9",
"react-query": "^3.39.3",
"urql": "^3.0.3",
"zod": "^3.21.4",
"dotenv": "^16.1.4",
"prisma": "^4.15.0"
"zod": "^3.21.4"
},
"devDependencies": {
"@graphql-codegen/cli": "3.2.2",
@ -61,15 +61,15 @@
"@types/react": "~18.0.38",
"@types/react-dom": "^18.0.8",
"@vitejs/plugin-react": "4.0.0",
"concurrently": "^8.1.0",
"eslint": "8.42.0",
"eslint-config-saleor": "workspace:*",
"node-mocks-http": "^1.12.2",
"tsup": "^6.7.0",
"tsx": "^3.12.7",
"typescript": "5.1.3",
"vite": "4.3.9",
"vitest": "0.31.3",
"tsup": "^6.7.0",
"concurrently": "^8.1.0",
"tsx": "^3.12.7"
"vitest": "0.31.3"
},
"private": true,
"saleor": {

View file

@ -0,0 +1,13 @@
-- CreateTable
CREATE TABLE "IndexJob" (
"id" SERIAL NOT NULL,
"jobId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"createdBy" TEXT NOT NULL,
"status" TEXT NOT NULL,
CONSTRAINT "IndexJob_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "IndexJob_jobId_key" ON "IndexJob"("jobId");

View file

@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `ownerSaleor` to the `IndexJob` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "IndexJob" ADD COLUMN "ownerSaleor" TEXT NOT NULL;

View file

@ -17,3 +17,12 @@ model AlgoliaConfiguration {
secretKey String // TODO encryption
saleorApiUrl String @unique // Reference - maybe it can be unique id? This will share config where 2 apps installed
}
model IndexJob {
id Int @id @default(autoincrement())
jobId Int @unique
createdAt DateTime @default(now())
createdBy String
status String // probably enum
ownerSaleor String // maybe we should have table with insalled saleors
}

View file

@ -0,0 +1,36 @@
import { prisma, Prisma } from "../../db/prisma";
export class IndexingJobRepository {
constructor(private prisma: Prisma) {}
getJob(jobId: number, saleorApiUrl: string) {
return this.prisma.indexJob.findFirst({
where: {
AND: {
ownerSaleor: saleorApiUrl,
jobId,
},
},
});
}
createPendingJob(
saleorApiUrl: string,
job: {
jobId: number;
createdByEmail: string;
secretKey: string;
}
) {
return this.prisma.indexJob.create({
data: {
ownerSaleor: saleorApiUrl,
jobId: job.jobId,
createdBy: job.createdByEmail,
status: "PENDING",
},
});
}
}
export const indexingJobRepository = new IndexingJobRepository(prisma);