diff --git a/Dockerfile b/Dockerfile index 231389e..c119378 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,21 @@ FROM --platform=linux/amd64 node:18.8.0-alpine LABEL description="This container serves as an entry point for our future Snek Function projects." -LABEL org.opencontainers.image.source="https://github.com/snek-functions/mailpress" +LABEL org.opencontainers.image.source="https://github.com/snek-functions/mailpresss" LABEL maintainer="opensource@snek.at" WORKDIR /app COPY .sf/ ./.sf -COPY templates/ ./templates COPY package.json . +COPY templates/ ./templates +# Copy prisma files +COPY prisma/schema.prisma ./prisma/schema.prisma RUN yarn install --production +RUN npx prisma generate + CMD ["sh", "-c", "yarn sf-server"] EXPOSE 3000 diff --git a/package.json b/package.json index 48083a8..36cfa9c 100644 --- a/package.json +++ b/package.json @@ -26,13 +26,16 @@ } }, "dependencies": { + "@devoxa/prisma-relay-cursor-connection": "^3.1.0", + "@prisma/client": "^5.2.0", "@snek-at/function": "*", "@snek-at/function-cli": "*", "@snek-at/function-server": "*", "@snek-functions/jwt": "*", "dotenv": "^16.0.3", "html-minifier": "^4.0.0", - "twig": "^1.16.0" + "twig": "^1.16.0", + "prisma": "^5.2.0" }, "devDependencies": { "@types/html-minifier": "^4.0.2", @@ -44,7 +47,11 @@ "scripts": { "develop": "yarn sf develop", "build": "yarn sf build", + "migrate": "prisma migrate dev", "generate-clients": "yarn snek-query generate https://services.snek.at/iam/graphql --output ./src/clients/iam && yarn snek-query generate https://services.snek.at/mailer/graphql --output ./src/clients/mailer", "generate-clients-dev": "yarn snek-query generate http://localhost:4050/graphql --output ./src/clients/iam && yarn snek-query generate http://localhost:4020/graphql --output ./src/clients/mailer" + }, + "prisma": { + "schema": "prisma/schema.prisma" } } diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..e69de29 diff --git a/src/prisma.ts b/src/prisma.ts new file mode 100644 index 0000000..9e215ee --- /dev/null +++ b/src/prisma.ts @@ -0,0 +1,48 @@ +import { logger } from "@snek-at/function"; + +import type { PrismaClient as PrismaClientType } from "@prisma/client"; +import { createRequire } from "module"; + +const require = createRequire(import.meta.url); +const { PrismaClient } = require("@prisma/client") as { + PrismaClient: typeof PrismaClientType; +}; + +export const prisma = new PrismaClient({ + log: [ + { + level: "info", + emit: "event", + }, + { + level: "query", + emit: "event", + }, + { + level: "warn", + emit: "event", + }, + { + level: "error", + emit: "event", + }, + ], +}); + +prisma.$on("info", (e) => { + logger.debug(`[${e.timestamp}] [DEBUG] [Prisma] ${e.target}: ${e.message}`); +}); + +prisma.$on("query", (e) => { + logger.debug( + `[${e.timestamp}] [DEBUG] [Prisma] ${e.target}: ${e.query} (params: ${e.params}, duration: ${e.duration}ms)` + ); +}); + +prisma.$on("warn", (e) => { + logger.warn(`[${e.timestamp}] [WARNING] [Prisma] ${e.target}: ${e.message}`); +}); + +prisma.$on("error", (e) => { + logger.error(`[${e.timestamp}] [ERROR] [Prisma] ${e.target}: ${e.message}`); +});