1"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([["27395"],{60671(e,n,t){t.r(n),t.d(n,{metadata:()=>r,default:()=>h,frontMatter:()=>a,contentTitle:()=>o,toc:()=>c,assets:()=>d});var r=JSON.parse('{"id":"seeding","title":"Seeding","description":"When initializing your application or testing it can be exhausting to create sample data for your database. The solution is to use seeding. Create factories for your entities and use them in the seed script or combine multiple seed scripts.","source":"@site/versioned_docs/version-7.2/seeding.md","sourceDirName":".","slug":"/seeding","permalink":"/docs/seeding","draft":false,"unlisted":false,"editUrl":"https://github.com/mikro-orm/mikro-orm/edit/master/docs/versioned_docs/version-7.2/seeding.md","tags":[],"version":"7.2","lastUpdatedBy":"Martin Ad\xe1mek","lastUpdatedAt":1788766630000,"frontMatter":{"title":"Seeding"},"sidebar":"docs","previous":{"title":"Migrations","permalink":"/docs/migrations"},"next":{"title":"Entity Generator","permalink":"/docs/entity-generator"}}'),s=t(74848),i=t(28453);let a={title:"Seeding"},o,d={},c=[{value:"Configuration",id:"configuration",level:2},{value:"Seeders",id:"seeders",level:2},{value:"Using entity factories",id:"using-entity-factories",level:3},{value:"Calling additional seeders",id:"calling-additional-seeders",level:3},{value:"Shared context",id:"shared-context",level:3},{value:"Entity factories",id:"entity-factories",level:2},{value:"Creating entities using factories",id:"creating-entities-using-factories",level:3},{value:"Generate multiple entities",id:"generate-multiple-entities",level:4},{value:"Overriding attributes",id:"overriding-attributes",level:4},{value:"Persisting entities",id:"persisting-entities",level:3},{value:"Factory relationships",id:"factory-relationships",level:3},{value:"Defining relations via <code>.each()</code>",id:"defining-relations-via-each",level:4},{value:"ManyToOne and OneToOne relations",id:"manytoone-and-onetoone-relations",level:4},{value:"OneToMany and ManyToMany",id:"onetomany-and-manytomany",level:4},{value:"Defining relations via <code>.definition()</code>",id:"defining-relations-via-definition",level:4},{value:"Use with CLI",id:"use-with-cli",level:2},{value:"Use in tests",id:"use-in-tests",level:2},{value:"Running seeder in production",id:"running-seeder-in-production",level:2}];function l(e){let n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h2:"h2",h3:"h3",h4:"h4",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"When initializing your application or testing it can be exhausting to create sample data for your database. The solution is to use seeding. Create factories for your entities and use them in the seed script or combine multiple seed scripts."}),"\n",(0,s.jsxs)(n.admonition,{type:"info",children:[(0,s.jsxs)(n.p,{children:["To use seeder, you need to first install ",(0,s.jsx)(n.code,{children:"@mikro-orm/seeder"}),", and register the ",(0,s.jsx)(n.code,{children:"SeedManager"})," extension in your ORM config."]}),(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",metastring:"title='mikro-orm.config.ts'",children:"import { SeedManager } from '@mikro-orm/seeder';\n\nexport default defineConfig({\n // ...\n extensions: [SeedManager],\n})\n"})})]}),"\n",(0,s.jsx)(n.h2,{id:"configuration",children:"Configuration"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.code,{children:"seeder.path"})," and ",(0,s.jsx)(n.code,{children:"seeder.pathTs"})," works the same way as ",(0,s.jsx)(n.code,{children:"entities"})," and ",(0,s.jsx)(n.code,{children:"entitiesTs"})," in entity discovery."]}),"\n"]}),"\n",(0,s.jsx)(n.p,{children:"The seeder has a few default settings that can be changed easily through the MikroORM config. Underneath, you find the configuration options with their defaults."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"MikroORM.init({\n seeder: {\n path: './seeders', // path to the folder with seeders\n pathTs: undefined, // path to the folder with TS seeders (if used, you should put path to compiled files in `path`)\n defaultSeeder: 'DatabaseSeeder', // default seeder
1class name\n glob: '!(*.d).{js,ts}', // how to match seeder files (all .js and .ts files, but not .d.ts)\n emit: 'ts', // seeder generation mode\n fileName: (className: string) => className, // seeder file naming convention\n },\n});\n"})}),"\n",(0,s.jsxs)(n.p,{children:["You can also override those options using the ",(0,s.jsx)(n.a,{href:"/docs/configuration#using-environment-variables",children:"environment variables"}),":"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"MIKRO_ORM_SEEDER_PATH"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"MIKRO_ORM_SEEDER_PATH_TS"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"MIKRO_ORM_SEEDER_EMIT"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"MIKRO_ORM_SEEDER_GLOB"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"MIKRO_ORM_SEEDER_DEFAULT_SEEDER"})}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"seeders",children:"Seeders"}),"\n",(0,s.jsxs)(n.p,{children:["A seeder class contains one method ",(0,s.jsx)(n.code,{children:"run"}),". This method is called when you use the command ",(0,s.jsx)(n.code,{children:"npx mikro-orm seeder:run"}),". In the ",(0,s.jsx)(n.code,{children:"run"})," method you define how and what data you want to insert into the database. You can create entities using the ",(0,s.jsx)(n.a,{href:"http://mikro-orm.io/docs/entity-manager",children:"EntityManager"})," or you can use ",(0,s.jsx)(n.a,{href:"#using-entity-factories",children:"Factories"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"You can create your own seeder classes using the following CLI command:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-shell",children:"npx mikro-orm seeder:create DatabaseSeeder # generates the class DatabaseSeeder\nnpx mikro-orm seeder:create test # generates the class TestSeeder\nnpx mikro-orm seeder:create project-names # generates the class ProjectNamesSeeder\n"})}),"\n",(0,s.jsxs)(n.p,{children:["This creates a new seeder class. By default, it will be generated in the ",(0,s.jsx)(n.code,{children:"./seeders/"})," directory. You can configure the directory in the config with the key ",(0,s.jsx)(n.code,{children:"seeder.path"})," or using the ",(0,s.jsx)(n.a,{href:"/docs/configuration#using-environment-variables",children:"environment variable"})," ",(0,s.jsx)(n.code,{children:"MIKRO_ORM_SEEDER_PATH"}),". You are allowed to call the ",(0,s.jsx)(n.code,{children:"seeder:create"})," command with a name, class name or hyphenated name."]}),"\n",(0,s.jsx)(n.p,{children:"As an example, let's look at a very basic seeder."}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:["Note that the ",(0,s.jsx)(n.code,{children:"EntityManager"})," available in seeders will have ",(0,s.jsx)(n.code,{children:"persistOnCreate"})," enabled (even if you explicitly disable it in the ORM config), hence calling ",(0,s.jsx)(n.code,{children:"em.create()"})," will automatically call ",(0,s.jsx)(n.code,{children:"em.persist()"})," on the created entity. If you use entity constructor instead, you need to call ",(0,s.jsx)(n.code,{children:"em.persist()"})," explicitly."]}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",metastring:'title="./database/seeder/database.seeder.ts"',children:"import { EntityManager } from '@mikro-orm/core';\nimport { Seeder } from '@mikro-orm/seeder';\nimport { Author } from './author'\n\nexport class DatabaseSeeder extends Seeder {\n\n async run(em: Entity
1Manager): Promise<void> {\n // will get persisted automatically\n const author = em.create(Author, {\n name: 'John Snow',\n email: '[email protected]'\n });\n\n // but if you would do `const author = new Author()` instead,\n // you would need to call `em.persist(author)` explicitly.\n }\n}\n"})}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:["Running a seeder from the command line or programmatically will automatically call ",(0,s.jsx)(n.code,{children:"flush"})," and ",(0,s.jsx)(n.code,{children:"clear"})," after the ",(0,s.jsx)(n.code,{children:"run"})," method has completed."]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"using-entity-factories",children:"Using entity factories"}),"\n",(0,s.jsxs)(n.p,{children:["Instead of specifying all the attributes for every entity, you can also use ",(0,s.jsx)(n.a,{href:"#entity-factories",children:"entity factories"}),". These can be used to generate large amounts of database records. Please read the ",(0,s.jsx)(n.a,{href:"#entity-factories",children:"documentation on how to define factories"})," to learn how to define your factories."]}),"\n",(0,s.jsx)(n.p,{children:"In the following example, 10 author entities are generated."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"import { EntityManager } from '@mikro-orm/core';\nimport { Seeder } from '@mikro-orm/seeder';\nimport { AuthorFactory } from '../factories/author.factory'\n\nexport class DatabaseSeeder extends Seeder {\n\n async run(em: Entity
1Manager): Promise<void> {\n new AuthorFactory(em).make(10);\n }\n}\n"})}),"\n",(0,s.jsx)(n.h3,{id:"calling-additional-seeders",children:"Calling additional seeders"}),"\n",(0,s.jsxs)(n.p,{children:["Inside the ",(0,s.jsx)(n.code,{children:"run"})," method you can specify other seeder classes. You can use the ",(0,s.jsx)(n.code,{children:"call"})," method to break up the database seeder into multiple files to prevent a seeder file from becoming too large. The ",(0,s.jsx)(n.code,{children:"call"})," method requires an ",(0,s.jsx)(n.code,{children:"em"})," and an array of seeder classes."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"import { EntityManager } from '@mikro-orm/core';\nimport { Seeder } from '@mikro-orm/seeder';\nimport { AuthorSeeder, BookSeeder } from '../seeders'\n\nexport class DatabaseSeeder extends Seeder {\n\n run(em: EntityManager): Promise<void> {\n return this.call(em, [\n AuthorSeeder,\n BookSeeder,\n ]);\n }\n}\n"})}),"\n",(0,s.jsx)(n.h3,{id:"shared-context",children:"Shared context"}),"\n",(0,s.jsxs)(n.p,{children:["Often you might want to generate entities that are referencing other entities, created by other seeders. For that you can use the shared context object provided in the second parameter or ",(0,s.jsx)(n.code,{children:"run"})," method. It is automatically created when using ",(0,s.jsx)(n.code,{children:"this.call()"})," and passed down to each seeder's ",(0,s.jsx)(n.code,{children:"run"})," method. Let's see how the ",(0,s.jsx)(n.code,{children:"AuthorSeeder"})," and ",(0,s.jsx)(n.code,{children:"BookSeeder"})," from previous example could look like:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"export class AuthorSeeder extends Seeder {\n async run(em: Entity
1Manager, context: Dictionary): Promise<void> {\n // save the entity to the context\n context.author = em.create(Author, {\n name: '...',\n email: '...',\n });\n }\n}\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"export class BookSeeder extends Seeder {\n async run(em: EntityManager, context: Dictionary): Promise<void> {\n em.create(Book, {\n title: '...',\n author: context.author, // use the entity from context\n });\n }\n}\n"})}),"\n",(0,s.jsx)(n.h2,{id:"entity-factories",children:"Entity factories"}),"\n",(0,s.jsxs)(n.p,{children:["When testing you may insert entities in the database before starting a test. Instead of specifying every attribute of every entity by hand, you could also use a ",(0,s.jsx)(n.code,{children:"Factory"})," to define a set of default attributes for an entity using entity factories."]}),"\n",(0,s.jsxs)(n.p,{children:["Let's have a look at an example factory for an ",(0,s.jsx)(n.a,{href:"http://mikro-orm.io/docs/defining-entities",children:"Author entity"}),"."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"import { Factory } from '@mikro-orm/seeder';\nimport { faker } from '@faker-js/faker';\nimport { Author } from './entities/author.entity';\n\nexport class AuthorFactory extends Factory<Author> {\n model = Author;\n\n definition(): Partial<Author> {\n return {\n name: faker.person.findName(),\n email: faker.internet.email(),\n age: faker.random.number(18, 99),\n };\n }\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["Here you extend the base ",(0,s.jsx)(n.code,{children:"Factory"})," class, define a ",(0,s.jsx)(n.code,{children:"model"})," property and a ",(0,s.jsx)(n.code,{children:"definition"})," method. The ",(0,s.jsx)(n.code,{children:"model"})," defines for which entity the factory generates entity instances. The ",(0,s.jsx)(n.code,{children:"definition"})," method returns the default set of attribute values that should be applied when creating an entity using the factory."]}),"\n",(0,s.jsxs)(n.p,{children:["In this example, a library called ",(0,s.jsx)(n.a,{href:"https://github.com/faker-js/faker",children:"Faker"})," is used, which allows you to conveniently generate various kinds of random data for testing."]}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsx)(n.p,{children:"Since v6, Faker is no longer re-exported from the seeder package and needs to be installed separately."}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"creating-entities-using-factories",children:"Creating entities using factories"}),"\n",(0,s.jsxs)(n.p,{children:["Once you define your factories, you can use them to generate entities. Import the factory, instantiate it and call the ",(0,s.jsx)(n.code,{children:"makeOne"})," method:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"const author = new AuthorFactory(orm.em).makeOne();\n"})}),"\n",(0,s.jsx)(n.h4,{id:"generate-multiple-entities",children:"Generate multiple entities"}),"\n",(0,s.jsxs)(n.p,{children:["Generate multiple entities by calling the ",(0,s.jsx)(n.code,{children:"make"})," method. The parameter of the ",(0,s.jsx)(n.code,{children:"make"})," method is the number of entities you generate."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"// Generate 5 authors\nconst authors = new AuthorFactory(orm.em).make(5);\n"})}),"\n",(0,s.jsx)(n.h4,{id:"overriding-attributes",children:"Overriding attributes"}),"\n",(0,s.jsxs)(n.p,{children:["If you would like to override some of the default values of your factories, you may pass an object to the ",(0,s.jsx)(n.code,{children:"make"})," method. Only the specified attributes will be replaced while the rest of the attributes remain set to their default values as specified by the factory."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"// Make a single author\nconst author = new AuthorFactory(orm.em).makeOne({\n name: 'John Snow',\n});\n\n// Make 5 authors\nconst authors = new AuthorFactory(orm.em).make(5, {\n name: 'John Snow',\n});\n"})}),"\n",(0,s.jsx)(n.h3,{id:"persisting-entities",children:"Persisting entities"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"create"})," method instantiates entities and persists them to the database using ",(0,s.jsx)(n.code,{children:"persist"})," and ",(0,s.jsx)(n.code,{children:"flush"})," on the EntityManager."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"// Make and persist a single author\nconst author = await new AuthorFactory(orm.em).createOne();\n\n// Make and persist 5 authors\nconst authors = await new AuthorFactory(orm.em).create(5);\n"})}),"\n",(0,s.jsxs)(n.p,{children:["You can override the default values of your factories by passing an object to the ",(0,s.jsx)(n.code,{children:"create"})," method."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"// Make and persist a single author\nconst author = await new AuthorFactory(orm.em).createOne({\n name: 'John Snow',\n});\n\n// Make and persist a 5 authors\nconst authors = await new AuthorFactory(orm.em).create(5, {\n name: 'John Snow',\n});\n"})}),"\n",(0,s.jsx)(n.h3,{id:"factory-relationships",children:"Factory relationships"}),"\n",(0,s.jsx)(n.p,{children:"It is nice to create large quantities of data for one entity, but most of the time you will want to create data for multiple entities and also have relations between them."}),"\n",(0,s.jsxs)(n.h4,{id:"defining-relations-via-each",children:["Defining relations via ",(0,s.jsx)(n.code,{children:".each()"})]}),"\n",(0,s.jsxs)(n.p,{children:["For that you can use the ",(0,s.jsx)(n.code,{children:"each"})," method which can be chained on a factory. The ",(0,s.jsx)(n.code,{children:"each"})," method can be called with a function that transforms output entity from the factory before returning it. Let's look at some examples of the different relations."]}),"\n",(0,s.jsx)(n.h4,{id:"manytoone-and-onetoone-relations",children:"ManyToOne and OneToOne relations"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"const books: Book[] = new BookFactory(orm.em).each(book => {\n book.author = new AuthorFactory(orm.em).makeOne();\n}).make(5);\n"})}),"\n",(0,s.jsx)(n.h4,{id:"onetomany-and-manytomany",children:"OneToMany and ManyToMany"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"const books: Book[] = new BookFactory(orm.em).each(book => {\n book.owners.set(new OwnerFactory(orm.em).make(5));\n}).make(5);\n"})}),"\n",(0,s.jsxs)(n.h4,{id:"defining-relations-via-definition",children:["Defining relations via ",(0,s.jsx)(n.code,{children:".definition()"})]}),"\n",(0,s.jsxs)(n.p,{children:["Alternatively you can build the nested entities inside of the ",(0,s.jsx)(n.code,{children:"definition"})," method. If needed, this method can accept additional params that need not to be a part of the entity schema."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"export class AuthorFactory extends Factory<\n AuthorEntity,\n EntityData<AuthorEntity> & { booksCount?: number }\n> {\n model = AuthorEntity;\n\n async definition(\n params?: EntityData<AuthorEntity> & { booksCount?: number }\n ): EntityData<AuthorEntity> {\n const name = params.name ?? faker.person.findName();\n const books = params.books ?? (\n [...Array(params?.booksCount ?? 0)].map((v, i) =>\n new BookFactory(this.em).makeEntity({\n title: `${name} Trilogy - Part ${i + 1}`\n })\n )\n );\n return {\n ...params,\n name,\n books\n };\n }\n}\n\n// Finally\nnew AuthorFactory(em).createOne({ booksCount: 4 })\n"})}),"\n",(0,s.jsx)(n.h2,{id:"use-with-cli",children:"Use with CLI"}),"\n",(0,s.jsxs)(n.p,{children:["You may execute the ",(0,s.jsx)(n.code,{children:"seeder:run"})," MikroORM CLI command to seed your database. By default, the ",(0,s.jsx)(n.code,{children:"seeder:run"})," command runs the ",(0,s.jsx)(n.code,{children:"DatabaseSeeder"})," class, which may in turn invoke other seed classes. You can configure the default seeder using the key ",(0,s.jsx)(n.code,{children:"seeder.defaultSeeder"})," or using the ",(0,s.jsx)(n.a,{href:"/docs/configuration#using-environment-variables",children:"environment variable"})," ",(0,s.jsx)(n.code,{children:"MIKRO_ORM_SEEDER_DEFAULT_SEEDER"}),". You can also use the ",(0,s.jsx)(n.code,{children:"--class"})," option to specify a seeder class:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-shell",metastring:"script",children:"npx mikro-orm seeder:run\n\nnpx mikro-orm seeder:run --class=BookSeeder\n"})}),"\n",(0,s.jsxs)(n.p,{children:["You may also seed your database using the ",(0,s.jsx)(n.a,{href:"/docs/migrations#using-via-cli",children:(0,s.jsx)(n.code,{children:"migrate:fresh"})})," or ",(0,s.jsx)(n.a,{href:"/docs/schema-generator",children:(0,s.jsx)(n.code,{children:"schema:fresh"})})," command in combination with the ",(0,s.jsx)(n.code,{children:"--seed"})," option, which will drop all tables and re-run all of your migrations or generate the database based on the current entities. This command is useful for completely re-building your database:"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-shell",metastring:"script",children:"npx mikro-orm migration:fresh --seed # will drop the database, run all migrations and the DatabaseSeeder class\n\nnpx mikro-orm schema:fresh --seed # will recreate the database and run the DatabaseSeeder class\n"})}),"\n",(0,s.jsxs)(n.p,{children:["If you do not want to run the ",(0,s.jsx)(n.code,{children:"DatabaseSeeder"}
1)," class you can either specify what the default seeder class should be. This can be done by changing the ",(0,s.jsx)(n.a,{href:"/docs/configuration#seeder",children:"default settings"}),". Another option is to explicitly define the seeder class you want to run."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-shell",metastring:"script",children:"npx mikro-orm migration:fresh --seed TestSeeder # will drop the database, run all migrations and the TestSeeder class\n\nnpx mikro-orm schema:fresh --seed ProjectsSeeder # will recreate the database and run the ProjectsSeeder class\n"})}),"\n",(0,s.jsx)(n.h2,{id:"use-in-tests",children:"Use in tests"}),"\n",(0,s.jsx)(n.p,{children:"Now you know how to create seeders and factories, but how can you effectively use them in tests? Let's take a look at the following example:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"let orm: MikroORM;\n\nbeforeAll(async () => {\n // Initialize the ORM\n orm = await MikroORM.init({ ... });\n \n // Refresh the database to start clean\n await orm.schema.refresh();\n\n // And run the seeder afterwards\n await orm.seeder.seed(DatabaseSeeder);\n});\n\ntest(() => {\n // Do tests\n});\n\nafterAll(async () => {\n // Close connection\n await orm.close();\n});\n"})}),"\n",(0,s.jsx)(n.h2,{id:"running-seeder-in-production",children:"Running seeder in production"}),"\n",(0,s.jsx)(n.p,{children:"In a production environment, you might want to use compiled seeder files. All you need to do is to configure the seeder path accordingly in your ORM config:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-ts",children:"import { MikroORM, Utils } from '@mikro-orm/core';\n\nawait MikroORM.init({\n seeder: {\n path: 'dist/seeders',\n pathTs: 'src/seeders',\n },\n // or alternatively\n // seeder: {\n // path: Utils.detectTypeScriptSupport() ? 'src/seeders' : 'dist/seeders',\n // },\n // ...\n});\n"})}),"\n",(0,s.jsx)(n.p,{children:"This should allow using CLI to generate TS seeder files (as in CLI we probably have TS support enabled), while using compiled JS files in production."})]})}function h(e={}){let{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},28453(e,n,t){t.d(n,{R:()=>a,x:()=>o});var r=t(96540);let s={},i=r.createContext(s);function a(e){let n=r.useContext(i);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),r.createElement(i.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.