@itrocks/mysql-maintainer 0.0.13 → 0.0.14
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.
package/cjs/mysql-maintainer.js
CHANGED
|
@@ -24,6 +24,7 @@ const schema_diff_mysql_1 = require("@itrocks/schema-diff-mysql");
|
|
|
24
24
|
const schema_to_mysql_1 = require("@itrocks/schema-to-mysql");
|
|
25
25
|
const store_1 = require("@itrocks/store");
|
|
26
26
|
__exportStar(require("./mysql"), exports);
|
|
27
|
+
const DELETION = false;
|
|
27
28
|
class MysqlMaintainer {
|
|
28
29
|
connection;
|
|
29
30
|
constructor(connection) {
|
|
@@ -54,14 +55,10 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
54
55
|
const tableSchema = new reflect_to_schema_1.ReflectToTable().convert(type);
|
|
55
56
|
const schemaToMysql = new schema_to_mysql_1.SchemaToMysql();
|
|
56
57
|
const sql = schemaToMysql.sql(tableSchema);
|
|
57
|
-
console.log(sql);
|
|
58
58
|
await this.connection.query(sql);
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
async manageError(error, context, sql, values) {
|
|
62
|
-
console.log('query', sql, values);
|
|
63
|
-
console.log('throw', error);
|
|
64
|
-
console.log('context', context);
|
|
65
62
|
switch (error.code) {
|
|
66
63
|
case 'ER_BAD_FIELD_ERROR':
|
|
67
64
|
case 'ER_CANNOT_ADD_FOREIGN':
|
|
@@ -96,14 +93,14 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
96
93
|
new mysql_to_schema_1.MysqlToTable(this.connection).normalize(classTable);
|
|
97
94
|
const mysqlTable = await ((new mysql_to_schema_1.MysqlToTable(this.connection)).convert(tableName));
|
|
98
95
|
const schemaDiff = new schema_diff_1.TableDiff(mysqlTable, classTable);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
if (!schemaDiff.additions.length
|
|
97
|
+
&& !schemaDiff.changes.length
|
|
98
|
+
&& (!schemaDiff.deletions.length || !DELETION)
|
|
99
|
+
&& !schemaDiff.tableChanges()) {
|
|
103
100
|
return false;
|
|
104
101
|
}
|
|
105
102
|
const schemaDiffMysql = new schema_diff_mysql_1.SchemaDiffMysql();
|
|
106
|
-
const sql = schemaDiffMysql.sql(schemaDiff);
|
|
103
|
+
const sql = schemaDiffMysql.sql(schemaDiff, DELETION);
|
|
107
104
|
await this.connection.query(sql);
|
|
108
105
|
return true;
|
|
109
106
|
}
|
package/esm/mysql-maintainer.js
CHANGED
|
@@ -7,6 +7,7 @@ import { SchemaDiffMysql } from '@itrocks/schema-diff-mysql';
|
|
|
7
7
|
import { SchemaToMysql } from '@itrocks/schema-to-mysql';
|
|
8
8
|
import { storeOf } from '@itrocks/store';
|
|
9
9
|
export * from './mysql';
|
|
10
|
+
const DELETION = false;
|
|
10
11
|
export class MysqlMaintainer {
|
|
11
12
|
connection;
|
|
12
13
|
constructor(connection) {
|
|
@@ -37,14 +38,10 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
37
38
|
const tableSchema = new ReflectToTable().convert(type);
|
|
38
39
|
const schemaToMysql = new SchemaToMysql();
|
|
39
40
|
const sql = schemaToMysql.sql(tableSchema);
|
|
40
|
-
console.log(sql);
|
|
41
41
|
await this.connection.query(sql);
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
44
44
|
async manageError(error, context, sql, values) {
|
|
45
|
-
console.log('query', sql, values);
|
|
46
|
-
console.log('throw', error);
|
|
47
|
-
console.log('context', context);
|
|
48
45
|
switch (error.code) {
|
|
49
46
|
case 'ER_BAD_FIELD_ERROR':
|
|
50
47
|
case 'ER_CANNOT_ADD_FOREIGN':
|
|
@@ -79,14 +76,14 @@ CONSTRAINT \`${joinTable}.${table2}_id\` FOREIGN KEY (${table2}_id) REFERENCES \
|
|
|
79
76
|
new MysqlToTable(this.connection).normalize(classTable);
|
|
80
77
|
const mysqlTable = await ((new MysqlToTable(this.connection)).convert(tableName));
|
|
81
78
|
const schemaDiff = new TableDiff(mysqlTable, classTable);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
if (!schemaDiff.additions.length
|
|
80
|
+
&& !schemaDiff.changes.length
|
|
81
|
+
&& (!schemaDiff.deletions.length || !DELETION)
|
|
82
|
+
&& !schemaDiff.tableChanges()) {
|
|
86
83
|
return false;
|
|
87
84
|
}
|
|
88
85
|
const schemaDiffMysql = new SchemaDiffMysql();
|
|
89
|
-
const sql = schemaDiffMysql.sql(schemaDiff);
|
|
86
|
+
const sql = schemaDiffMysql.sql(schemaDiff, DELETION);
|
|
90
87
|
await this.connection.query(sql);
|
|
91
88
|
return true;
|
|
92
89
|
}
|
package/package.json
CHANGED