# update-pg

> a Postgres database update script for your migrations

Latest version **0.0.7** (published 2024-02-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install update-pg
pnpm add update-pg
yarn add update-pg
bun add update-pg
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2024-02-19 |
| First published | 2023-08-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 22.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | MK2k |
| Maintainers | mk2k |

## Links

- npm: https://www.npmjs.com/package/update-pg
- Repository: https://github.com/theMK2k/update-pg
- Homepage: https://github.com/theMK2k/update-pg#readme
- Issues: https://github.com/theMK2k/update-pg/issues
- npm.io page: https://npm.io/package/update-pg

## Dependencies (5)

- [pg](https://npm.io/package/pg.md) 8.11.0
- [ora](https://npm.io/package/ora.md) 6.1.2
- [chalk](https://npm.io/package/chalk.md) 5.1.2
- [sha.js](https://npm.io/package/sha.js.md) 2.4.11
- [loglevel](https://npm.io/package/loglevel.md) 1.8.1

## Recent versions

- 0.0.7 (latest) — 2024-02-19
- 0.0.6 — 2024-02-19
- 0.0.5 — 2023-09-20
- 0.0.4 — 2023-08-15
- 0.0.3 — 2023-08-04
- 0.0.2 — 2023-08-04
- 0.0.1 — 2023-08-04

## README

# Update PG

Update PG is a script for Postgres database migrations.

## How it works

Define your database update and migration scripts as `.sql` files in `pg/pg-updates`, e.g.:

```text
pg/pg-updates
├── public.permissions RLS.sql
├── public.permissions TABLE.sql
├── public.roles RLS.sql
├── public.roles TABLE.sql
├── public.users RLS.sql
├── public.users TABLE.sql
└── public.users TRIGGER.sql
```

Create a `.json` file to define the sequence in which the `.sql` files should be run:

```json
{
  "updates": [
    "public.users TABLE.sql",
    "public.roles TABLE.sql",
    "public.permissions TABLE.sql",

    "public.users TRIGGER.sql",

    "public.permissions RLS.sql",
    "public.roles RLS.sql",
    "public.users RLS.sql",
  ],
  "ignore": []
}
```

## Running update-pg

Provide the following environment variables for the Postgres connection:

```text
PGHOST=<string, host of your pg instance>
PGUSER=<string, user of your pg instance>
PGDATABASE=<string, database name>
PGPASSWORD=<string, password for the user>
PGPORT=<number, port of your pg instance>

optional:

PGSSLREQUIRE=<true/false, require ssl>
PGSSLALLOWSELFSIGNED=<true/false, allow self-signed certificates>
PGSSLCERT=<-----BEGIN CERTIFICATE-----\n[...]\n-----END CERTIFICATE----->
```

Run `node update-pg.mjs` and update-pg will perform the updates in **dry-run mode** (the actual updates will not be committed).

Run `node update-pg.mjs --commit` and update-pg will perform the updates and **commit** them.

---
_Source: https://npm.io/package/update-pg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
