typeorm-seeding icon indicating copy to clipboard operation
typeorm-seeding copied to clipboard

How to seed data with monorepo workspace in nestjs

Open Sotatek-PhuongNguyen4 opened this issue 2 years ago • 4 comments

I use monorepo to build the applications. I've some apps and libs

My code folder is below. How to write typeorm config file in my case for seeding data.

image

ormconfig.ts image

package json seeding script

image

Error image

The codebuild only has the main.js file. It doesn't have some file like .entity.js. So I think my ormconfig.ts file is wrong. Please help. Thanks you guys a lot.

Sotatek-PhuongNguyen4 avatar Nov 18 '22 07:11 Sotatek-PhuongNguyen4

@Sotatek-PhuongNguyen4 we are having the same issue that the lib import doesn't resolve right. Have you figured it out yet?

weilinzung avatar Oct 18 '23 18:10 weilinzung

@weilinzung I resolved this problem by creating SeederModule and run it as application context to initialize database. In each module, I run service to insert data directly to database. I hop It's helpful for you. image image image

Sotatek-PhuongNguyen4 avatar Oct 19 '23 03:10 Sotatek-PhuongNguyen4

@Sotatek-PhuongNguyen4 any update on this one? Have you found a solution that works together with Nest.js? Thank you!

dlhck avatar Mar 15 '24 07:03 dlhck

@Sotatek-PhuongNguyen4 any update on this one? Have you found a solution that works together with Nest.js? Thank you!

@davidhoeck As I commented above, I seeded data manually by using standalone application feature. Read more: https://docs.nestjs.com/faq/serverless#using-standalone-application-feature The main idea here is call directly to database to insert datas.

Sotatek-PhuongNguyen4 avatar Mar 19 '24 03:03 Sotatek-PhuongNguyen4