Skip to content

Commit

Permalink
prisma error fixed - related to prisma/prisma#16600
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Dec 2, 2022
1 parent e91e436 commit 8a47669
Show file tree
Hide file tree
Showing 9 changed files with 3,217 additions and 1,136 deletions.
4 changes: 2 additions & 2 deletions packages/db/index.ts
Expand Up @@ -6,10 +6,10 @@ declare global {
var prisma: PrismaClient | undefined
}

export const prisma: PrismaClient =
export const prisma =
global.prisma ||
new PrismaClient({
// log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
log: process.env.NODE_ENV === 'development' ? ['query', 'error', 'warn'] : ['error'],
})

if (process.env.NODE_ENV !== 'production') {
Expand Down
4 changes: 2 additions & 2 deletions packages/db/package.json
Expand Up @@ -33,7 +33,7 @@
"with-env": "dotenv -e ../../.env --"
},
"dependencies": {
"@prisma/client": "4.7.0",
"@prisma/client": "4.7.1",
"prisma-docs-generator": "0.5.0",
"zod": "3.19.1"
},
Expand Down Expand Up @@ -65,7 +65,7 @@
"listr2": "5.0.5",
"luxon": "3.1.0",
"mongoback": "3.0.3",
"prisma": "4.7.0",
"prisma": "4.7.1",
"prisma-dbml-generator": "0.10.0",
"quicktype-core": "6.1.0",
"recursive-readdir": "2.2.3",
Expand Down
9 changes: 5 additions & 4 deletions packages/db/prisma/schema.prisma
@@ -1,9 +1,10 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["fieldReference", "postgresqlExtensions", "clientExtensions", "filteredRelationCount", "multiSchema"]
// output = "../../../node_modules/.prisma/client"
// output = "../node_modules/.prisma/client"
binaryTargets = ["native", "rhel-openssl-1.0.x"]
// clientExtensions causing error
// previewFeatures = ["fieldReference", "postgresqlExtensions", "filteredRelationCount", "multiSchema", "clientExtensions"]
previewFeatures = ["fieldReference", "postgresqlExtensions", "filteredRelationCount", "multiSchema"]
binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

// generator docs {
Expand Down
65 changes: 28 additions & 37 deletions packages/db/seed/data/03-ethnicity.ts
@@ -1,10 +1,8 @@
import { Prisma, UserEthnicity } from '~/client'
import { prisma } from '~/index'

import { logFile } from '../logger'
import { ListrTask } from '../starterData'
import { keySlug } from './00-namespaces'
import { translationNamespace } from './01-user'
import { keySlug, namespaces } from './00-namespaces'

type EthnicityData = string[]

Expand All @@ -23,46 +21,39 @@ const ethnicityData: EthnicityData = [
]

export const generateEthnicityRecords = (task: ListrTask) => {
const queue: Prisma.Prisma__UserEthnicityClient<Partial<UserEthnicity>>[] = []
let i = 1
for (const item of ethnicityData) {
const transaction: Prisma.Prisma__UserEthnicityClient<Partial<UserEthnicity>> =
prisma.userEthnicity.upsert({
where: {
ethnicity: item,
},
create: {
ethnicity: item,
key: {
create: {
key: `eth-${keySlug(item)}`,
text: item,
namespace: {
connect: {
name: translationNamespace,
},
const queue = ethnicityData.map((item, i) => {
const logMessage = `(${i}/${ethnicityData.length}) Added Ethnicity transaction to queue: ${item}`
logFile.log(logMessage)
task.output = logMessage

return prisma.userEthnicity.upsert({
where: {
ethnicity: item,
},
create: {
ethnicity: item,
key: {
create: {
key: `eth-${keySlug(item)}`,
text: item,
namespace: {
connect: {
name: namespaces.user,
},
},
},
},
update: {
key: {
update: {
key: `eth-${keySlug(item)}`,
text: item,
},
},
update: {
key: {
update: {
key: `eth-${keySlug(item)}`,
text: item,
},
},
select: {
id: true,
},
})
},
})
})

queue.push(transaction)
const logMessage = `(${i}/${ethnicityData.length}) Added Ethnicity transaction to queue: ${item}`
logFile.log(logMessage)
task.output = logMessage
i++
}
return queue
}
6 changes: 2 additions & 4 deletions packages/db/seed/starter/01-user.ts
@@ -1,12 +1,10 @@
import { UserRole } from '@prisma/client'
import slugify from 'slugify'

import { Prisma } from '~/client'
import { prisma } from '~/index'
import { namespaces } from '~/seed/data'
import { ListrTask } from '~/seed/starterData'

import { seedUser, userEmail, userRoleList } from '../data/01-user'
import { seedUser, userEmail, userRoleList } from '../data'
import { logFile } from '../logger'

export const seedSystemUser = async (task: ListrTask) => {
Expand Down Expand Up @@ -77,7 +75,7 @@ export const seedUserTypes = async (task: ListrTask) => {
export const seedUserRoles = async (task: ListrTask) => {
let logMessage = ``
let countA = 1
const bulkTransactions: Prisma.Prisma__UserRoleClient<UserRole>[] = userRoleList.map((role) => {
const bulkTransactions = userRoleList.map((role) => {
logMessage = `(${countA}/${userRoleList.length}) Upserting User Role: ${role.name}`
logFile.info(logMessage)
task.output = logMessage
Expand Down
3 changes: 0 additions & 3 deletions packages/db/seed/starter/12-geodata.ts
Expand Up @@ -202,9 +202,6 @@ const countryUS = async (task: ListrTask) => {
parent: connectTo(stateId),
key,
},
select: {
id: true,
},
})
)
countA++
Expand Down
5 changes: 2 additions & 3 deletions packages/db/tsconfig.json
Expand Up @@ -6,8 +6,7 @@
"baseUrl": ".",
"paths": {
"~/*": ["./*"]
},
"declaration": true
}
},
"include": ["index.ts", "data-transfer", "seed", "zod-schemas", "zod-util"]
"include": ["index.ts", "datastore", "seed", "zod-schemas", "zod-util"]
}
12 changes: 0 additions & 12 deletions packages/db/tsup.config.ts

This file was deleted.

0 comments on commit 8a47669

Please sign in to comment.