@itrocks/mysql-maintainer 0.2.1 → 0.2.3

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.
@@ -57,7 +57,7 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
57
57
  switch (error.code) {
58
58
  case 'ER_BAD_FIELD_ERROR':
59
59
  case 'ER_CANNOT_ADD_FOREIGN':
60
- return await this.updateContextTables(context);
60
+ return this.updateContextTables(context);
61
61
  case 'ER_NO_SUCH_TABLE':
62
62
  const tableName = /Table '.*?\.(.*?)'/.exec(error.message)?.[1];
63
63
  return this.updateContextTables(context, tableName);
@@ -65,6 +65,7 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
65
65
  return false;
66
66
  }
67
67
  async updateContextTables(context, tableName) {
68
+ let result = false;
68
69
  const contexts = Array.isArray(context) ? context : [context];
69
70
  for (const context of contexts) {
70
71
  const type = (0, class_type_1.typeOf)(context);
@@ -73,12 +74,12 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
73
74
  throw 'No table name for type';
74
75
  }
75
76
  const exists = (await this.connection.query('SHOW TABLES LIKE ?', tableName));
76
- await (exists.length ? this.updateTable(type) : this.createTable(type));
77
+ result ||= await (exists.length ? this.updateTable(type) : this.createTable(type));
77
78
  }
78
79
  if ((contexts.length === 2) && (this.implicitTableName(contexts[0], contexts[1]) === tableName)) {
79
- await this.createImplicitTable(contexts[0], contexts[1]);
80
+ result ||= await this.createImplicitTable(contexts[0], contexts[1]);
80
81
  }
81
- return true;
82
+ return result;
82
83
  }
83
84
  async updateTable(type) {
84
85
  const tableName = (0, store_1.storeOf)(type);
@@ -53,7 +53,7 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
53
53
  switch (error.code) {
54
54
  case 'ER_BAD_FIELD_ERROR':
55
55
  case 'ER_CANNOT_ADD_FOREIGN':
56
- return await this.updateContextTables(context);
56
+ return this.updateContextTables(context);
57
57
  case 'ER_NO_SUCH_TABLE':
58
58
  const tableName = /Table '.*?\.(.*?)'/.exec(error.message)?.[1];
59
59
  return this.updateContextTables(context, tableName);
@@ -61,6 +61,7 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
61
61
  return false;
62
62
  }
63
63
  async updateContextTables(context, tableName) {
64
+ let result = false;
64
65
  const contexts = Array.isArray(context) ? context : [context];
65
66
  for (const context of contexts) {
66
67
  const type = typeOf(context);
@@ -69,12 +70,12 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
69
70
  throw 'No table name for type';
70
71
  }
71
72
  const exists = (await this.connection.query('SHOW TABLES LIKE ?', tableName));
72
- await (exists.length ? this.updateTable(type) : this.createTable(type));
73
+ result ||= await (exists.length ? this.updateTable(type) : this.createTable(type));
73
74
  }
74
75
  if ((contexts.length === 2) && (this.implicitTableName(contexts[0], contexts[1]) === tableName)) {
75
- await this.createImplicitTable(contexts[0], contexts[1]);
76
+ result ||= await this.createImplicitTable(contexts[0], contexts[1]);
76
77
  }
77
- return true;
78
+ return result;
78
79
  }
79
80
  async updateTable(type) {
80
81
  const tableName = storeOf(type);
package/package.json CHANGED
@@ -57,5 +57,5 @@
57
57
  "build:esm": "tsc -p tsconfig.esm.json"
58
58
  },
59
59
  "types": "./esm/mysql-maintainer.d.ts",
60
- "version": "0.2.1"
60
+ "version": "0.2.3"
61
61
  }