This commit is contained in:
pincman 2024-05-09 02:37:11 +08:00
parent 99401e713c
commit 011ae4b467
3 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,8 @@
import { Migrator } from '@mikro-orm/migrations'; import { Migrator } from '@mikro-orm/migrations';
import { defineConfig, Utils } from '@mikro-orm/postgresql'; import { defineConfig, Utils } from '@mikro-orm/postgresql';
import { SeedManager } from '@mikro-orm/seeder';
import { moduleImports } from '@/module.list'; import { moduleImports } from '@/module.list';
import { getEntities } from '@/modules/database/helpers'; import { getEntities } from '@/modules/database/helpers';
@ -16,5 +18,9 @@ export const database = () =>
tableName: 'migrations', tableName: 'migrations',
path: Utils.detectTsNode() ? 'src/database/migrations' : 'dist/database/migrations', path: Utils.detectTsNode() ? 'src/database/migrations' : 'dist/database/migrations',
}, },
seeder: {
path: Utils.detectTsNode() ? 'src/database/seeders' : 'dist/database/seeders',
defaultSeeder: 'DatabaseSeeder',
},
}); });
export default database(); export default database();

View File

@ -0,0 +1,10 @@
import type { EntityManager } from '@mikro-orm/core';
import { Seeder } from '@mikro-orm/seeder';
import { PostSeeder } from './PostSeeder';
export class DatabaseSeeder extends Seeder {
async run(em: EntityManager): Promise<void> {
return this.call(em, [PostSeeder]);
}
}

View File

@ -0,0 +1,6 @@
import type { EntityManager } from '@mikro-orm/core';
import { Seeder } from '@mikro-orm/seeder';
export class PostSeeder extends Seeder {
async run(em: EntityManager): Promise<void> {}
}