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

Support postgrator v5, add cosmiconfig, etc #30

Merged
merged 35 commits into from
Feb 17, 2022
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f3dd416
Migrate to cosmiconfig
perrin4869 Nov 18, 2021
4a369ce
Test --no-config option
perrin4869 Nov 19, 2021
f5d5cd4
Update README.md
perrin4869 Nov 19, 2021
1ef8b01
Upgrade eslint and eslint-config-airbnb
perrin4869 Nov 21, 2021
16df32a
Remove redundant postgrator.json
perrin4869 Nov 21, 2021
bb8e7f4
Make type module
perrin4869 Nov 21, 2021
b922d23
Update command-line dependencies
perrin4869 Nov 21, 2021
91b2118
Small improvements
perrin4869 Nov 21, 2021
fefe433
Add docker-compose.yml
perrin4869 Nov 21, 2021
c6a8dde
Upgrade to postgrator 5
perrin4869 Nov 22, 2021
41234fb
Add mysql and mssql support
perrin4869 Nov 22, 2021
9c5de99
Attempt fix
perrin4869 Nov 22, 2021
9afd1a1
secure option -> ssl
perrin4869 Nov 24, 2021
49e127f
v5 requires node >= 12
perrin4869 Nov 24, 2021
52792f6
mssql encrypt is false by default
perrin4869 Nov 24, 2021
ee857ae
Fix published files
perrin4869 Nov 24, 2021
a9ec341
Add config option
perrin4869 Nov 27, 2021
2372088
Replace assert with chai
perrin4869 Nov 28, 2021
d3bd30a
Support merging options
perrin4869 Nov 29, 2021
e7d7630
Fix node 12
perrin4869 Nov 29, 2021
d0a3ee6
Remove restoreOptions from tests
perrin4869 Nov 29, 2021
760ecfc
Merge pull request #3 from perrin4869/feature/config-flag-merge-options
perrin4869 Nov 29, 2021
f0c77a9
Remove default values from host, user, database
perrin4869 Nov 29, 2021
c54ff63
Add missing tests
perrin4869 Nov 29, 2021
eb1225b
Update README and CHANGELOG
perrin4869 Nov 29, 2021
7fbca07
Add coverage reports
perrin4869 Nov 29, 2021
2ef5014
Fix README example
perrin4869 Nov 29, 2021
210692b
Add multi command support and drop-schema command
perrin4869 Nov 30, 2021
ac0eaba
Merge pull request #4 from perrin4869/feature/remove-schema
perrin4869 Nov 30, 2021
fcf5b70
Isolate commands
perrin4869 Nov 30, 2021
f1a0c18
Merge pull request #5 from perrin4869/chore/isolate-commands
perrin4869 Nov 30, 2021
da10f49
Minor refactoring
perrin4869 Nov 30, 2021
7165bd4
Fix running postgrator 0
perrin4869 Nov 30, 2021
a69bde1
Fix case where _unknown is undefined
perrin4869 Nov 30, 2021
d389307
Test rejecting invalid commands
perrin4869 Dec 1, 2021
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
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: 4 additions & 3 deletions .eslintrc → .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"extends": "airbnb-base",

"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"browser": false
},

"rules": {
"arrow-body-style": "off",
"comma-dangle": ["error", "always-multiline"],
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
versioning-strategy: increase
schedule:
interval: daily
29 changes: 0 additions & 29 deletions .github/workflows/nodejs.yml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: release
on:
release:
types: [published]

jobs:
publish:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Use Node.js 16
uses: actions/setup-node@v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Start databases
run: docker-compose up -d

- name: Wait for databases to be available
run: sleep 10

- name: Test
run: npm test

- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

- name: Stop databases
run: docker-compose down
49 changes: 49 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: test
on:
push:
branches:
- master
pull_request:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version:
- 12.x
- 14.x
- 16.x
redis-version: [6]

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Start databases
run: docker-compose up -d

- name: Wait for databases to be available
run: sleep 10

- name: 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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +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
70 changes: 47 additions & 23 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.
@@ -10,7 +16,7 @@ Uses [Postgrator](https://github.com/rickbergfalk/postgrator) node.js library de

## Installation

*As of postgrator-cli 4 Node.js version 10 or greater is required*
*As of postgrator-cli 5 Node.js version 12 or greater is required*

```
npm install -g postgrator-cli
@@ -27,7 +33,6 @@ And install the appropriate DB engine(s) if not installed yet:
```
npm install pg@8
npm install mysql@2
npm install mysql2@2
npm install mssql@6
```

@@ -89,11 +94,11 @@ environment variables such as the above.

You can specify all the parameters from command line (see below) but the easiest way is to:

* Create `postgrator.json` configuration file. For example:
* Create `.postgratorrc.json`, or any config file supported by [cosmiconfig](https://github.com/davidtheclark/cosmiconfig). For example:

```
{
"migrationDirectory": "migrations",
"migrationPattern": "migrations/*",
"driver": "pg",
"host": "127.0.0.1",
"port": 5432,
@@ -103,7 +108,7 @@ You can specify all the parameters from command line (see below) but the easiest
}
```

* Migrate to latest version (it looks settings by default from `postgrator.json`):
* Migrate to latest version (it looks settings by default from `.postgratorrc.json`, etc):
```
$ postgrator
```
@@ -117,40 +122,59 @@ $ postgrator 4
### Synopsis

```
postgrator [[--to=]<version>] --database=<db> [--driver=<driver>] [--host=<host>] [--port=<port>] [--username=<username>] [--password=<password>]
postgrator [[--to=]<version>] --database=<db> [--driver=<driver>] [--host=<host>] [--port=<port>] [--username=<username>] [--password=<password>] [--no-config]

postgrator [[--to=]<version>] [--config=<config>]

postgrator migrate [[--to=]version]

postgrator drop-schema [--config=<config>]
```

### Options

```
--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''
-s, --secure Secure connection (Azure). Default: false
-c, --config file Load configuration from a JSON file. With a configuration file you can also
use additional configuration parameters available on postgrator. See syntax
from https://github.com/rickbergfalk/postgrator
-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.
--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 file 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.

Examples

1. Specify parameters on command line postgrator 23 --host 127.0.0.1 --database sampledb
--username testuser --password testpassword
2. Use configuration file postgrator 2 --config myConfig.json
3. Use default configuration file (postgrator.json) postgrator 5
2. Explicitly disable loading configuration file postgrator 2 --no-config
3. Use default configuration file to migrate to version 5 postgrator 5
4. Migrate to latest version using default configuration postgrator
file (postgrator.json)
file (.postgratorrc.json, etc)
5. Drop the schema table using configuration files postgrator drop-schema
```

## 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
Loading