@sqb/migrator 4.12.1 → 4.13.0

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.
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PgMigrationAdapter = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const postgres_1 = require("@sqb/postgres");
5
6
  const path_1 = tslib_1.__importDefault(require("path"));
6
7
  const postgresql_client_1 = require("postgresql-client");
7
- const postgres_1 = require("@sqb/postgres");
8
8
  const migration_adapter_js_1 = require("../migration-adapter.js");
9
9
  const migration_package_js_1 = require("../migration-package.js");
10
10
  const types_js_1 = require("../types.js");
@@ -88,7 +88,7 @@ CREATE TABLE IF NOT EXISTS ${adapter.eventTableFull}
88
88
  objectRows: true,
89
89
  });
90
90
  if (!(r && r.rows?.length)) {
91
- await connection.query(`insert into ${adapter.summaryTableFull} ` + '(package_name, status) values ($1, $2)', {
91
+ await connection.query(`insert into ${adapter.summaryTableFull} (package_name, status) values ($1, $2)`, {
92
92
  params: [adapter.packageName, types_js_1.MigrationStatus.idle],
93
93
  });
94
94
  }
package/cjs/index.js CHANGED
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./db-migrator.js"), exports);
5
- tslib_1.__exportStar(require("./migration-package.js"), exports);
6
5
  tslib_1.__exportStar(require("./migration-adapter.js"), exports);
6
+ tslib_1.__exportStar(require("./migration-package.js"), exports);
7
7
  tslib_1.__exportStar(require("./types.js"), exports);
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MigrationPackage = exports.isCustomMigrationTask = exports.isInsertDataMigrationTask = exports.isSqlScriptMigrationTask = void 0;
3
+ exports.MigrationPackage = void 0;
4
+ exports.isSqlScriptMigrationTask = isSqlScriptMigrationTask;
5
+ exports.isInsertDataMigrationTask = isInsertDataMigrationTask;
6
+ exports.isCustomMigrationTask = isCustomMigrationTask;
4
7
  const tslib_1 = require("tslib");
5
8
  const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
6
9
  const promises_1 = tslib_1.__importDefault(require("fs/promises"));
@@ -9,15 +12,12 @@ const get_calling_filename_js_1 = require("./utils/get-calling-filename.js");
9
12
  function isSqlScriptMigrationTask(x) {
10
13
  return typeof x === 'object' && (typeof x.script === 'string' || typeof x.script === 'function');
11
14
  }
12
- exports.isSqlScriptMigrationTask = isSqlScriptMigrationTask;
13
15
  function isInsertDataMigrationTask(x) {
14
16
  return typeof x === 'object' && typeof x.tableName === 'string' && Array.isArray(x.rows);
15
17
  }
16
- exports.isInsertDataMigrationTask = isInsertDataMigrationTask;
17
18
  function isCustomMigrationTask(x) {
18
19
  return typeof x === 'object' && typeof x.fn === 'function';
19
20
  }
20
- exports.isCustomMigrationTask = isCustomMigrationTask;
21
21
  var MigrationPackage;
22
22
  (function (MigrationPackage) {
23
23
  async function load(asyncConfig) {
@@ -27,8 +27,9 @@ var MigrationPackage;
27
27
  baseDir,
28
28
  migrations: [],
29
29
  };
30
- if (!Array.isArray(asyncConfig.migrations))
30
+ if (!Array.isArray(asyncConfig.migrations)) {
31
31
  throw new TypeError('You must provide array of MigrationConfig in "migrations" property');
32
+ }
32
33
  if (asyncConfig.migrations?.length) {
33
34
  const srcMigrations = [];
34
35
  const trgMigrations = [];
@@ -110,33 +111,33 @@ var MigrationPackage;
110
111
  return out;
111
112
  }
112
113
  MigrationPackage.load = load;
113
- async function loadMigrations(baseDir, pattern) {
114
- const out = [];
115
- const files = await (0, fast_glob_1.default)(path_1.default.join(baseDir, pattern), { absolute: true, onlyFiles: true });
116
- for (const filename of files) {
117
- const ext = path_1.default.extname(filename).toLowerCase();
118
- if (path_1.default.basename(filename, ext) !== 'migration')
119
- continue;
120
- let json;
121
- if (['.js', '.ts', '.cjs', '.mjs'].includes(ext)) {
122
- json = await Promise.resolve(`${filename}`).then(s => tslib_1.__importStar(require(s)));
123
- if (json.__esModule)
124
- json = json.default;
125
- }
126
- else if (ext === '.json') {
127
- try {
128
- json = JSON.parse(await promises_1.default.readFile(filename, 'utf-8'));
129
- }
130
- catch (e) {
131
- e.message = `Error in ${filename}\n` + e.message;
132
- throw e;
133
- }
114
+ })(MigrationPackage || (exports.MigrationPackage = MigrationPackage = {}));
115
+ async function loadMigrations(baseDir, pattern) {
116
+ const out = [];
117
+ const files = await (0, fast_glob_1.default)(path_1.default.join(baseDir, pattern), { absolute: true, onlyFiles: true });
118
+ for (const filename of files) {
119
+ const ext = path_1.default.extname(filename).toLowerCase();
120
+ if (path_1.default.basename(filename, ext) !== 'migration')
121
+ continue;
122
+ let json;
123
+ if (['.js', '.ts', '.cjs', '.mjs'].includes(ext)) {
124
+ json = await Promise.resolve(`${filename}`).then(s => tslib_1.__importStar(require(s)));
125
+ if (json.__esModule)
126
+ json = json.default;
127
+ }
128
+ else if (ext === '.json') {
129
+ try {
130
+ json = JSON.parse(await promises_1.default.readFile(filename, 'utf-8'));
134
131
  }
135
- if (json && typeof json === 'object' && json.version && Array.isArray(json.tasks)) {
136
- json.baseDir = path_1.default.relative(baseDir, path_1.default.dirname(filename));
137
- out.push(json);
132
+ catch (e) {
133
+ e.message = `Error in ${filename}\n` + e.message;
134
+ throw e;
138
135
  }
139
136
  }
140
- return out;
137
+ if (json && typeof json === 'object' && json.version && Array.isArray(json.tasks)) {
138
+ json.baseDir = path_1.default.relative(baseDir, path_1.default.dirname(filename));
139
+ out.push(json);
140
+ }
141
141
  }
142
- })(MigrationPackage || (exports.MigrationPackage = MigrationPackage = {}));
142
+ return out;
143
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCallingFilename = void 0;
3
+ exports.getCallingFilename = getCallingFilename;
4
4
  const PATH_PATTERN = /^(?:file:\/\/)?(.+)$/;
5
5
  function getCallingFilename(position = 0) {
6
6
  position++;
@@ -19,4 +19,3 @@ function getCallingFilename(position = 0) {
19
19
  }
20
20
  return '';
21
21
  }
22
- exports.getCallingFilename = getCallingFilename;
@@ -1,6 +1,6 @@
1
+ import { PgAdapter } from '@sqb/postgres';
1
2
  import path from 'path';
2
3
  import { stringifyValueForSQL } from 'postgresql-client';
3
- import { PgAdapter } from '@sqb/postgres';
4
4
  import { MigrationAdapter } from '../migration-adapter.js';
5
5
  import { isCustomMigrationTask, isInsertDataMigrationTask, isSqlScriptMigrationTask, } from '../migration-package.js';
6
6
  import { MigrationStatus } from '../types.js';
@@ -84,7 +84,7 @@ CREATE TABLE IF NOT EXISTS ${adapter.eventTableFull}
84
84
  objectRows: true,
85
85
  });
86
86
  if (!(r && r.rows?.length)) {
87
- await connection.query(`insert into ${adapter.summaryTableFull} ` + '(package_name, status) values ($1, $2)', {
87
+ await connection.query(`insert into ${adapter.summaryTableFull} (package_name, status) values ($1, $2)`, {
88
88
  params: [adapter.packageName, MigrationStatus.idle],
89
89
  });
90
90
  }
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './db-migrator.js';
2
- export * from './migration-package.js';
3
2
  export * from './migration-adapter.js';
3
+ export * from './migration-package.js';
4
4
  export * from './types.js';
@@ -20,8 +20,9 @@ export var MigrationPackage;
20
20
  baseDir,
21
21
  migrations: [],
22
22
  };
23
- if (!Array.isArray(asyncConfig.migrations))
23
+ if (!Array.isArray(asyncConfig.migrations)) {
24
24
  throw new TypeError('You must provide array of MigrationConfig in "migrations" property');
25
+ }
25
26
  if (asyncConfig.migrations?.length) {
26
27
  const srcMigrations = [];
27
28
  const trgMigrations = [];
@@ -103,33 +104,33 @@ export var MigrationPackage;
103
104
  return out;
104
105
  }
105
106
  MigrationPackage.load = load;
106
- async function loadMigrations(baseDir, pattern) {
107
- const out = [];
108
- const files = await glob(path.join(baseDir, pattern), { absolute: true, onlyFiles: true });
109
- for (const filename of files) {
110
- const ext = path.extname(filename).toLowerCase();
111
- if (path.basename(filename, ext) !== 'migration')
112
- continue;
113
- let json;
114
- if (['.js', '.ts', '.cjs', '.mjs'].includes(ext)) {
115
- json = await import(filename);
116
- if (json.__esModule)
117
- json = json.default;
118
- }
119
- else if (ext === '.json') {
120
- try {
121
- json = JSON.parse(await fs.readFile(filename, 'utf-8'));
122
- }
123
- catch (e) {
124
- e.message = `Error in ${filename}\n` + e.message;
125
- throw e;
126
- }
107
+ })(MigrationPackage || (MigrationPackage = {}));
108
+ async function loadMigrations(baseDir, pattern) {
109
+ const out = [];
110
+ const files = await glob(path.join(baseDir, pattern), { absolute: true, onlyFiles: true });
111
+ for (const filename of files) {
112
+ const ext = path.extname(filename).toLowerCase();
113
+ if (path.basename(filename, ext) !== 'migration')
114
+ continue;
115
+ let json;
116
+ if (['.js', '.ts', '.cjs', '.mjs'].includes(ext)) {
117
+ json = await import(filename);
118
+ if (json.__esModule)
119
+ json = json.default;
120
+ }
121
+ else if (ext === '.json') {
122
+ try {
123
+ json = JSON.parse(await fs.readFile(filename, 'utf-8'));
127
124
  }
128
- if (json && typeof json === 'object' && json.version && Array.isArray(json.tasks)) {
129
- json.baseDir = path.relative(baseDir, path.dirname(filename));
130
- out.push(json);
125
+ catch (e) {
126
+ e.message = `Error in ${filename}\n` + e.message;
127
+ throw e;
131
128
  }
132
129
  }
133
- return out;
130
+ if (json && typeof json === 'object' && json.version && Array.isArray(json.tasks)) {
131
+ json.baseDir = path.relative(baseDir, path.dirname(filename));
132
+ out.push(json);
133
+ }
134
134
  }
135
- })(MigrationPackage || (MigrationPackage = {}));
135
+ return out;
136
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/migrator",
3
3
  "description": "Database migrator for SQB",
4
- "version": "4.12.1",
4
+ "version": "4.13.0",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>",
@@ -35,12 +35,17 @@
35
35
  "clean:cover": "rimraf ../../coverage/migrator"
36
36
  },
37
37
  "dependencies": {
38
+ "fast-glob": "^3.3.2",
39
+ "strict-typed-events": "^2.3.3",
38
40
  "ts-gems": "^3.4.0"
39
41
  },
40
42
  "peerDependencies": {
41
- "@sqb/builder": "^4.12.1",
42
- "@sqb/connect": "^4.12.1",
43
- "@sqb/postgres": "^4.12.1"
43
+ "@sqb/builder": "^4.13.0",
44
+ "@sqb/connect": "^4.13.0",
45
+ "@sqb/postgres": "^4.13.0"
46
+ },
47
+ "devDependencies": {
48
+ "postgresql-client": "^2.12.0"
44
49
  },
45
50
  "engines": {
46
51
  "node": ">=16.0",
@@ -1,5 +1,5 @@
1
- import { AsyncEventEmitter } from 'strict-typed-events';
2
1
  import { ClientConfiguration } from '@sqb/connect';
2
+ import { AsyncEventEmitter } from 'strict-typed-events';
3
3
  import { MigrationAdapter } from './migration-adapter.js';
4
4
  import { MigrationPackage, MigrationPackageConfig } from './migration-package.js';
5
5
  export interface DbMigratorOptions {
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './db-migrator.js';
2
- export * from './migration-package.js';
3
2
  export * from './migration-adapter.js';
3
+ export * from './migration-package.js';
4
4
  export * from './types.js';