-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Prisma support and generate schema
- Added Prisma dependency to package.json - Copied prisma/schema.prisma file in Dockerfile - Added "migrate" script to package.json for running Prisma migrations - Created prisma/schema.prisma file - Created a prisma.ts file
- Loading branch information
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="[email protected]" | ||
|
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`); | ||
}); |