Skip to content

Commit

Permalink
refactor(mono): ♻️ Move prisma and prisma/client into internal packag…
Browse files Browse the repository at this point in the history
…e to be reusable with a single schmema
  • Loading branch information
Nudelsuppe42 committed Oct 26, 2024
1 parent 044a069 commit 2208f2d
Show file tree
Hide file tree
Showing 59 changed files with 109 additions and 69 deletions.
6 changes: 1 addition & 5 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"lint": "eslint . --max-warnings 0",
"prebuild": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'+'export const LIB_LICENSE = ' + JSON.stringify(require('./package.json').license) + ';'\" > src/util/package.ts",
"prettier": "prettier ./src --write --ignore-unknown",
"db:generate": "prisma generate",
"db:migrate": "prisma migrate deploy",
"db:studio": "prisma studio",
"env:copy": "cp .env.example .env"
},
"devDependencies": {
Expand All @@ -32,16 +29,15 @@
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"postcss": "^8.4.31",
"prisma": "^5.18.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.427.0",
"@bte-germany/terraconvert": "^1.0.1",
"@keycloak/keycloak-admin-client": "24.0.5",
"@prisma/client": "^5.18.0",
"@repo/prettier-config": "*",
"@repo/db": "*",
"@repo/typescript-config": "*",
"@turf/helpers": "^6.5.0",
"@turf/turf": "^6.5.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/Core.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as session from 'express-session';
import * as winston from 'winston';

import { PrismaClient } from '@prisma/client';
import { LIB_LICENSE, LIB_VERSION } from './util/package.js';
import { applicationReminder, purgeClaims, purgeVerifications } from './util/Prisma.js';

import { PrismaClient } from '@repo/db';
import Keycloak from 'keycloak-connect';
import AmazonAWS from './util/AmazonAWS.js';
import CronHandler from './util/CronHandler.js';
Expand Down Expand Up @@ -150,7 +150,7 @@ class Core {
export default Core;

function createPrismaClient() {
return new PrismaClient().$extends({
return new PrismaClient({ datasourceUrl: process.env.DATABASE_URL }).$extends({
name: 'uploadSrc',
result: {
upload: {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/controllers/ApplicationController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Application, ApplicationQuestionType, ApplicationStatus } from '@prisma/client';
import { Application, ApplicationQuestionType, ApplicationStatus } from '@repo/db';
import { Request, Response } from 'express';
import { sendBtWebhook, WebhookType } from '../util/BtWebhooks.js';
import { ERROR_GENERIC, ERROR_NO_PERMISSION, ERROR_VALIDATION } from '../util/Errors.js';
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/controllers/BuildTeamController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response } from 'express';
import { ERROR_GENERIC, ERROR_VALIDATION } from '../util/Errors.js';
import { FrontendRoutesGroups, rerenderFrontend } from '../util/Frontend.js';

import { ApplicationQuestionType } from '@prisma/client';
import { ApplicationQuestionType } from '@repo/db';
import crypto from 'crypto';
import { validationResult } from 'express-validator';
import yup from 'yup';
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/controllers/ClaimController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sendBtWebhook, WebhookType } from '../util/BtWebhooks.js';
import turf, { toOverpassPolygon, toPolygon } from '../util/Coordinates.js';
import { ERROR_GENERIC, ERROR_NO_PERMISSION, ERROR_VALIDATION } from '../util/Errors.js';

import { Claim } from '@prisma/client';
import { Claim } from '@repo/db';
import axios from 'axios';
import { validationResult } from 'express-validator';
import Core from '../Core.js';
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/controllers/TokenRouteController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sendBtWebhook, WebhookType } from '../util/BtWebhooks.js';
import turf, { toPolygon } from '../util/Coordinates.js';
import { ERROR_GENERIC, ERROR_VALIDATION } from '../util/Errors.js';

import { ApplicationStatus } from '@prisma/client';
import { ApplicationStatus } from '@repo/db';
import { validationResult } from 'express-validator';
import Core from '../Core.js';
import { parseApplicationStatus } from '../util/Parser.js';
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Core, { ExtendedPrismaClient } from '../Core.js';
import { ERROR_GENERIC, ERROR_NO_PERMISSION, ERROR_VALIDATION } from '../util/Errors.js';

import type KcAdminClient from '@keycloak/keycloak-admin-client';
import { ApplicationStatus } from '@prisma/client';
import { ApplicationStatus } from '@repo/db';
import { validationResult } from 'express-validator';
import { userHasPermissions } from '../web/routes/utils/CheckUserPermissionMiddleware.js';

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/types/express.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import UserRepresentation from '@keycloak/keycloak-admin-client/lib/defs/userRepresentation.js';
import { BuildTeam, User } from '@prisma/client';
import { BuildTeam, User } from '@repo/db';

interface kAuth {
grant: any;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/util/DiscordIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Claim } from '@prisma/client';
import { Claim } from '@repo/db';
import Core from '../Core.js';

class DiscordIntegration {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/util/Parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApplicationStatus } from '@prisma/client';
import { ApplicationStatus } from '@repo/db';

export function parseApplicationStatus(status: string, isTrial?: boolean): ApplicationStatus {
switch (status.toLowerCase()) {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/util/Prisma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApplicationStatus } from '@prisma/client';
import { ApplicationStatus } from '@repo/db';
import Core from '../Core.js';

export async function middlewareUploadSrc(params, next) {
Expand Down
3 changes: 2 additions & 1 deletion apps/api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@repo/typescript-config/expressjs.json",
"compilerOptions": {
"outDir": "./dist"
"outDir": "./dist",
"moduleResolution": "NodeNext"
},
"include": ["./src/**/*", "./index.ts"],
"exclude": ["node_modules"]
Expand Down
4 changes: 4 additions & 0 deletions packages/db/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#
# Database
#
DATABASE_URL="postgresql://user:pass@ip:5432/database?pool_timeout=0"
2 changes: 2 additions & 0 deletions packages/db/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
30 changes: 30 additions & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@repo/db",
"version": "0.0.0",
"private": true,
"packageManager": "[email protected]",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"scripts": {
"db:generate": "prisma generate",
"db:migrate": "prisma migrate deploy",
"db:studio": "prisma studio",
"db:pull": "prisma db pull",
"env:copy": "cp .env.example .env",
"build": "tsc"
},
"dependencies": {
"@prisma/client": "5.18.0",
"@repo/typescript-config": "*"
},
"devDependencies": {
"prisma": "5.18.0",
"typescript": "^4.9.4"
},
"exports": {
"types": "./src/index.ts",
"default": "./dist/index.js"
}
}
File renamed without changes.
6 changes: 6 additions & 0 deletions packages/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

/**
* Re-export all the types from the Prisma client to be used in apps. This way, we only need one prisma schema
*/
export * from '@prisma/client';

8 changes: 8 additions & 0 deletions packages/db/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"outDir": "./dist",
},
"include": ["./src/**/*"],
"exclude": ["node_modules"]
}
97 changes: 45 additions & 52 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1341,46 +1341,46 @@
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==

"@prisma/client@^5.18.0":
version "5.19.1"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.19.1.tgz#d73f2b17b08628b6450c1c2dd20924d7a993aadf"
integrity sha512-x30GFguInsgt+4z5I4WbkZP2CGpotJMUXy+Gl/aaUjHn2o1DnLYNTA+q9XdYmAQZM8fIIkvUiA2NpgosM3fneg==

"@prisma/debug@5.19.1":
version "5.19.1"
resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.19.1.tgz#9c6f25f62192104b96bee8c452e10872be6d000b"
integrity sha512-lAG6A6QnG2AskAukIEucYJZxxcSqKsMK74ZFVfCTOM/7UiyJQi48v6TQ47d6qKG3LbMslqOvnTX25dj/qvclGg==

"@prisma/engines-version@5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3":
version "5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3.tgz#f211e2c000ef244bc6e5eaddbde75223c2e71411"
integrity sha512-xR6rt+z5LnNqTP5BBc+8+ySgf4WNMimOKXRn6xfNRDSpHvbOEmd7+qAOmzCrddEc4Cp8nFC0txU14dstjH7FXA==

"@prisma/engines@5.19.1":
version "5.19.1"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.19.1.tgz#792d4f1ada73cf6fc20b0f188bf88d844bce428b"
integrity sha512-kR/PoxZDrfUmbbXqqb8SlBBgCjvGaJYMCOe189PEYzq9rKqitQ2fvT/VJ8PDSe8tTNxhc2KzsCfCAL+Iwm/7Cg==
dependencies:
"@prisma/debug" "5.19.1"
"@prisma/engines-version" "5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3"
"@prisma/fetch-engine" "5.19.1"
"@prisma/get-platform" "5.19.1"

"@prisma/fetch-engine@5.19.1":
version "5.19.1"
resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.19.1.tgz#10a0f75636cac6647c71b9edd0b9a79c1b58468a"
integrity sha512-pCq74rtlOVJfn4pLmdJj+eI4P7w2dugOnnTXpRilP/6n5b2aZiA4ulJlE0ddCbTPkfHmOL9BfaRgA8o+1rfdHw==
dependencies:
"@prisma/debug" "5.19.1"
"@prisma/engines-version" "5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3"
"@prisma/get-platform" "5.19.1"

"@prisma/get-platform@5.19.1":
version "5.19.1"
resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.19.1.tgz#518f3a0e260f716151671c64140fb67953e0307d"
integrity sha512-sCeoJ+7yt0UjnR+AXZL7vXlg5eNxaFOwC23h0KvW1YIXUoa7+W2ZcAUhoEQBmJTW4GrFqCuZ8YSP0mkDa4k3Zg==
dependencies:
"@prisma/debug" "5.19.1"
"@prisma/[email protected]":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-5.18.0.tgz#526e4281a448f214c0ff81d65c39243608c98294"
integrity sha512-BWivkLh+af1kqC89zCJYkHsRcyWsM8/JHpsDMM76DjP3ZdEquJhXa4IeX+HkWPnwJ5FanxEJFZZDTWiDs/Kvyw==

"@prisma/debug@5.18.0":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@prisma/debug/-/debug-5.18.0.tgz#527799e044d2903a35945e61ac2d8916e4b61ead"
integrity sha512-f+ZvpTLidSo3LMJxQPVgAxdAjzv5OpzAo/eF8qZqbwvgi2F5cTOI9XCpdRzJYA0iGfajjwjOKKrVq64vkxEfUw==

"@prisma/engines-version@5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169":
version "5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169.tgz#203426ebf4ec4e1acce7da4a59ec8f0df92b29e7"
integrity sha512-a/+LpJj8vYU3nmtkg+N3X51ddbt35yYrRe8wqHTJtYQt7l1f8kjIBcCs6sHJvodW/EK5XGvboOiwm47fmNrbgg==

"@prisma/engines@5.18.0":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-5.18.0.tgz#26ea46e26498be622407cf95663d7fb4c39c895b"
integrity sha512-ofmpGLeJ2q2P0wa/XaEgTnX/IsLnvSp/gZts0zjgLNdBhfuj2lowOOPmDcfKljLQUXMvAek3lw5T01kHmCG8rg==
dependencies:
"@prisma/debug" "5.18.0"
"@prisma/engines-version" "5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169"
"@prisma/fetch-engine" "5.18.0"
"@prisma/get-platform" "5.18.0"

"@prisma/fetch-engine@5.18.0":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@prisma/fetch-engine/-/fetch-engine-5.18.0.tgz#5b343e2b36b27e2713901ddd032ddd6932b3d55f"
integrity sha512-I/3u0x2n31rGaAuBRx2YK4eB7R/1zCuayo2DGwSpGyrJWsZesrV7QVw7ND0/Suxeo/vLkJ5OwuBqHoCxvTHpOg==
dependencies:
"@prisma/debug" "5.18.0"
"@prisma/engines-version" "5.18.0-25.4c784e32044a8a016d99474bd02a3b6123742169"
"@prisma/get-platform" "5.18.0"

"@prisma/get-platform@5.18.0":
version "5.18.0"
resolved "https://registry.yarnpkg.com/@prisma/get-platform/-/get-platform-5.18.0.tgz#0dc4c82fe9a4971f4519a57cb2dd69d8e0df4b71"
integrity sha512-Tk+m7+uhqcKDgnMnFN0lRiH7Ewea0OEsZZs9pqXa7i3+7svS3FSCqDBCaM9x5fmhhkufiG0BtunJVDka+46DlA==
dependencies:
"@prisma/debug" "5.18.0"

"@react-spring/animated@~9.6.1":
version "9.6.1"
Expand Down Expand Up @@ -6101,11 +6101,6 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

[email protected]:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==

function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
Expand Down Expand Up @@ -8227,14 +8222,12 @@ prism-react-renderer@^1.2.1:
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.3.5.tgz#786bb69aa6f73c32ba1ee813fbe17a0115435085"
integrity sha512-IJ+MSwBWKG+SM3b2SUfdrhC+gu01QkV2KmRQgREThBfSQRoufqRfxfHUxpG1WcaFjP+kojcFyO9Qqtpgt3qLCg==

prisma@^5.18.0:
version "5.19.1"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.19.1.tgz#33a4fecb9bcdf1c3f40d2c7e1cc06055edbb0ebc"
integrity sha512-c5K9MiDaa+VAAyh1OiYk76PXOme9s3E992D7kvvIOhCrNsBQfy2mP2QAQtX0WNj140IgG++12kwZpYB9iIydNQ==
[email protected]:
version "5.18.0"
resolved "https://registry.yarnpkg.com/prisma/-/prisma-5.18.0.tgz#5ef69c802a075b7596231ea57003496873610b9e"
integrity sha512-+TrSIxZsh64OPOmaSgVPH7ALL9dfU0jceYaMJXsNrTkFHO7/3RANi5K2ZiPB1De9+KDxCWn7jvRq8y8pvk+o9g==
dependencies:
"@prisma/engines" "5.19.1"
optionalDependencies:
fsevents "2.3.3"
"@prisma/engines" "5.18.0"

process-nextick-args@~2.0.0:
version "2.0.1"
Expand Down

0 comments on commit 2208f2d

Please sign in to comment.