Skip to content

Commit

Permalink
Merge branch 'master' into v5.0.0-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 committed Nov 29, 2021
2 parents d37054a + 7fbca07 commit 64691cf
Show file tree
Hide file tree
Showing 14 changed files with 973 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"reporter": "lcovonly"
}
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
coverage/
7 changes: 6 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ jobs:
run: sleep 10

- name: Test
run: npm test
run: npm run cover

- name: Stop databases
run: docker-compose down

- name: Publish to coveralls.io
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
.eslintcache
coverage
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 5.0.0
### Unreleased
* (**Breaking**) Node.js 12 or later required
* (**Breaking**) Removed option -t, --detect-version-conflicts. Conflicts are now always detected.
* (**Breaking**) Target postgrator 5.x.x
* (**Breaking**) Migrate to using cosmiconfig for configuration file
* (**Breaking**) `secure` option is now `ssl` and it works differently for each supported driver
* Add support for node 16.x.x
* Support merging cli and config file options

## 4.0.0
### May, 17, 2020
* (**Breaking**) Node.js 10 or later required
Expand Down
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Postgrator CLI

[![Build Status][build-badge]][build]
[![npm package][npm-badge]][npm]
[![Coverage Status][coveralls-badge]][coveralls]
[![Dependency Status][dependency-status-badge]][dependency-status]
[![devDependency Status][dev-dependency-status-badge]][dev-dependency-status]

Command line SQL database migration tool using SQL scripts. For PostgreSQL, MySQL and SQL Server.

Version control your SQL database using plain old SQL files.
Expand Down Expand Up @@ -92,7 +98,7 @@ You can specify all the parameters from command line (see below) but the easiest

```
{
"migrationDirectory": "migrations",
"migrationPattern": "migrations/*",
"driver": "pg",
"host": "127.0.0.1",
"port": 5432,
Expand Down Expand Up @@ -123,16 +129,17 @@ postgrator [[--to=]<version>] --database=<db> [--driver=<driver>] [--host=<host>

```
--to version Version number of the file to migrate to or 'max'. Default: 'max'
-r, --driver pg|mysql|mssql Database driver. Default: 'pg'
-h, --host hostname Host. Default: '127.0.0.1'
-o, --port port Host. Default: '5432'
-d, --database database Database name
-u, --username database Username
-p, --password password Password
-m, --migration-directory directory A directory to run migration files from. Default: 'migrations''
-r, --driver pg|mysql|mssql Database driver. Default: 'pg'.
-h, --host hostname Host.
-o, --port port Port.
-d, --database database Database name.
-u, --username database Username.
-p, --password password Password. If parameter without value is given, password will be asked.
-m, --migration-pattern pattern A pattern matching files to run migration files from. Default: 'migrations/*'
-t --schema-table Table created to track schema version.
-c --validate-checksum Validates checksum of existing SQL migration files already run prior to executing migrations.
--validate-checksum Validates checksum of existing SQL migration files already run prior to executing migrations.
-s, --ssl Enables ssl connections. When using the mysql driver it expects a string containing name of ssl profile.
-c, --config Explicitly set the location of the config file to load.
--no-config Do not load options from a configuration file.
-v, --version Print version.
-?, --help Print this usage guide.
Expand All @@ -148,7 +155,19 @@ Examples
```

## Tests
To run postgrator tests locally, you'll need:
- A [postgreSQL](http://www.postgresql.org/download/) instance running on default port (5432), with a `postgrator` (password `postgrator`) account and a `postgrator` database
To run postgrator tests locally, run `docker-compose up` and then `npm test`.

[build-badge]: https://img.shields.io/github/workflow/status/MattiLehtinen/postgrator-cli/test/master?style=flat-square
[build]: https://github.com/MattiLehtinen/postgrator-cli/actions

[npm-badge]: https://img.shields.io/npm/v/postgrator-cli.svg?style=flat-square
[npm]: https://www.npmjs.org/package/postgrator-cli

[coveralls-badge]: https://img.shields.io/coveralls/MattiLehtinen/postgrator-cli/master.svg?style=flat-square
[coveralls]: https://coveralls.io/r/MattiLehtinen/postgrator-cli

[dependency-status-badge]: https://david-dm.org/MattiLehtinen/postgrator-cli.svg?style=flat-square
[dependency-status]: https://david-dm.org/MattiLehtinen/postgrator-cli

then run `npm test`
[dev-dependency-status-badge]: https://david-dm.org/MattiLehtinen/postgrator-cli/dev-status.svg?style=flat-square
[dev-dependency-status]: https://david-dm.org/MattiLehtinen/postgrator-cli#info=devDependencies
35 changes: 19 additions & 16 deletions lib/command-line-options.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint max-len: 0 */

import commandLineArgs from 'command-line-args';
import { readFileSync } from 'fs';
import commandLineArgs from 'command-line-args';

const pjson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url)));

Expand All @@ -19,45 +19,48 @@ const optionDefinitions = (defaults = {}) => [
alias: 'r', type: String, typeLabel: 'pg|mysql|mssql', defaultValue: defaults.driver || 'pg',
},
{
name: 'host', description: "Host. Default: '127.0.0.1'",
alias: 'h', type: String, typeLabel: '{underline hostname}', defaultValue: defaults.host || '127.0.0.1',
name: 'host', description: 'Host.',
alias: 'h', type: String, typeLabel: '{underline hostname}',
...defaults.host && { defaultValue: defaults.host },
},
{
name: 'port', description: "Host. Default: '5432'",
alias: 'o', type: Number, typeLabel: '{underline port}', defaultValue: defaults.port || '5432',
name: 'port', description: 'Port.',
alias: 'o', type: Number, typeLabel: '{underline port}',
...defaults.port && { defaultValue: defaults.port },
},
{
name: 'database', description: 'Database name',
alias: 'd', type: String, typeLabel: '{underline database}', defaultValue: defaults.database || '',
alias: 'd', type: String, typeLabel: '{underline database}',
...defaults.database && { defaultValue: defaults.database },
},
{
name: 'username', description: 'Username',
alias: 'u', type: String, typeLabel: '{underline database}', defaultValue: defaults.username || '',
alias: 'u', type: String, typeLabel: '{underline database}',
...defaults.username && { defaultValue: defaults.username },
},
{
name: 'password', description: 'Password. If parameter without value is given, password will be asked.',
alias: 'p', type: String, typeLabel: '[{underline password}]', defaultValue: defaults.password || null,
alias: 'p', type: String, typeLabel: '[{underline password}]',
...defaults.password && { defaultValue: defaults.password },
},
{
name: 'migration-pattern', description: "A pattern matching files to run migration files from. Default: 'migrations/*''",
name: 'migration-pattern', description: "A pattern matching files to run migration files from. Default: 'migrations/*'",
alias: 'm', type: String, typeLabel: '{underline directory}', defaultValue: defaults.migrationPattern || DEFAULT_MIGRATION_PATTERN,
},
{
name: 'schema-table', description: 'Table created to track schema version.',
alias: 't', type: String, defaultValue: defaults.schemaTable || 'schemaversion',
alias: 't', type: String,
...defaults.schemaTable && { defaultValue: defaults.schemaTable },
},
{
name: 'validate-checksum', description: 'Validates checksum of existing SQL migration files already run prior to executing migrations.',
type: Boolean, defaultValue: defaults.validateChecksum || true,
type: Boolean,
...defaults.validateChecksum && { defaultValue: defaults.validateChecksum },
},
{
name: 'ssl', description: 'Enables ssl connections. When using the mysql driver it expects a string containing name of ssl profile.',
alias: 's',
...defaults.ssl && { ssl: defaults.ssl },
},
{
name: 'prompt-password', description: 'Enables password prompt if the password is empty',
type: Boolean, defaultValue: defaults.promptPassword || false,
...defaults.ssl && { defaultValue: defaults.ssl },
},
{
name: 'config', description: 'Select the config file explicitly.',
Expand Down
2 changes: 1 addition & 1 deletion lib/postgrator-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const getClientOptions = async (options) => ({
...(
options.password // eslint-disable-line no-nested-ternary
? { password: options.password }
: options['prompt-password']
: options.password === null
? { password: await promptPassword() }
: {}
),
Expand Down
Loading

0 comments on commit 64691cf

Please sign in to comment.