Chris Bongers
01/09/2022, 11:41 AMnpx prisma migrate dev
I get the following:
[*] Changed the `photo` table
[+] Added foreign key on columns (userId)
? We need to reset the PostgreSQL database "test_db" at "localhost:5432".
Do you want to continue? All data will be lost.
How can I go about keeping my data whilst migrating to Prisma from TypeORM?
The TypeORM looks like this:
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@OneToMany((type) => Photo, (photo) => photo.user)
photos: Photo[];
}
@Entity()
export class Photo {
@PrimaryGeneratedColumn()
id: number;
@ManyToOne((type) => User, (user) => user.photos)
user: User;
}
Sabin Adams
01/10/2022, 5:25 PMintrospect
to pull the existing database's schema down first, or build it manually?Chris Bongers
01/10/2022, 5:58 PMnpx prisma db pull
Then I added the @@map function
The full schema:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Photo {
id Int @id(map: "PK_723fa50bf70dcfd06fb5a44d4ff") @default(autoincrement())
name String @db.VarChar(100)
description String
filename String @db.VarChar
views Int
isPublished Boolean
userId Int?
user User? @relation(fields: [userId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "FK_4494006ff358f754d07df5ccc87")
@@map('photo')
}
model User {
id Int @id(map: "PK_cace4a159ff9f2512dd42373760") @default(autoincrement())
firstName String @db.VarChar
lastName String @db.VarChar
age Int
photo Photo[]
@@map('user')
}
/// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client.
model typeorm_metadata {
type String @db.VarChar
database String? @db.VarChar
schema String? @db.VarChar
table String? @db.VarChar
name String? @db.VarChar
value String?
@@ignore
}
Sabin Adams
01/10/2022, 11:54 PM