Atticus Curtis
03/21/2022, 6:56 PMOrcioly Andrade Alves
03/22/2022, 2:05 AMalechko
03/22/2022, 6:52 AMprisma migrate
command generates raw sql file and there’s no up
method that could be used to launch a custom script or whatever to initiate a data migration process related to the schema process. is there a best practices how to do that with maybe prisma seed
or some other method, or do I need to figure out on my own how to do that?
2. are UNION
queries available from the client api or only by raw sql?
3. is there a way to specify db master/replicas and set the query to use a replica
for reads and master
for writes? (like Mikro-ORM)
Thanks!s1w
03/22/2022, 7:16 AMmodel Item {
id String @unique
}
model Set {
additions Item[]
removals Item[]
}
I can’t get the right combination of references and stuff between the twodhatGuy
03/22/2022, 9:58 AM@default(crypt(genSaltSync(10), ""))
GitHub copilot suggested that when defining a model and I want to know if it is possible. I have searched and I can't find an answer.Orcioly Andrade Alves
03/22/2022, 1:15 PMimport { User } from '@prisma/client';
import { AppError } from '../shared/errors/AppError';
import prismaClient from '../prisma';
import { hash } from 'bcryptjs';
import { CreateUserDTO } from '../dtos/user/CreateUserDto';
class CreateUserService {
async execute({
_name_,
_email_,
_password_,
_admin_,
}: _CreateUserDTO_): _Promise_<_User_ | _undefined_> {
const passwodHash = await hash(_password_, 8);
const userAlreadyExists = await prismaClient.user.findUnique({
where: {
email,
},
});
if (!userAlreadyExists) {
try {
const user = await prismaClient.user.create({
data: {
name,
email,
password: passwodHash,
admin,
},
});
return user;
} catch (error) {
throw *new* AppError('User already exists!');
}
}
}
}
export { CreateUserService };
Julius
03/22/2022, 1:25 PMuser
03/22/2022, 2:12 PMuser
03/22/2022, 2:14 PMDaniel Mahon
03/22/2022, 6:56 PMKilled
prisma exceptions?…. Im qeurying a large data set 3mil+ (indexed) but even locally prisma seems to crash when trying to return anything larger than a few thousand records. I cant seem to find any other error message. When enabled prisma logging the only thing different is it doesnt print out the “query” to console, like it does with the previous ones. Thoughts?
EDIT: Nevermind, I think it has something to do with my local docker setup, not specifically prisma.Adam
03/22/2022, 7:09 PMv2.27.0
to the latest v3.11.0
in typescript/node, and I’m having issues with Prisma
Keeping the previous connection string when starting a new Integration Test.
Is there something else I should do to force-reset the connection string that prisma is using?
I know the example docs show to call delete
on everything, but that seemed excessive and painstaking. So I simply generate a new schema (postgres
) for each test suite, keeps it nice and clean. I override the Jest
NodeEnvironment
to create a new random connection string. This was working fine in v2.27. Now the below code will fail tests because prisma
will try to be querying a schema from a previous test and it doesn’t exist. I am also using --runInBand
with jest to run tests sequentially
class PrismaTestEnvironment extends NodeEnvironment {
connectionString?: string;
schema?: string;
app?: ExpressType;
constructor(config: Config.ProjectConfig) {
//@ts-ignore
super(config);
// Generate a unique schema identifier for this test context
this.schema = stringGenerator();
//pseudo-code, set random schema on DB_URL ENV
this.global.process.env.DB_URL = `{myConnectionString}/${this.schema}`
process.env.DB_URL = `{myConnectionString}/${this.schema}`
}
public async setup(): Promise<void> {
process.env.DB_URL = this.connectionString;
this.global.process.env.DB_URL = this.connectionString;
forceResetPrisma();
// Run the migrations to ensure our schema has the required structure
try {
const out = await promisifiedExec(
`${prismaBinary} db push --force-reset`
);
<http://this.app|this.app> = await initExpress();
<http://this.global.APP|this.global.APP> = <http://this.app|this.app>;
} catch (e) {
console.error(e);
throw e;
}
return super.setup();
}
public async teardown(): Promise<void> {
const prismaClient = getPrisma();
await prismaClient.$executeRawUnsafe(
`drop schema if exists "${this.schema}" cascade`
);
await prismaClient.$disconnect();
await super.teardown();
}
}
export default PrismaTestEnvironment;
//Prisma Generator File
import { PrismaClient, Prisma } from '@prisma/client';
let db: PrismaClient;
const DefaultLogLevels: Prisma.LogLevel[] = ['info', 'warn', 'error'];
export const getPrisma = (log: Array<Prisma.LogLevel> = DefaultLogLevels) => {
if (!db) {
forceResetPrisma(log);
}
return db;
};
export const hasPrisma = () => !!db;
/**
* Force reset the DB instance using the current @param DB_URL environment var
* @param log
* @returns
*/
export const forceResetPrisma = (
log: Array<Prisma.LogLevel> = DefaultLogLevels
) => {
console.log(`[PRISMA] Generating Client with log levels ${log.join(',')} `);
try {
db = new PrismaClient({
log,
});
} catch (e) {
console.error(e);
throw e;
}
return db;
};
ben aldrich
03/22/2022, 8:26 PMben aldrich
03/22/2022, 8:28 PMconst allUsers = await prisma.user.findMany({
include: {
posts: true,
limit: 10 // <--- Something like this
},
})
Philipp Minder
03/22/2022, 10:32 PMKenneth Gitere
03/23/2022, 5:06 AM@prisma/client
. Idk how often other people faced such an issue so I was thinking I could add to any existing wiki on it as a potential fix.Kenneth Gitere
03/23/2022, 5:06 AMKay Khan
03/23/2022, 8:48 AMGenericFailure
and i'm not really too sure what is happening here..
export const GetReachForServiceIds = async (serviceIds: string[], startDate: Date, endDate: Date) => {
try {
const result = await PrismaService.reach_growth.findMany({
where: { service_id: { in: serviceIds }, date: { gte: startDate, lte: endDate } },
});
return [result, null] as const;
} catch (err) {
Logger.error({ kind: "leaderboard_reach", method: "GetReachForServiceIds", error: err, stack_trace: err.stack });
return [null, err] as const;
}
};
Invalid `PrismaService.reach_growth.findMany()` invocation in
/home/kay/checkpoint/leaderboards/src/reach/reach.service.ts:19:57
16
17 export const GetReachForServiceIds = async (serviceIds: string[], startDate: Date, endDate: Date) => {
18 try {
→ 19 const result = await PrismaService.reach_growth.findMany(
at Object.request (/home/kay/checkpoint/leaderboards/node_modules/@prisma/client/runtime/index.js:39818:15)
at async PrismaClient._request (/home/kay/checkpoint/leaderboards/node_modules/@prisma/client/runtime/index.js:40646:18)
at async GetReachForServiceIds (/home/kay/checkpoint/leaderboards/src/reach/reach.service.ts:19:24)
at async LeaderboardReach (/home/kay/checkpoint/leaderboards/src/reach/leaderboard-reach.ts:23:37)
at async Main (/home/kay/checkpoint/leaderboards/src/reach/main.ts:9:9) {
code: 'GenericFailure',
clientVersion: '3.11.0',
meta: undefined
nikolasburk
Dhananjay Takalkar
03/23/2022, 10:55 AMJonas Rothmann
03/23/2022, 1:02 PMAustin Zentz
03/23/2022, 2:03 PMAdam Kaczmarek
03/23/2022, 3:02 PMmotiondev
03/23/2022, 3:47 PMreturn ctx.prisma.dataProvider.update({
data: {
name: args.data?.name,
description: args.data?.description,
},
where: {
id: BigInt(args.data.id), // <===== I have to do this to every Prisma operation where I work with IDS
},
});
Is there something like a way to extend models to accept id as string and cast it at model level with BigInt(id)?
Thanks in advance!Julian
03/23/2022, 4:16 PMorder
table for exampleSeraphina Orsini
03/23/2022, 7:07 PMMultiSubnetFailover
for sqlserver is blocking my team and I would love to help contribute a fix if possible. It appears like it may be a simple fix here, but would love to chat with someone on if that is the right approach before jumping in (or if there are any other expected blockers). GH Issue here.Glaucia Lemos
03/23/2022, 9:17 PMBret emm
03/23/2022, 10:40 PMezeikel
03/23/2022, 11:37 PMfindRaw
with mongodb? The raw query returns an empty array but the other query returns all users as expected. Am I doing something wrong?
const rawUsers = await prisma.user.findRaw(); // empty array
const users = await prisma.user.findMany(); // all users as expected
Hamin Lee
03/24/2022, 5:14 AMA. Sauder
03/24/2022, 6:30 AM