conniehunt
conniehunt
Explore posts from servers
PPrisma
Created by conniehunt on 7/6/2024 in #help-and-questions
NestJS + prisma
Giving nestjs and prisma a go together for the first time but can't get it to run a migration or db push
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SurveysModule } from './surveys/surveys.module';
import { UsersModule } from './users/users.module';
import { IntegrationsModule } from './integrations/integrations.module';
import { DatabaseModule } from './database/database.module';
import { StripeModule } from './stripe/stripe.module';
import { ConfigModule } from '@nestjs/config';
import { PrismaService } from './prisma.service';

@Module({
imports: [
SurveysModule,
UsersModule,
IntegrationsModule,
DatabaseModule,
StripeModule,
ConfigModule.forRoot({
isGlobal: true,
}),
],
controllers: [AppController],
providers: [AppService, PrismaService],
})
export class AppModule {}
// app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SurveysModule } from './surveys/surveys.module';
import { UsersModule } from './users/users.module';
import { IntegrationsModule } from './integrations/integrations.module';
import { DatabaseModule } from './database/database.module';
import { StripeModule } from './stripe/stripe.module';
import { ConfigModule } from '@nestjs/config';
import { PrismaService } from './prisma.service';

@Module({
imports: [
SurveysModule,
UsersModule,
IntegrationsModule,
DatabaseModule,
StripeModule,
ConfigModule.forRoot({
isGlobal: true,
}),
],
controllers: [AppController],
providers: [AppService, PrismaService],
})
export class AppModule {}
//prisma.service.ts
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
async onModuleInit() {
await this.$connect();
}

async onModuleDestroy() {
await this.$disconnect();
}
}
//prisma.service.ts
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
async onModuleInit() {
await this.$connect();
}

async onModuleDestroy() {
await this.$disconnect();
}
}
//schema
generator client {
provider = "prisma-client-js"
}

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

model User {
id String @id
clerkId String @unique
emailAddress String? @unique
createdAt DateTime @default(now())
firstName String?
lastName String?
fullName String? @map("firstName + ' ' + lastName")
updatedAt DateTime? @updatedAt

@@index(clerkId)
}
//schema
generator client {
provider = "prisma-client-js"
}

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

model User {
id String @id
clerkId String @unique
emailAddress String? @unique
createdAt DateTime @default(now())
firstName String?
lastName String?
fullName String? @map("firstName + ' ' + lastName")
updatedAt DateTime? @updatedAt

@@index(clerkId)
}
when I run npx prisma migrate dev or npx prisma db push the process just freezes
3 replies