docs: update cli related docs (#9659)

- remove cli.entitiesDir description
- remove cli.subscribersDir description
- remove cli from Data Source Options example
- extend migration:run examples with -- -d path-to-datasource-config
- extend migration:revert examples with -- -d path-to-datasource-config
- extend migration:show examples with -- -d path-to-datasource-config
- extend migration:create examples with path-to-migrations-dir/migrationName

Co-authored-by: Stefan <stefi@sprintingsoftware.com>
This commit is contained in:
StefanZivkovic 2023-02-07 08:34:37 +01:00 committed by GitHub
parent d2f37f6e72
commit c418aae39a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 103 deletions

View File

@ -97,10 +97,6 @@ Different RDBMS-es have their own specific options.
- `cache` - Enables entity result caching. You can also configure cache type and other cache options here.
Read more about caching [here](caching.md).
- `cli.entitiesDir` - Directory where entities should be created by default by CLI.
- `cli.subscribersDir` - Directory where subscribers should be created by default by CLI.
## `mysql` / `mariadb` data source options
- `url` - Connection url where perform connection to. Please note that other data source options will override parameters set from url.
@ -553,11 +549,6 @@ Here is a small example of data source options for mysql:
],
migrations: [
"migration/*.js"
],
cli: {
entitiesDir: "entity",
migrationsDir: "migration",
subscribersDir: "subscriber"
}
]
}
```

View File

@ -137,7 +137,7 @@ export class PostRefactoringTIMESTAMP implements MigrationInterface {
Once you have a migration to run on production, you can run them using a CLI command:
```
typeorm migration:run
typeorm migration:run -- -d path-to-datasource-config
```
**`typeorm migration:create` and `typeorm migration:generate` will create `.ts` files, unless you use the `o` flag (see more in [Generating migrations](#generating-migrations)). The `migration:run` and `migration:revert` commands only work on `.js` files. Thus the typescript files need to be compiled before running the commands.** Alternatively you can use `ts-node` in conjunction with `typeorm` to run `.ts` migration files.
@ -145,13 +145,13 @@ typeorm migration:run
Example with `ts-node`:
```
npx typeorm-ts-node-commonjs migration:run
npx typeorm-ts-node-commonjs migration:run -- -d path-to-datasource-config
```
Example with `ts-node` in ESM projects:
```
npx typeorm-ts-node-esm migration:run
npx typeorm-ts-node-esm migration:run -- -d path-to-datasource-config
```
```
@ -165,7 +165,7 @@ That's all! Now you have your database schema up-to-date.
If for some reason you want to revert the changes, you can run:
```
typeorm migration:revert
typeorm migration:revert -- -d path-to-datasource-config
```
This command will execute `down` in the latest executed migration.

View File

@ -60,13 +60,7 @@ If you want to load more modules like [module-alias](https://github.com/ilearnio
Then you may run the command like this:
```
npm run typeorm migration:run
```
If you need to pass parameter with dash to npm script, you will need to add them after --. For example, if you need to _generate_, the command is like this:
```
npm run typeorm migration:generate -- -n migrationNameHere
npm run typeorm migration:run -- -d path-to-datasource-config
```
### How to read the documentation
@ -131,27 +125,7 @@ typeorm init --docker
You can create a new entity using CLI:
```
typeorm entity:create -n User
```
where `User` is an entity file and class name.
Running the command will create a new empty entity in `entitiesDir` of the project.
To set up the `entitiesDir` of the project you must add it in data source options:
```
{
cli: {
entitiesDir: "src/entity"
}
}
```
Learn more about [data source options](./data-source-options.md).
If you have a multi-module project structure with multiple entities in different directories
you can provide the path to the CLI command where you want to generate an entity:
```
typeorm entity:create -n User -d src/user/entity
typeorm entity:create path-to-entity-dir/entity
```
Learn more about [entities](./entities.md).
@ -161,27 +135,7 @@ Learn more about [entities](./entities.md).
You can create a new subscriber using CLI:
```
typeorm subscriber:create -n UserSubscriber
```
where `UserSubscriber` is a subscriber file and class name.
Running the following command will create a new empty subscriber in the `subscribersDir` of the project.
To setup `subscribersDir` you must add it in data source options:
```
{
cli: {
subscribersDir: "src/subscriber"
}
}
```
Learn more about [data source options](./data-source-options.md).
If you have a multi-module project structure with multiple subscribers in different directories
you can provide a path to the CLI command where you want to generate a subscriber:
```
typeorm subscriber:create -n UserSubscriber -d src/user/subscriber
typeorm subscriber:create path-to-subscriber-dir/subscriber
```
Learn more about [Subscribers](./listeners-and-subscribers.md).
@ -191,29 +145,8 @@ Learn more about [Subscribers](./listeners-and-subscribers.md).
You can create a new migration using CLI:
```
typeorm migration:create -n UserMigration
typeorm migration:create path-to-migrations-dir/migrationName
```
where `UserMigration` is a migration file and class name.
Running the command will create a new empty migration in the `migrationsDir` of the project.
To setup `migrationsDir` you must add it in data source options:
```
{
cli: {
migrationsDir: "src/migration"
}
}
```
Learn more about [data source options](./data-source-options.md).
If you have a multi-module project structure with multiple migrations in different directories
you can provide a path to the CLI command where you want to generate a migration:
```
typeorm migration:create -n UserMigration -d src/user/migration
```
Learn more about [Migrations](./migrations.md).
## Generate a migration from existing table schema
@ -238,7 +171,7 @@ Learn more about [Migrations](./migrations.md).
To execute all pending migrations use following command:
```
typeorm migration:run
typeorm migration:run -- -d path-to-datasource-config
```
Learn more about [Migrations](./migrations.md).
@ -248,7 +181,7 @@ Learn more about [Migrations](./migrations.md).
To revert the most recently executed migration use the following command:
```
typeorm migration:revert
typeorm migration:revert -- -d path-to-datasource-config
```
This command will undo only the last executed migration.
@ -260,7 +193,7 @@ Learn more about [Migrations](./migrations.md).
To show all migrations and whether they've been run or not use following command:
```
typeorm migration:show
typeorm migration:show -- -d path-to-datasource-config
```
[X] = Migration has been ran
@ -292,7 +225,7 @@ typeorm schema:log
To completely drop a database schema use:
```
typeorm schema:drop
typeorm schema:drop -- -d path-to-datasource-config
```
Be careful with this command on production since it completely removes data from your database.

View File

@ -420,11 +420,6 @@
],
migrations: [
"migration/*.js"
],
cli: {
entitiesDir: "entity",
migrationsDir: "migration",
subscribersDir: "subscriber"
}
]
}
```

View File

@ -77,7 +77,7 @@ TypeORM 提供了一个可以编写此类 SQL 查询并在需要时运行它们
设置连接选项后,可以使用 CLI 创建新的迁移:
```
typeorm migration:create -n PostRefactoring
typeorm migration:create path-to-migrations-dir/migrationName
```
要使用 CLI 命令,需要全局安装 typeorm`npm i typeorm -g`)。
@ -130,7 +130,7 @@ export class PostRefactoringTIMESTAMP implements MigrationInterface {
迁移到生产后,可以使用 CLI 命令运行它们:
```
typeorm migration:run
typeorm migration:run -- -d path-to-datasource-config
```
**`typeorm migrationcreate``typeorm migrationgenerate`将创建`.ts`文件。 `migrationrun``migrationrevert`命令仅适用于`.js`文件。 因此,在运行命令之前需要编译 typescript 文件。**或者你可以使用`ts-node``typeorm`来运行`.ts`迁移文件。
@ -138,7 +138,7 @@ typeorm migration:run
`ts-node`的示例:
```
npx typeorm-ts-node-commonjs migration:run
npx typeorm-ts-node-commonjs migration:run -- -d path-to-datasource-config
```
此命令将执行所有挂起的迁移,并按其时间戳排序的顺序运行它们。
@ -148,7 +148,7 @@ npx typeorm-ts-node-commonjs migration:run
如果由于某种原因你想要还原更改,则可以运行:
```
typeorm migration:revert
typeorm migration:revert -- -d path-to-datasource-config
```
该命令将在最近执行的迁移中执行`down`

View File

@ -161,7 +161,7 @@ typeorm subscriber:create -n UserSubscriber -d src/user/subscriber
你可以使用 CLI 创建新的迁移:
```
typeorm migration:create -n UserMigration
typeorm migration:create path-to-migrations-dir/migrationName
```
其中`UserMigration`是一个迁移文件和类名。
@ -180,7 +180,7 @@ typeorm migration:create -n UserMigration
如果你有一个在不同目录中具有多个迁移的多模块结构的项目,则可以提供要生成迁移的 CLI 命令的路径:
```
typeorm migration:create -n UserMigration -d src/user/migration
typeorm migration:create path-to-migrations-dir/migrationName
```
了解有关[Migrations](./migrations.md)的更多信息。
@ -212,7 +212,7 @@ typeorm migration:run
要还原最近执行的迁移,请使用以下命令:
```
typeorm migration:revert
typeorm migration:revert -- -d path-to-datasource-config
```
此命令将仅撤消上次执行的迁移。
@ -242,7 +242,7 @@ typeorm schema:log
要完全删除数据库架构,请使用以下命令:
```
typeorm schema:drop
typeorm schema:drop -- -d path-to-datasource-config
```
在生产环境时要谨慎使用这个命令,因为它会完全删除数据库中的数据。