@sqb/migrator 4.10.1 → 4.10.2
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.
|
@@ -46,6 +46,7 @@ class PgMigrationAdapter extends migration_adapter_js_1.MigrationAdapter {
|
|
|
46
46
|
try {
|
|
47
47
|
const adapter = new PgMigrationAdapter();
|
|
48
48
|
adapter._connection = connection;
|
|
49
|
+
adapter._packageName = options.migrationPackage.name;
|
|
49
50
|
adapter._infoSchema = options.infoSchema || '__migration';
|
|
50
51
|
adapter.defaultVariables.schema = options.connection.schema || '';
|
|
51
52
|
if (!adapter.defaultVariables.schema) {
|
|
@@ -108,14 +109,16 @@ CREATE TABLE IF NOT EXISTS ${adapter.eventTableFull}
|
|
|
108
109
|
const params = [];
|
|
109
110
|
if (info.status && info.status !== this.status) {
|
|
110
111
|
params.push(info.status);
|
|
111
|
-
sql += '
|
|
112
|
+
sql += ',\n status = $' + (params.length);
|
|
112
113
|
}
|
|
113
114
|
if (info.version && info.version !== this.version) {
|
|
114
115
|
params.push(info.version);
|
|
115
|
-
sql += '
|
|
116
|
+
sql += ',\n current_version = $' + (params.length);
|
|
116
117
|
}
|
|
117
118
|
if (sql) {
|
|
118
|
-
|
|
119
|
+
params.push(this.packageName);
|
|
120
|
+
sql = `update ${this.summaryTableFull} set updated_at = current_timestamp` + sql +
|
|
121
|
+
`\n where package_name =$` + (params.length);
|
|
119
122
|
await this._connection.query(sql, { params });
|
|
120
123
|
if (info.status)
|
|
121
124
|
this._status = info.status;
|
package/cjs/db-migrator.js
CHANGED
|
@@ -49,12 +49,19 @@ class DbMigrator extends strict_typed_events_1.AsyncEventEmitter {
|
|
|
49
49
|
await migrationAdapter.backupDatabase();
|
|
50
50
|
}
|
|
51
51
|
// Execute migration tasks
|
|
52
|
+
let migrationIndex = -1;
|
|
52
53
|
for (const migration of migrations) {
|
|
54
|
+
migrationIndex++;
|
|
53
55
|
if (migration.version > targetVersion || migrationAdapter.version >= migration.version)
|
|
54
56
|
continue;
|
|
57
|
+
await this.emitAsync('migration-start', {
|
|
58
|
+
migration,
|
|
59
|
+
total: migrations.length,
|
|
60
|
+
index: migrationIndex
|
|
61
|
+
});
|
|
55
62
|
for (let index = 0; index < migration.tasks.length; index++) {
|
|
56
63
|
task = migration.tasks[index];
|
|
57
|
-
await this.emitAsync('task-start', {
|
|
64
|
+
await this.emitAsync('task-start', { migration, task, total, index });
|
|
58
65
|
await migrationAdapter.update({ status: types_js_1.MigrationStatus.busy });
|
|
59
66
|
await migrationAdapter.writeEvent({
|
|
60
67
|
event: migration_adapter_js_1.MigrationAdapter.EventKind.started,
|
|
@@ -76,14 +83,23 @@ class DbMigrator extends strict_typed_events_1.AsyncEventEmitter {
|
|
|
76
83
|
await migrationAdapter.writeEvent({
|
|
77
84
|
event: migration_adapter_js_1.MigrationAdapter.EventKind.error,
|
|
78
85
|
version: migration.version,
|
|
79
|
-
message: String(e)
|
|
86
|
+
message: String(e),
|
|
87
|
+
details: e.message + '\n\n' +
|
|
88
|
+
Object.keys(e)
|
|
89
|
+
.filter(k => e[k] != null)
|
|
90
|
+
.map(k => k + ': ' + e[k]).join('\n')
|
|
80
91
|
});
|
|
81
92
|
// noinspection ExceptionCaughtLocallyJS
|
|
82
93
|
throw e;
|
|
83
94
|
}
|
|
84
|
-
await this.emitAsync('task-finish', {
|
|
95
|
+
await this.emitAsync('task-finish', { migration, task, total, index });
|
|
85
96
|
}
|
|
86
|
-
await migrationAdapter.update({ version: migration.version });
|
|
97
|
+
await migrationAdapter.update({ version: migration.version, status: types_js_1.MigrationStatus.idle });
|
|
98
|
+
await this.emitAsync('migration-finish', {
|
|
99
|
+
migration,
|
|
100
|
+
total: migrations.length,
|
|
101
|
+
index: migrationIndex
|
|
102
|
+
});
|
|
87
103
|
}
|
|
88
104
|
}
|
|
89
105
|
catch (e) {
|
package/cjs/migration-package.js
CHANGED
|
@@ -57,7 +57,11 @@ var MigrationPackage;
|
|
|
57
57
|
else if (typeof t === 'string') {
|
|
58
58
|
let pattern = t.replace(/\\/g, '/');
|
|
59
59
|
pattern = path_1.default.resolve(migration.dirname || baseDir, pattern);
|
|
60
|
-
const files = await (0, fast_glob_1.default)(pattern, {
|
|
60
|
+
const files = await (0, fast_glob_1.default)(pattern, {
|
|
61
|
+
absolute: true,
|
|
62
|
+
onlyFiles: true
|
|
63
|
+
});
|
|
64
|
+
files.sort();
|
|
61
65
|
for (const filename of files) {
|
|
62
66
|
const ext = path_1.default.extname(filename).toLowerCase();
|
|
63
67
|
if (!path_1.default.basename(filename, ext).endsWith('.task'))
|
|
@@ -43,6 +43,7 @@ export class PgMigrationAdapter extends MigrationAdapter {
|
|
|
43
43
|
try {
|
|
44
44
|
const adapter = new PgMigrationAdapter();
|
|
45
45
|
adapter._connection = connection;
|
|
46
|
+
adapter._packageName = options.migrationPackage.name;
|
|
46
47
|
adapter._infoSchema = options.infoSchema || '__migration';
|
|
47
48
|
adapter.defaultVariables.schema = options.connection.schema || '';
|
|
48
49
|
if (!adapter.defaultVariables.schema) {
|
|
@@ -105,14 +106,16 @@ CREATE TABLE IF NOT EXISTS ${adapter.eventTableFull}
|
|
|
105
106
|
const params = [];
|
|
106
107
|
if (info.status && info.status !== this.status) {
|
|
107
108
|
params.push(info.status);
|
|
108
|
-
sql += '
|
|
109
|
+
sql += ',\n status = $' + (params.length);
|
|
109
110
|
}
|
|
110
111
|
if (info.version && info.version !== this.version) {
|
|
111
112
|
params.push(info.version);
|
|
112
|
-
sql += '
|
|
113
|
+
sql += ',\n current_version = $' + (params.length);
|
|
113
114
|
}
|
|
114
115
|
if (sql) {
|
|
115
|
-
|
|
116
|
+
params.push(this.packageName);
|
|
117
|
+
sql = `update ${this.summaryTableFull} set updated_at = current_timestamp` + sql +
|
|
118
|
+
`\n where package_name =$` + (params.length);
|
|
116
119
|
await this._connection.query(sql, { params });
|
|
117
120
|
if (info.status)
|
|
118
121
|
this._status = info.status;
|
package/esm/db-migrator.js
CHANGED
|
@@ -46,12 +46,19 @@ export class DbMigrator extends AsyncEventEmitter {
|
|
|
46
46
|
await migrationAdapter.backupDatabase();
|
|
47
47
|
}
|
|
48
48
|
// Execute migration tasks
|
|
49
|
+
let migrationIndex = -1;
|
|
49
50
|
for (const migration of migrations) {
|
|
51
|
+
migrationIndex++;
|
|
50
52
|
if (migration.version > targetVersion || migrationAdapter.version >= migration.version)
|
|
51
53
|
continue;
|
|
54
|
+
await this.emitAsync('migration-start', {
|
|
55
|
+
migration,
|
|
56
|
+
total: migrations.length,
|
|
57
|
+
index: migrationIndex
|
|
58
|
+
});
|
|
52
59
|
for (let index = 0; index < migration.tasks.length; index++) {
|
|
53
60
|
task = migration.tasks[index];
|
|
54
|
-
await this.emitAsync('task-start', {
|
|
61
|
+
await this.emitAsync('task-start', { migration, task, total, index });
|
|
55
62
|
await migrationAdapter.update({ status: MigrationStatus.busy });
|
|
56
63
|
await migrationAdapter.writeEvent({
|
|
57
64
|
event: MigrationAdapter.EventKind.started,
|
|
@@ -73,14 +80,23 @@ export class DbMigrator extends AsyncEventEmitter {
|
|
|
73
80
|
await migrationAdapter.writeEvent({
|
|
74
81
|
event: MigrationAdapter.EventKind.error,
|
|
75
82
|
version: migration.version,
|
|
76
|
-
message: String(e)
|
|
83
|
+
message: String(e),
|
|
84
|
+
details: e.message + '\n\n' +
|
|
85
|
+
Object.keys(e)
|
|
86
|
+
.filter(k => e[k] != null)
|
|
87
|
+
.map(k => k + ': ' + e[k]).join('\n')
|
|
77
88
|
});
|
|
78
89
|
// noinspection ExceptionCaughtLocallyJS
|
|
79
90
|
throw e;
|
|
80
91
|
}
|
|
81
|
-
await this.emitAsync('task-finish', {
|
|
92
|
+
await this.emitAsync('task-finish', { migration, task, total, index });
|
|
82
93
|
}
|
|
83
|
-
await migrationAdapter.update({ version: migration.version });
|
|
94
|
+
await migrationAdapter.update({ version: migration.version, status: MigrationStatus.idle });
|
|
95
|
+
await this.emitAsync('migration-finish', {
|
|
96
|
+
migration,
|
|
97
|
+
total: migrations.length,
|
|
98
|
+
index: migrationIndex
|
|
99
|
+
});
|
|
84
100
|
}
|
|
85
101
|
}
|
|
86
102
|
catch (e) {
|
package/esm/migration-package.js
CHANGED
|
@@ -50,7 +50,11 @@ export var MigrationPackage;
|
|
|
50
50
|
else if (typeof t === 'string') {
|
|
51
51
|
let pattern = t.replace(/\\/g, '/');
|
|
52
52
|
pattern = path.resolve(migration.dirname || baseDir, pattern);
|
|
53
|
-
const files = await glob(pattern, {
|
|
53
|
+
const files = await glob(pattern, {
|
|
54
|
+
absolute: true,
|
|
55
|
+
onlyFiles: true
|
|
56
|
+
});
|
|
57
|
+
files.sort();
|
|
54
58
|
for (const filename of files) {
|
|
55
59
|
const ext = path.extname(filename).toLowerCase();
|
|
56
60
|
if (!path.basename(filename, ext).endsWith('.task'))
|
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.10.
|
|
4
|
+
"version": "4.10.2",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Eray Hanoglu <e.hanoglu@panates.com>",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"ts-gems": "^2.5.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@sqb/builder": "^4.10.
|
|
40
|
-
"@sqb/connect": "^4.10.
|
|
41
|
-
"@sqb/postgres": "^4.10.
|
|
39
|
+
"@sqb/builder": "^4.10.2",
|
|
40
|
+
"@sqb/connect": "^4.10.2",
|
|
41
|
+
"@sqb/postgres": "^4.10.2"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": ">=16.0",
|