Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-update README.md about CLI usage and commands #111

Merged
merged 4 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 142 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,45 +38,168 @@ This utility uses [Knex](http://knexjs.org/) under the hood so these are the [su

You can use `sync-db` both as a CLI utility and programmatically.

### CLI
<!-- usage -->

```sh-session
$ npm install -g @leapfrogtechnology/sync-db
$ sync-db COMMAND
running command...
$ sync-db (-v|--version|version)
@leapfrogtechnology/sync-db/1.0.0-beta.9 darwin-x64 node-v12.20.1
$ sync-db --help [COMMAND]
USAGE
$ sync-db COMMAND
...
```

<!-- usagestop -->

## Commands

When installed globally, you can invoke the CLI directly.

The CLI exposes a single command `sync-db` that runs synchronize operation based on your [configuration](#configuration).

**CLI Options**
<!-- commands -->

Below shown are the available CLI options , which is also the output printed by `sync-db --help`.
- [`sync-db`](#sync-db-)
- [`sync-db help [COMMAND]`](#sync-db-help-command)
- [`sync-db make NAME`](#sync-db-make-name)
- [`sync-db migrate-latest`](#sync-db-migrate-latest)
- [`sync-db migrate-list`](#sync-db-migrate-list)
- [`sync-db migrate-rollback`](#sync-db-migrate-rollback)
- [`sync-db prune`](#sync-db-prune)
- [`sync-db synchronize`](#sync-db-synchronize)

```bash
Synchronize database
## `sync-db`

```
USAGE
$ sync-db
```

_See code: [src/commands/index.ts](https://github.com/leapfrogtechnology/sync-db/blob/v1.0.0-beta.9/src/commands/index.ts)_

## `sync-db help [COMMAND]`

display help for sync-db

```
USAGE
$ sync-db help [COMMAND]

ARGUMENTS
COMMAND command to show help for

OPTIONS
--all see all commands in CLI
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2/src/commands/help.ts)_

## `sync-db make NAME`

Make migration files from the template.

```
USAGE
$ sync-db make NAME

ARGUMENTS
NAME Object or filename to generate.

OPTIONS
-t, --type=TYPE [default: migration] Type of file to generate.
```

_See code: [src/commands/make.ts](https://github.com/leapfrogtechnology/sync-db/blob/v1.0.0-beta.9/src/commands/make.ts)_

## `sync-db migrate-latest`

Run the migrations up to the latest changes.

```
USAGE
$ sync-db migrate-latest

OPTIONS
--connection-resolver=PATH Path to the connection resolver.
--dry-run Dry run migration.
--only=CONNECTION_ID Filter only a single connection.
```

_See code: [src/commands/migrate-latest.ts](https://github.com/leapfrogtechnology/sync-db/blob/v1.0.0-beta.9/src/commands/migrate-latest.ts)_

## `sync-db migrate-list`

List all the migrations.

```
USAGE
$ sync-db migrate-list

OPTIONS
--connection-resolver=PATH Path to the connection resolver.
--only=CONNECTION_ID Filter only a single connection.
```

_See code: [src/commands/migrate-list.ts](https://github.com/leapfrogtechnology/sync-db/blob/v1.0.0-beta.9/src/commands/migrate-list.ts)_

## `sync-db migrate-rollback`

Rollback migrations up to the last run batch.

```
USAGE
$ sync-db migrate-rollback

OPTIONS
--connection-resolver=PATH Path to the connection resolver.
--dry-run Dry run rollback.
--only=CONNECTION_ID Filter only a single connection.
```

_See code: [src/commands/migrate-rollback.ts](https://github.com/leapfrogtechnology/sync-db/blob/v1.0.0-beta.9/src/commands/migrate-rollback.ts)_

## `sync-db prune`

Drop all the synchronized db objects except the ones created via migrations.

```
USAGE
$ sync-db prune

OPTIONS
--connection-resolver=PATH Path to the connection resolver.
--dry-run Dry run prune.
--only=CONNECTION_ID Filter only a single connection.
```

_See code: [src/commands/prune.ts](https://github.com/leapfrogtechnology/sync-db/blob/v1.0.0-beta.9/src/commands/prune.ts)_

## `sync-db synchronize`

Synchronize all the configured database connections.

```
USAGE
$ sync-db synchronize

OPTIONS
-h, --help Print help information
-v, --version Print version

COMMANDS
make Make migration files from the template.
migrate-latest Run the migrations up to the latest changes.
migrate-list List all the migrations.
migrate-rollback Rollback migrations up to the last run batch.
prune Drop all the synchronized db objects except the ones created via migrations.
synchronize Synchronize all the configured database connections.

FLAGS
-f, --force Force synchronization.
--connection-resolver=PATH Path to the connection resolver.
--dry-run Dry run synchronization.
--only=CONNECTION_ID Filter only a single connection.
--skip-migration Skip running migrations.
--dry-run Dry run migrations and synchronization.
```

_See code: [src/commands/synchronize.ts](https://github.com/leapfrogtechnology/sync-db/blob/v1.0.0-beta.9/src/commands/synchronize.ts)_

<!-- commandsstop -->

Refer to the [examples](#examples) section below for full example with CLI usage.

### Programmatic Usage
## Programmatic Usage

You may use programmatic API as shown below in case you need better flexibility based on your needs.

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
},
"oclif": {
"bin": "sync-db",
"commands": "./lib/commands"
"commands": "./lib/commands",
"plugins": [
"@oclif/plugin-help"
]
},
"repository": "https://github.com/leapfrogtechnology/sync-db",
"homepage": "https://github.com/leapfrogtechnology/sync-db",
Expand Down Expand Up @@ -48,7 +51,8 @@
"changelog": "./release.sh changelog",
"release": "./release.sh bump",
"format": "prettier --write . '**/*.{ts,js,md,yaml,json}'",
"format:check": "prettier --check . '**/*.{ts,js,md,yaml,json}'"
"format:check": "prettier --check . '**/*.{ts,js,md,yaml,json}'",
"doc:cli": "oclif-dev readme && prettier --write README.md"
},
"dependencies": {
"@oclif/command": "^1",
Expand All @@ -65,6 +69,7 @@
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@oclif/dev-cli": "^1.26.0",
"@oclif/test": "^1",
"@oclif/tslint": "^3",
"@types/chai": "^4.2.7",
Expand Down
6 changes: 5 additions & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ compare_and_release() {
fi

if [ "$NEXT" != "false" ]; then
# Update CHANGELOG.md
changelog

# Update commands and usage of CLI in README.md
yarn doc:update

git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis CI"

git add CHANGELOG.md
git add CHANGELOG.md README.md
git commit -v -m "${NEXT} Release :tada: :fireworks: :bell:" -m "[skip ci]"

git remote rm origin
Expand Down
Loading