@ps-aux/nodebup 0.9.6 → 0.9.8

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.
@@ -27,7 +27,7 @@ const parseConnectionUrl = url => {
27
27
  var _url$match;
28
28
 
29
29
  // TODO what if there are query params in the end?
30
- const regex = /postgres:\/\/(?<username>.*):(?<password>.*)@(?<host>.*):(?<port>\d*)(\/(?<database>.*))?$/;
30
+ const regex = /postgres:\/\/(?<username>.*):(?<password>.*)@(?<host>.*):(?<port>\d*)$/;
31
31
  const match = (_url$match = url.match(regex)) === null || _url$match === void 0 ? void 0 : _url$match.groups;
32
32
  if (!match || !match.username || !match.password || !match.host || !match.port) throw new Error(`The Postgres connection URL does not match required regex: ${regex.toString()}`);
33
33
  return {
@@ -103,7 +103,7 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
103
103
  const version = this.getVersion(pgVersion);
104
104
  const storage = this.storageBackendProvider.provide(); // To validate
105
105
 
106
- parseConnectionUrl(pgUrl);
106
+ const con = parseConnectionUrl(pgUrl);
107
107
  this.log.info(`Restoring Postgres database, version=${version}`);
108
108
  await this.fs.inTmpDir('pg-restore', async dirStr => {
109
109
  const dir = _Path.AbsPath.from(dirStr);
@@ -115,10 +115,13 @@ let PgBackupController = (_dec = (0, _inversify.injectable)(), _dec2 = Reflect.m
115
115
  await this.zip.unzipDir(zipFile, dir);
116
116
  this.fs.rmFile(zipFile);
117
117
  const outFile = this.fs.listFiles(dir)[0];
118
- this.log.debug('Will run psql import from %s', outFile.str()); // Don't forget that this itself might be run in docker
118
+ this.log.debug('Will run psql import from %s', outFile.str()); // Database is set to 'postgres' so that also users which don't have db created can use db-less URL
119
+ // Restoring user needs to have the admin access anyway
120
+
121
+ const connectionArgs = `-h ${con.host} -p ${con.port} -U ${con.username} -d postgres`; // Don't forget that this itself might be run in docker
119
122
  // therefore volume mounts are not usable (will apply to the location at host)
120
123
 
121
- this.sh.exec(`docker run --network host -i ` + `postgres:${version} ` + `psql ${pgUrl} -v ON_ERROR_STOP=0 < ${outFile.str()}`);
124
+ this.sh.exec(`docker run --network host -i ` + `-e PGPASSWORD=${con.password} ` + `postgres:${version} ` + `psql ${connectionArgs} -v ON_ERROR_STOP=0 < ${outFile.str()}`);
122
125
  });
123
126
  });
124
127
  }
@@ -7,20 +7,20 @@ exports.makeLog = exports.classObjLog = void 0;
7
7
 
8
8
  var _pino = _interopRequireDefault(require("pino"));
9
9
 
10
+ var _pinoPretty = _interopRequireDefault(require("pino-pretty"));
11
+
10
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
13
 
12
- // TODO set from config
14
+ // TODO set from the config
13
15
  const level = process.env.NODEBUP_LOG_LEVEL || 'trace';
16
+ const sync = process.env.TS_JEST === '1';
17
+ const stream = (0, _pinoPretty.default)({
18
+ sync
19
+ });
14
20
  const root = (0, _pino.default)({
15
21
  name: 'root',
16
- level,
17
- prettyPrint: true // TODO deprecated but other options don't work
18
- // Must be used as string. For some reason does not work as transport.
19
- // 1. No logging in Jest
20
- // 2. Not logging when run as CLI app
21
-
22
- } // stream
23
- );
22
+ level
23
+ }, stream);
24
24
 
25
25
  const makeLog = name => {
26
26
  return root.child({
@@ -26,7 +26,8 @@ let Zipper = (_dec = (0, _inversify.injectable)(), _dec(_class = class Zipper {
26
26
  _defineProperty(this, "log", (0, _logging.classObjLog)(this));
27
27
 
28
28
  _defineProperty(this, "zipDir", async (dir, to) => {
29
- this.log.trace(`Zipping %s to %s`, dir.str(), to.str());
29
+ this.log.trace(`Zipping %s to %s`, dir.str(), to.str()); // TODO replace with unzipper
30
+
30
31
  const z = new _admZip.default();
31
32
  z.addLocalFolder(dir.str());
32
33
  z.writeZip(to.str());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ps-aux/nodebup",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "",
5
5
  "module": "lib/index.js",
6
6
  "main": "lib/index.js",