@klapeks/micro-db-utils 0.0.4 → 0.0.5

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.
@@ -104,7 +104,8 @@ var MySQLMigrations = /** @class */ (function () {
104
104
  migrationRecords_1 = _b.sent();
105
105
  runnedMigrationsAmount_1 = 0;
106
106
  runTableMigration = function (table) { return __awaiter(_this, void 0, void 0, function () {
107
- var todoMigrations, tableInfo, lastMigrationDate, lastRealMigration, _i, todoMigrations_1, migration, migrationName, sqls, _a, sqls_1, sql, sql;
107
+ var todoMigrations, tableInfo, lastMigrationDate, lastRealMigration, _local_runSQL, _i, todoMigrations_1, migration, migrationName, sqls, _a, sqls_1, sql, sql;
108
+ var _this = this;
108
109
  var _b, _c;
109
110
  return __generator(this, function (_d) {
110
111
  switch (_d.label) {
@@ -125,6 +126,30 @@ var MySQLMigrations = /** @class */ (function () {
125
126
  case 3: return [2 /*return*/];
126
127
  case 4:
127
128
  lastRealMigration = (_c = migrationRecords_1 === null || migrationRecords_1 === void 0 ? void 0 : migrationRecords_1.find(function (r) { return r.table == table; })) === null || _c === void 0 ? void 0 : _c.lastMigrationTime;
129
+ _local_runSQL = function (sql) { return __awaiter(_this, void 0, void 0, function () {
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ if (!sql.toLowerCase().startsWith("alter table")) return [3 /*break*/, 2];
134
+ // log error if error
135
+ return [4 /*yield*/, mysqlInstance_1.runSQL(sql).catch(function (err) {
136
+ logger.error("Error while alter table:", err);
137
+ })];
138
+ case 1:
139
+ // log error if error
140
+ _a.sent();
141
+ return [3 /*break*/, 4];
142
+ case 2:
143
+ // throw error if error
144
+ return [4 /*yield*/, mysqlInstance_1.runSQL(sql)];
145
+ case 3:
146
+ // throw error if error
147
+ _a.sent();
148
+ _a.label = 4;
149
+ case 4: return [2 /*return*/];
150
+ }
151
+ });
152
+ }); };
128
153
  _i = 0, todoMigrations_1 = todoMigrations;
129
154
  _d.label = 5;
130
155
  case 5:
@@ -147,7 +172,7 @@ var MySQLMigrations = /** @class */ (function () {
147
172
  case 6:
148
173
  if (!(_a < sqls_1.length)) return [3 /*break*/, 9];
149
174
  sql = sqls_1[_a];
150
- return [4 /*yield*/, mysqlInstance_1.runSQL(sql)];
175
+ return [4 /*yield*/, _local_runSQL(sql)];
151
176
  case 7:
152
177
  _d.sent();
153
178
  _d.label = 8;
@@ -158,7 +183,7 @@ var MySQLMigrations = /** @class */ (function () {
158
183
  case 10:
159
184
  sql = utils_1.utils.replaceAll(migration.sql, "%{table_name}", table);
160
185
  logger.log(runnedMigrationsAmount_1, "| Migration will be runned:", migrationName, '|\n' + utils_1.terminalColors.cyan, sql.trim());
161
- return [4 /*yield*/, mysqlInstance_1.runSQL(sql)];
186
+ return [4 /*yield*/, _local_runSQL(sql)];
162
187
  case 11:
163
188
  _d.sent();
164
189
  _d.label = 12;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@klapeks/micro-db-utils",
3
3
  "description": "klapeks utils for db and other storages",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "type": "commonjs",
6
6
  "author": "Klapeks",
7
7
  "license": "ISC",