Skip to content

Commit

Permalink
Docs and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovepixelart committed Sep 18, 2022
1 parent f33afe8 commit 2c09c58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ yarn migrate help
npm exec migrate help
```

```text
CLI migration tool for mongoose
Options:
-f, --config-path <path> path to the config file (default: "migrate")
-d, --uri <string> mongo connection string
-c, --collection <string> collection name to use for the migrations (default: "migrations")
-a, --autosync <boolean> automatically sync new migrations without prompt (default: false)
-m, --migrations-path <path> path to the migration files (default: "./migrations")
-t, --template-path <path> template file to use when creating a migration
-cd, --change-dir <path> change current working directory before running anything
-h, --help display help for command
Commands:
list list all migrations
create <migration-name> create a new migration file
up [migration-name] run all migrations or a specific migration if name provided
down <migration-name> roll back migrations down to given name
prune delete extraneous migrations from migration folder or database
help [command] display help for command
```

- More examples

```bash
Expand Down
26 changes: 13 additions & 13 deletions src/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,52 +73,52 @@ export class Migrate {
this.program = new Command()
this.program
.name('migrate')
.description('A cli based migration tool for mongoose')
.option('-f, --config-path <path>', 'Path to the config file', 'migrate')
.option('-d, --uri <string>', 'MongoDB connection string URI')
.option('-c, --collection <string>', 'The collection to use for the migrations', 'migrations')
.option('-a, --autosync <boolean>', 'Automatically add new migrations in the migrations folder to the database instead of asking interactively', false)
.option('-m, --migrations-path <path>', 'The path to the migration files', './migrations')
.option('-t, --template-path <path>', 'The template file to use when creating a migration')
.option('-cd, --change-dir <path>', 'Change current working directory before running anything')
.description('CLI migration tool for mongoose'.cyan)
.option('-f, --config-path <path>', 'path to the config file', 'migrate')
.option('-d, --uri <string>', 'mongo connection string'.yellow)
.option('-c, --collection <string>', 'collection name to use for the migrations', 'migrations')
.option('-a, --autosync <boolean>', 'automatically sync new migrations without prompt', false)
.option('-m, --migrations-path <path>', 'path to the migration files', './migrations')
.option('-t, --template-path <path>', 'template file to use when creating a migration')
.option('-cd, --change-dir <path>', 'change current working directory before running anything')
.hook('preAction', async () => {
const opts = this.program.opts()
this.migrator = await getMigrator(opts)
})

this.program
.command('list')
.description('List all migrations')
.description('list all migrations')
.action(async () => {
console.log('Listing migrations'.cyan)
await this.migrator.list()
})

this.program
.command('create <migration-name>')
.description('Creates a new migration file')
.description('create a new migration file')
.action(async (migrationName) => {
await this.migrator.create(migrationName)
console.log('Migration created. Run ' + `migrate up ${migrationName}`.cyan + ' to apply the migration')
})

this.program
.command('up [migration-name]')
.description('Run all migrations or a specific migration')
.description('run all migrations or a specific migration if name provided')
.action(async (migrationName) => {
await this.migrator.run('up', migrationName)
})

this.program
.command('down <migration-name>')
.description('Rolls back migrations down to given name (if down function was provided)')
.description('roll back migrations down to given name')
.action(async (migrationName) => {
await this.migrator.run('down', migrationName)
})

this.program
.command('prune')
.description('Allows you to delete extraneous migrations by removing extraneous local migration files/database migrations')
.description('delete extraneous migrations from migration folder or database')
.action(async () => {
await this.migrator.prune()
})
Expand Down

0 comments on commit 2c09c58

Please sign in to comment.