Skip to content

Upgrade prisma #401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion server/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRISMA_URL=http://localhost:4466
DATABASE_URL="postgresql://prisma:prisma@localhost:5432/prisma?schema=default$default"
PRISMA_API_SECRET=secret-42
PRISMA_MANAGEMENT_API_SECRET=my-secret-42

Expand Down
6,982 changes: 1,956 additions & 5,026 deletions server/package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
"name": "faq_server",
"version": "1.0.0",
"dependencies": {
"@graphql-tools/utils": "^7.10.0",
"@prisma/client": "^5.1.1",
"algoliasearch": "^3.35.1",
"express": "^4.17.3",
"express-force-https": "^1.0.0",
"express-jwt": "^6.0.0",
"form-data": "^2.5.1",
"graphql": "^15.8.0",
"graphql-yoga": "^1.18.3",
"isomorphic-fetch": "^2.2.1",
"jsonwebtoken": "^8.5.1",
Expand All @@ -15,7 +18,6 @@
"mjml": "^4.5.1",
"node-fetch": "^2.6.7",
"path": "^0.12.7",
"prisma": "^1.34.10",
"prisma-binding": "^2.3.16",
"prisma-multi-tenant": "^1.0.3",
"showdown": "^1.9.1",
Expand Down Expand Up @@ -61,6 +63,7 @@
"lint-staged": "^13.2.3",
"nodemon": "^1.19.4",
"prettier": "^1.19.1",
"prisma": "^5.1.1",
"prisma-yml": "^1.34.10"
},
"prettier": {
Expand Down
179 changes: 179 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Answer {
id String @id @db.VarChar(25)
content String
createdAt DateTime
updatedAt DateTime
language String
certified String?
translationId String?
translation Translation? @relation(fields: [translationId], references: [id], name: "AnswerTranslation")
sources Source[]
nodeId String @unique
node ZNode @relation(fields: [nodeId], references: [id])
userId String
user User @relation(fields: [userId], references: [id])
}

model Configuration {
id String @id @db.VarChar(25)
name String @unique(map: "default$default.Configuration.name._UNIQUE")
title String
auth0Domain String
auth0ClientId String
algoliaAppId String?
algoliaApiKey String?
algoliaSynonyms String?
mailgunDomain String?
mailgunApiKey String?
slackChannelHook String?
slackCommandKey String?
tags String?
workplaceSharing Boolean?
bugReporting String?
updatedAt DateTime
createdAt DateTime
authorizedDomains AuthorizedDomains[]
tagCategories TagCategory[]
}

model AuthorizedDomains {
nodeId String @db.VarChar(25)
position Int
value String
configuration Configuration @relation(fields: [nodeId], references: [id], onDelete: NoAction, onUpdate: NoAction)

@@id([nodeId, position])
}

model Flag {
id String @id @db.VarChar(25)
type String
createdAt DateTime
updatedAt DateTime
nodeId String
node ZNode @relation(fields: [nodeId], references: [id])
userId String
user User @relation(fields: [userId], references: [id])
}

model HistoryAction {
id String @id @db.VarChar(25)
action String
model String
meta String?
createdAt DateTime
updatedAt DateTime
nodeId String
node ZNode @relation(fields: [nodeId], references: [id])
userId String
user User @relation(fields: [userId], references: [id])
}

model Question {
id String @id @db.VarChar(25)
title String
slug String
views Int?
createdAt DateTime
updatedAt DateTime
language String
translationId String?
translation Translation? @relation(fields: [translationId], references: [id], name: "QuestionTranslation")
nodeId String @unique
node ZNode @relation(fields: [nodeId], references: [id])
userId String
user User @relation(fields: [userId], references: [id])
}

model Source {
id String @id @db.VarChar(25)
label String
url String
updatedAt DateTime
createdAt DateTime
answerId String
answer Answer @relation(fields: [answerId], references: [id])
}

model Tag {
id String @id @db.VarChar(25)
createdAt DateTime
updatedAt DateTime
nodeId String
node ZNode @relation(fields: [nodeId], references: [id])
labelId String
label TagLabel @relation(fields: [labelId], references: [id])
userId String
user User @relation(fields: [userId], references: [id])
}

model TagCategory {
id String @id @db.VarChar(25)
name String
order Int
updatedAt DateTime
createdAt DateTime
configurationId String
configuration Configuration @relation(fields: [configurationId], references: [id])
labels TagLabel[]
}

model TagLabel {
id String @id @db.VarChar(25)
name String
order Int
createdAt DateTime
updatedAt DateTime
categoryId String
category TagCategory @relation(fields: [categoryId], references: [id])
tags Tag[]
specialists User[]
}

model Translation {
id String @id @db.VarChar(25)
language String
text String
question Question @relation(name: "QuestionTranslation")
answer Answer @relation(name: "AnswerTranslation")
}

model User {
id String @id @db.VarChar(25)
auth0Id String? @unique(map: "default$default.User.auth0Id._UNIQUE")
key String?
admin Boolean
name String?
email String?
picture String?
locale String?
createdAt DateTime
updatedAt DateTime
Answer Answer[]
flags Flag[]
history HistoryAction[]
questions Question[]
specialties TagLabel[]
tags Tag[]
}

model ZNode {
id String @id @db.VarChar(25)
highlights String?
updatedAt DateTime
createdAt DateTime
answer Answer
flags Flag[]
history HistoryAction[]
question Question
tags Tag[]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion server/src/directives/admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { SchemaDirectiveVisitor } = require('graphql-tools')
const { SchemaDirectiveVisitor } = require('@graphql-tools/utils')
const { defaultFieldResolver } = require('graphql')

class AdminDirective extends SchemaDirectiveVisitor {
Expand Down
62 changes: 32 additions & 30 deletions server/src/middlewares/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,39 @@ const getConfiguration = async (multiTenant, req, next) => {
}

const refreshConfiguration = async tenant => {
const conf = await tenant.query.configuration(
{
where: { name: 'default' }
},
`{
id
name
title
auth0Domain
auth0ClientId
authorizedDomains
algoliaAppId
algoliaApiKey
algoliaSynonyms
mailgunDomain
mailgunApiKey
slackChannelHook
tagCategories {
id
order
name
labels {
id
order
name
const conf = await tenant.configuration.findUnique({
where: { name: 'default' },
select: {
id: true,
name: true,
title: true,
auth0Domain: true,
auth0ClientId: true,
authorizedDomains: true,
algoliaAppId: true,
algoliaApiKey: true,
algoliaSynonyms: true,
mailgunDomain: true,
mailgunApiKey: true,
slackChannelHook: true,
tagCategories: {
select: {
id: true,
order: true,
name: true,
labels: {
select: {
id: true,
order: true,
name: true
}
}
}
}
workplaceSharing
bugReporting
}`
)
},
workplaceSharing: true,
bugReporting: true
}
})
if (!conf) {
throw new TypeError(
`could not find configuration with name "default" for service "${tenant._meta.service.name}" and stage "${tenant._meta.service.stage}"`
Expand Down
9 changes: 2 additions & 7 deletions server/src/multiTenant.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { Prisma } = require('prisma-binding')
const { MultiTenant } = require('prisma-multi-tenant')
const path = require('path')
const { PrismaClient } = require('@prisma/client')
const logger = require('./helpers/logger')

const multiTenant = new MultiTenant({
Expand All @@ -9,11 +8,7 @@ const multiTenant = new MultiTenant({
logger.info(
`instanciating prisma client for service "${name}", stage "${stage}", and endpoint "${endpoint}"`
)
return new Prisma({
typeDefs: path.join(__dirname, '/generated/prisma.graphql'),
endpoint,
secret: process.env.PRISMA_API_SECRET
})
return new PrismaClient()
},
nameStageFromReq: req => {
// Env vars take precedence
Expand Down
2 changes: 1 addition & 1 deletion server/src/resolvers/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const confTagLabels = ctx =>
module.exports = {
Query: {
zNode: async (_, args, ctx, info) => {
let node = await ctx.prisma.query.zNode(args, info)
let node = await ctx.prisma.zNode.findUnique({ where: { id: args.id } }, info)
if (!node.question.language || (node.answer && !node.answer?.language)) {
node = await translateContentAndSave(node, ctx, info)
}
Expand Down