typeorm
typeorm copied to clipboard
Seeding
Issue type:
[ ] question [ ] bug report [x] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[x] mongodb
[x] mssql
[x] mysql / mariadb
[x] oracle
[x] postgres
[x] cockroachdb
[x] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
Propose
Maybe add a field in ormconfig.json that points to a directory where seeders can be located.
Add an interface that i could inherit to seed the database with data.
Example ormconfig.json
[
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "postgres",
"password": "postgres",
"database": "seeded",
"synchronize": true,
"logging": true,
"entities": ["src/entity/**/*.*"],
"seeders": ["src/seeder/**/*.*"],
"migrations": ["src/migration/**/*.*"],
"subscribers": ["src/subscriber/**/*.*"],
"cli": {
"entitiesDir": "src/entity",
"seedersDir": "src/seeder",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
}
]
Example Seeder
import { SeederInterface, QueryRunner } from "typeorm"
export class UserSeeder implements SeederInterface {
public async seed(queryRunner: QueryRunner): Promise<any> {
//...logic here
}
}
If you need something now this works fine https://github.com/w3tecch/typeorm-seeding
Hello, This feature is very needed, not for fake data but I have this problem on my job that we have data to be seed to parameterize, you insert some data that you need to start.
A hint I am not a fan of sequelize but they have a must have feature related to this. Like the migrations inserts a line for each migration done, the seed must do as weel because is so much easier iterate over big projects and/or run the migrations and seed on deploy throughout a ci/cd pipeline (https://sequelize.org/master/manual/migrations.html#seed-storage).
Btw great project thank you.
Any updates on this?
Any updates on this?
Hey folks dunno when TypeORM gets up to speed on developing new features, but ATM I think these are potential solutions:
- Create a
SeederFactoryclass and then have it implemented for each entity separately. Frankly speaking it is not the most convenient solution. - Create an empty migration and then there seed your DB :thinking: IDK if this is the brightest idea ever or not.
- Or we can use 3rd-party libs as it is being suggested in the docs: https://typeorm.io/#extensions.
TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).
As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.
🧹 This issue is being automatically closed because it has had no activity in the last 6 months. If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.