w3tecch / typeorm-seeding

🌱 A delightful way to seed test data into your database.
https://www.npmjs.com/package/typeorm-seeding
MIT License
877 stars 131 forks source link

How to seed data with monorepo workspace in nestjs #236

Open Sotatek-PhuongNguyen4 opened 1 year ago

Sotatek-PhuongNguyen4 commented 1 year ago

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.

weilinzung commented 9 months ago

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

Sotatek-PhuongNguyen4 commented 9 months ago

@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

davidhoeck commented 4 months ago

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

Sotatek-PhuongNguyen4 commented 4 months ago

@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.