sqerge 1.1.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,8 +59,6 @@ A forward only PostgreSQL migration tool. Uses [Postgres.js](https://github.com/
59
59
 
60
60
  Command:
61
61
 
62
- **Note:** Use [environment variables](https://www.postgresql.org/docs/current/libpq-envars.html) for your database connection. Supported environment variables are at the discretion of [Postgres.js](https://github.com/porsager/postgres).
63
-
64
62
  ```sh
65
63
  PGHOST=localhost PGPORT=5438 PGUSER=jonathan PGPASSWORD=iliketurtles PGDATABASE=dev npx sqerge ./foo
66
64
  ```
@@ -73,3 +71,11 @@ A forward only PostgreSQL migration tool. Uses [Postgres.js](https://github.com/
73
71
  [sqerge] file 2 (2-biz.sql): executed
74
72
  [sqerge] file 3 (3-baz.js): executed
75
73
  ```
74
+
75
+ ## Environment Variables
76
+
77
+ - Use **Postgres.js** [environment variables](https://github.com/porsager/postgres#environmental-variables) for your database **connection**.
78
+
79
+ - **ROLE** (optional)
80
+
81
+ Execute migration with the specified database role. This is helpful for when your `LOGIN` role has a `NOINHERIT` membership to another role containting privileges required for your migration. If ROLE is provided, sqerge will execute `SET ROLE` for the session and then execute your migration files.
package/dist/bootstrap.js CHANGED
@@ -37,7 +37,7 @@ async function bootstrap() {
37
37
  process.on('exit', async () => {
38
38
  await sql.end();
39
39
  });
40
- await (0, index_1.default)(sql, dir, log);
40
+ await (0, index_1.default)(sql, dir, { log, role: process.env.ROLE });
41
41
  await sql.end();
42
42
  }
43
43
  catch (error) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { Sql } from 'postgres';
2
- export default function migrate(sql: Sql<{}>, fileDir: string, log?: typeof console.log): Promise<void>;
2
+ export default function migrate(sql: Sql<{}>, fileDir: string, options?: {
3
+ role?: string;
4
+ log?: typeof console.log;
5
+ }): Promise<void>;
3
6
  export declare class SqergeError extends Error {
4
7
  code: string;
5
8
  constructor(code: string, message: string, ...args: any);
package/dist/index.js CHANGED
@@ -5,12 +5,16 @@ const fs_1 = require("fs");
5
5
  const node_path_1 = require("node:path");
6
6
  const node_util_1 = require("node:util");
7
7
  const postgres_1 = require("postgres");
8
- async function migrate(sql, fileDir, log) {
8
+ async function migrate(sql, fileDir, options) {
9
+ const log = options?.log;
9
10
  const fileList = getFileList(fileDir);
10
11
  log && log('%O file(s) found in %O', fileList.length, fileDir);
11
12
  if (fileList.length === 0)
12
13
  return;
13
14
  await sql.begin(async (sql) => {
15
+ if (typeof options?.role === 'string') {
16
+ await sql `set role ${sql(options.role)};`;
17
+ }
14
18
  await createMigrationTable(sql);
15
19
  const migrationList = await getMigrations(sql);
16
20
  for (let i = 0; i < fileList.length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqerge",
3
- "version": "1.1.0",
3
+ "version": "2.0.1",
4
4
  "description": "A forward only PostgreSQL migration tool.",
5
5
  "keywords": [
6
6
  "postgres",
@@ -26,7 +26,7 @@
26
26
  "scripts": {
27
27
  "build": "rm -rf dist && tsc --build",
28
28
  "dev": "tsc -w",
29
- "dev:postgres": "node ./scripts/dev-postgres.js",
29
+ "dev:postgres": "PGHOST=localhost PGPORT=5438 PGUSER=jonathan PGPASSWORD=iliketurtles PGDATABASE=dev NAME=sqerge RESET=true TAG=14 pglocal",
30
30
  "prepare": "husky install",
31
31
  "test": "npm run test:prettier && npm run test:jest",
32
32
  "test:jest": "jest",
@@ -49,6 +49,7 @@
49
49
  ]
50
50
  },
51
51
  "devDependencies": {
52
+ "@eezing/pglocal": "^1.0.8",
52
53
  "@types/jest": "^29.1.2",
53
54
  "@types/node": "^16.11.59",
54
55
  "husky": "^8.0.0",