Skip to content

CLI

If you use esm, the executable must be changed from typeorm-extension to typeorm-extension-esm. The following commands are available in the terminal:

  • typeorm-extension db:create to create the database
  • typeorm-extension db:drop to drop the database
  • typeorm-extension seed:run seed the database
  • typeorm-extension seed:create to create a new seeder

If the application has not yet been built or is to be tested with ts-node, the commands can be adapted as follows:

"scripts": {
    "db:create": "ts-node ./node_modules/typeorm-extension/bin/cli.cjs db:create",
    "db:drop": "ts-node ./node_modules/typeorm-extension/bin/cli.cjs db:drop",
    "seed:run": "ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run",
    "seed:create": "ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:create"
}

To test the application in the context of an esm project, the following adjustments must be made:

  • executable ts-node to ts-node-esm
  • library path cli.cjs to cli.mjs

Read the Seeding Configuration section to find out how to specify the path, for the seeder- & factory-location.

CLI Options

OptionCommandsDefaultDescription
--root or -rdb:create, db:drop, seed:create & seed:runprocess.cwd()Root directory of the project.
--dataSource or -ddb:create, db:drop & seed:rundata-sourceName (or relative path incl. name) of the data-source file.
--synchronize or -sdb:create & db:dropyesSynchronize the database schema after database creation. Options: yes or no.
--initialDatabasedb:createundefinedSpecify the initial database to connect to. This option is only relevant for the postgres driver, which must always to connect to a database. If no database is provided, the database name will be equal to the connection user name.
--nameseed:create & seed:runundefinedName (or relative path incl. name) of the seeder.
--preserveFilePathsdb:create, db:drop, seed:create & seed:runfalseThis option indicates if file paths should be preserved and treated as if the just-in-time compilation environment is detected.