extract-mysql-schema 0.7.5 → 0.7.7
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/index.js +14 -34
- package/package.json +2 -6
package/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
const orderBy = require("lodash.orderby");
|
|
2
|
+
const mysql = require('mysql2/promise');
|
|
4
3
|
|
|
5
4
|
const spaceTabs = function(list) {
|
|
6
5
|
const cols=[];
|
|
@@ -26,48 +25,29 @@ const spaceTabs = function(list) {
|
|
|
26
25
|
return lines;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
const getAdapter = async function (connection) {
|
|
31
|
-
let adapter = new SequelizeAdapter(connection.database, connection.user, connection.password, {
|
|
32
|
-
host: connection.Host,
|
|
33
|
-
dialect: "mysql",
|
|
34
|
-
logging: false,
|
|
35
|
-
pool: {
|
|
36
|
-
max: 5,
|
|
37
|
-
min: 0,
|
|
38
|
-
idle: 10000
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return adapter;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
28
|
const extractSchemas = async function (connection, options) {
|
|
45
29
|
const schemaName = connection.database;
|
|
46
30
|
options = options || {};
|
|
47
31
|
|
|
48
|
-
let
|
|
49
|
-
|
|
50
|
-
let queryProcedures = await adapter.query(`
|
|
32
|
+
let c = await mysql.createConnection(connection);
|
|
33
|
+
let [queryProcedures] = await c.query(`
|
|
51
34
|
SELECT * FROM INFORMATION_SCHEMA.ROUTINES where ROUTINE_SCHEMA = '${schemaName}'
|
|
52
35
|
`);
|
|
53
|
-
queryProcedures=queryProcedures[0];
|
|
54
36
|
|
|
55
|
-
let queryParameters = await
|
|
37
|
+
let [queryParameters] = await c.query(`
|
|
56
38
|
SELECT p.* FROM INFORMATION_SCHEMA.PARAMETERS as p join INFORMATION_SCHEMA.ROUTINES as r on p.SPECIFIC_NAME=r.SPECIFIC_NAME and p.SPECIFIC_SCHEMA=r.ROUTINE_SCHEMA
|
|
57
39
|
WHERE ROUTINE_SCHEMA='${schemaName}'
|
|
58
40
|
ORDER BY p.SPECIFIC_NAME,p.ORDINAL_POSITION
|
|
59
41
|
`);
|
|
60
|
-
queryParameters=queryParameters[0];
|
|
61
42
|
|
|
62
|
-
let queryFkey = await
|
|
43
|
+
let [queryFkey] = await c.query(`
|
|
63
44
|
SELECT iif.*, iifc.FOR_COL_NAME, iifc.REF_COL_NAME
|
|
64
45
|
FROM INFORMATION_SCHEMA.INNODB_FOREIGN as iif
|
|
65
46
|
JOIN INFORMATION_SCHEMA.INNODB_FOREIGN_COLS as iifc on iifc.ID=iif.ID
|
|
66
47
|
WHERE iif.ID LIKE '${schemaName}/%'
|
|
67
48
|
`);
|
|
68
|
-
queryFkey=queryFkey[0];
|
|
69
49
|
|
|
70
|
-
let queryIndexes = await
|
|
50
|
+
let [queryIndexes] = await c.query(`
|
|
71
51
|
select
|
|
72
52
|
T2.TABLE_SCHEMA,T2.TABLE_NAME,I.NAME as INDEX_NAME,
|
|
73
53
|
C.COLUMN_TYPE as FIELD_TYPE,
|
|
@@ -91,9 +71,8 @@ const extractSchemas = async function (connection, options) {
|
|
|
91
71
|
WHERE T2.TABLE_SCHEMA = '${schemaName}' and F.POS=0
|
|
92
72
|
ORDER BY T2.TABLE_SCHEMA,T2.TABLE_NAME,I.NAME,F.POS
|
|
93
73
|
`);
|
|
94
|
-
queryIndexes=queryIndexes[0];
|
|
95
74
|
|
|
96
|
-
let queryColumns = await
|
|
75
|
+
let [queryColumns] = await c.query(`
|
|
97
76
|
SELECT T.TABLE_TYPE,C.*,
|
|
98
77
|
CASE WHEN EXISTS(SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS C2 WHERE C2.TABLE_SCHEMA=C.TABLE_SCHEMA and C2.TABLE_NAME=C.TABLE_NAME AND C2.COLUMN_KEY='PRI' AND C.COLUMN_KEY='PRI' AND C2.COLUMN_NAME<>C.COLUMN_NAME) THEN 'YES' ELSE 'NO' END AS IS_COMPOUND_KEY
|
|
99
78
|
,TP.PARTITION_METHOD,TP.PARTITION_EXPRESSION
|
|
@@ -103,9 +82,8 @@ const extractSchemas = async function (connection, options) {
|
|
|
103
82
|
where C.TABLE_SCHEMA ='${schemaName}'
|
|
104
83
|
order by C.TABLE_NAME,C.ORDINAL_POSITION
|
|
105
84
|
`);
|
|
106
|
-
queryColumns = queryColumns[0];
|
|
107
85
|
|
|
108
|
-
|
|
86
|
+
c.end();
|
|
109
87
|
|
|
110
88
|
const foreign = {};
|
|
111
89
|
for(let i=0;i<queryFkey.length;i++) {
|
|
@@ -293,21 +271,23 @@ create index ${idx['INDEX_NAME']}
|
|
|
293
271
|
}
|
|
294
272
|
}
|
|
295
273
|
tableOrder.sort();
|
|
274
|
+
let minpos = tableOrder.length;
|
|
296
275
|
|
|
297
276
|
hasParent.forEach((child)=>{
|
|
298
277
|
let tableColumns = schema[child];
|
|
299
|
-
let pos
|
|
278
|
+
let pos=minpos;
|
|
300
279
|
tableColumns.forEach((column)=>{
|
|
301
280
|
column.references.forEach((reference)=>{
|
|
302
281
|
let pos2 = tableOrder.indexOf(reference.tableName);
|
|
303
|
-
|
|
304
|
-
if(pos2<0) { if(tableOrder.indexOf(reference.tableName)<0) { tableOrder.push(reference.tableName); } }
|
|
282
|
+
if(pos2<0) { tableOrder.push(reference.tableName); pos=tableOrder.length }
|
|
305
283
|
else if(pos2+1>pos) pos=pos2+1;
|
|
306
284
|
});
|
|
307
285
|
});
|
|
308
286
|
if(tableOrder.indexOf(child)<0) {
|
|
309
287
|
if(pos<0) tableOrder.push(child);
|
|
310
|
-
else
|
|
288
|
+
else {
|
|
289
|
+
tableOrder.splice(pos,0,child);
|
|
290
|
+
}
|
|
311
291
|
}
|
|
312
292
|
});
|
|
313
293
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extract-mysql-schema",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": "./run.js",
|
|
@@ -18,10 +18,6 @@
|
|
|
18
18
|
"author": "Chris Doty",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"mysql2": "^3.
|
|
22
|
-
"sequelize": "^6.34.0"
|
|
23
|
-
},
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"lodash.orderby": "^4.6.0"
|
|
21
|
+
"mysql2": "^3.9.3"
|
|
26
22
|
}
|
|
27
23
|
}
|