Skip to content

Commit

Permalink
docs: update doc website (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Apr 19, 2024
1 parent 3735071 commit 5ba3f3a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 54 deletions.
78 changes: 30 additions & 48 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
# node-pg-migrate

[![Dependency Status](https://img.shields.io/david/salsita/node-pg-migrate.svg)](https://david-dm.org/salsita/node-pg-migrate)
[![devDependency Status](https://img.shields.io/david/dev/salsita/node-pg-migrate.svg)](https://david-dm.org/salsita/node-pg-migrate?type=dev)
[![NPM version](https://img.shields.io/npm/v/node-pg-migrate.svg)](https://www.npmjs.com/package/node-pg-migrate)
![Downloads](https://img.shields.io/npm/dm/node-pg-migrate.svg?style=flat)
> The core maintainer of this project moved to [@Shinigami92](https://github.com/Shinigami92) (also core maintainer of FakerJS and core member of Vite).
> The project is and remains under the MIT license.
[![npm version](https://badgen.net/npm/v/node-pg-migrate)](https://www.npmjs.com/package/node-pg-migrate)
[![npm downloads](https://badgen.net/npm/dm/node-pg-migrate)](https://www.npmjs.com/package/node-pg-migrate)
[![Continuous Integration](https://github.com/salsita/node-pg-migrate/actions/workflows/ci.yml/badge.svg)](https://github.com/salsita/node-pg-migrate/actions/workflows/ci.yml)
[![Postgres Test](https://github.com/salsita/node-pg-migrate/actions/workflows/postgres-test.yml/badge.svg)](https://github.com/salsita/node-pg-migrate/actions/workflows/postgres-test.yml)
[![Cockroach Test](https://github.com/salsita/node-pg-migrate/actions/workflows/cockroach-test.yml/badge.svg)](https://github.com/salsita/node-pg-migrate/actions/workflows/cockroach-test.yml)
![Licence](https://img.shields.io/npm/l/node-pg-migrate.svg?style=flat)
[![Known Vulnerabilities](https://snyk.io/test/github/salsita/node-pg-migrate/badge.svg)](https://snyk.io/test/github/salsita/node-pg-migrate)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
[![CircleCI](https://img.shields.io/circleci/project/github/salsita/node-pg-migrate.svg)](https://circleci.com/gh/salsita/workflows/node-pg-migrate)

Node.js database migration management built exclusively for postgres. (But can also be used for other DBs conforming to SQL standard - e.g. [CockroachDB](https://github.com/cockroachdb/cockroach).)
Started by [Theo Ephraim](https://github.com/theoephraim/), now maintained by [Salsita Software](https://www.salsitasoft.com/).
Node.js database migration management built exclusively for postgres. (But can also be used for other DBs conforming to SQL standard - e.g. [CockroachDB](https://github.com/cockroachdb/cockroach).)
Started by [Theo Ephraim](https://github.com/theoephraim/), then handed over to [Salsita Software](https://www.salsitasoft.com/) and now maintained by [@Shinigami92](https://github.com/Shinigami92).

### Looking for v3 docs?
## Preconditions

see [v3 branch](https://github.com/salsita/node-pg-migrate/tree/v3).
- Node.js 18 or higher
- PostgreSQL 12.8 or higher (lower versions may work but are not supported officially)

## Installation
If you don't already have the [`pg`](https://node-postgres.com/) library installed, you will need to add pg as either a direct or dev dependency

$ npm install node-pg-migrate pg
```bash
npm add pg
```

Installing this module adds a runnable file into your `node_modules/.bin` directory. If installed globally (with the -g option), you can run `node-pg-migrate` and if not, you can run `./node_modules/.bin/node-pg-migrate`
## Installation

It will also install [`pg`](https://node-postgres.com/) library as it is peer dependency used for migrations.
```bash
npm add --save-dev node-pg-migrate
```

## Usage
Installing this module adds a runnable file into your `node_modules/.bin` directory. If installed globally (with the -g option), you can run `node-pg-migrate` and if not, you can run `./node_modules/.bin/node-pg-migrate.js`

### Quick Example
## Quick Example

Add `"migrate": "node-pg-migrate"` to `scripts` section of `package.json` so you are able to quickly run commands.
Add `"migrate": "node-pg-migrate"` to `scripts` section of your `package.json` so you are able to quickly run commands.

Run `npm run migrate create my first migration`. It will create file `xxx_my-first-migration.js` in `migrations` folder.
Run `npm run migrate create my-first-migration`. It will create file `xxx_my-first-migration.js` in `migrations` folder.
Open it and change contents to:

```js
Expand Down Expand Up @@ -70,9 +76,9 @@ Now you should put your DB connection string to `DATABASE_URL` environment varia

You should now have two tables in your DB :tada:

If you will want to change your schema later, you can e.g. add lead paragraph to posts:
If you want to change your schema later, you can e.g. add lead paragraph to posts:

Run `npm run migrate create posts lead`, edit `xxx_posts_lead.js`:
Run `npm run migrate create posts_lead`, edit `xxx_posts_lead.js`:

```js
exports.up = (pgm) => {
Expand All @@ -82,11 +88,11 @@ exports.up = (pgm) => {
};
```

Run `npm run migrate up` and there will be new column in `posts` table :tada: :tada:
Run `npm run migrate up` and there will be a new column in `posts` table :tada:

Want to know more? Read docs:

### Docs
## Docs

- [CLI](cli.md)
- [Programmatic API](api.md)
Expand Down Expand Up @@ -121,28 +127,4 @@ _Naming / Raw Sql_ - Many tools force you to use their constants to do things li

## License

The MIT License (MIT)

Copyright (c) 2024 Christopher Quadflieg

Copyright (c) 2016-2021 Salsita Software <jando@salsitasoft.com>

Copyright (c) 2014-2016 Theo Ephraim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[MIT](https://github.com/salsita/node-pg-migrate/blob/main/LICENSE)
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ which takes options argument with following structure (similar to [command line
- `log` _[function]_ - Redirect log messages to this function, rather than `console`
- `logger` _[object with debug/info/warn/error methods]_ - Redirect messages to this logger object, rather than `console`
- `verbose` _[boolean]_ - Print all debug messages like DB queries run (if you switch it on, it will disable `logger.debug` method)
- `decamelize` _[boolean]_ - Runs [`decamelize`](https://github.com/sindresorhus/decamelize) on table/column/etc. names
- `decamelize` _[boolean]_ - Runs [`decamelize`](https://github.com/salsita/node-pg-migrate/blob/main/src/utils/decamelize.ts) on table/column/etc. names
2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ You can adjust defaults by passing arguments to `node-pg-migrate`:
- `single-transaction` - Combines all pending migrations into a single transaction so that if any migration fails, all will be rolled back (defaults to `true`, to switch it off supply `--no-single-transaction` on the command line).
- `no-lock` - Disables locking mechanism and checks (useful for DBs which does not support SQL commands used for [locking](migrations.md#locking))
- `fake` - Mark migrations as run without actually performing them (use with caution!)
- `decamelize` - Runs [`decamelize`](https://github.com/sindresorhus/decamelize) on table/column/etc. names
- `decamelize` - Runs [`decamelize`](https://github.com/salsita/node-pg-migrate/blob/main/src/utils/decamelize.ts) on table/column/etc. names
- `verbose` - Print all debug messages like DB queries run (defaults to `true`, to switch it off supply `--no-verbose` on the command line)
- `reject-unauthorized` - Sets ssl `rejectUnauthorized` parameter. Use for e.g. self-signed certificates on the server. [see](https://node-postgres.com/announcements#2020-02-25) and [see](https://github.com/brianc/node-postgres/issues/2009)

Expand Down
8 changes: 4 additions & 4 deletions docs/transpiling.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You can use babel for transpiling migration files. You have e.g. these options:

### Use global configuration

1. Update `scripts` section in your `package.json` to contain `"migrate": "babel-node node_modules/node-pg-migrate/bin/node-pg-migrate"`
1. Update `scripts` section in your `package.json` to contain `"migrate": "babel-node node_modules/node-pg-migrate/bin/node-pg-migrate.js"`

### Use custom configuration

Expand All @@ -17,7 +17,7 @@ It requires a little setup to use:

```
require('babel-core/register')( { ... your babel config ... } );
require('./node_modules/node-pg-migrate/bin/node-pg-migrate');
require('./node_modules/node-pg-migrate/bin/node-pg-migrate.js');
```

## Transpiling Typescript
Expand All @@ -31,7 +31,7 @@ Typescript is supported out of the box. You need to have installed `ts-node` pac
Another option is to use [ts-node](https://www.npmjs.com/package/ts-node) CLI directly and it needs to be available globally or as a dependency.

```
"migrate": "ts-node node_modules/.bin/node-pg-migrate -j ts",
"migrate": "ts-node node_modules/.bin/node-pg-migrate.js -j ts",
```

### Use custom configuration
Expand All @@ -42,5 +42,5 @@ If you need some more advanced TS config, you need to register transpiler yourse
const config = { ... your ts config ... }
require('ts-node').register(config);
// e.g. require("tsconfig-paths").register(config.compilerOptions);
require('./node_modules/node-pg-migrate/bin/node-pg-migrate');
require('./node_modules/node-pg-migrate/bin/node-pg-migrate.js');
```

0 comments on commit 5ba3f3a

Please sign in to comment.