extract-mysql-schema 0.7.0 → 0.7.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.
- package/index.js +6 -7
- package/package.json +1 -1
- package/run.js +11 -7
package/index.js
CHANGED
|
@@ -80,7 +80,7 @@ const extractSchemas = async function (connection, options) {
|
|
|
80
80
|
FROM INFORMATION_SCHEMA.INNODB_INDEXES I
|
|
81
81
|
JOIN INFORMATION_SCHEMA.INNODB_FIELDS F on F.INDEX_ID=I.INDEX_ID
|
|
82
82
|
JOIN (
|
|
83
|
-
SELECT group_concat(FF.NAME) as INDEX_KEYS,FF.INDEX_ID
|
|
83
|
+
SELECT group_concat(FF.NAME ORDER BY FF.POS) as INDEX_KEYS,FF.INDEX_ID
|
|
84
84
|
FROM INFORMATION_SCHEMA.INNODB_FIELDS as FF
|
|
85
85
|
GROUP BY FF.INDEX_ID
|
|
86
86
|
) as F2 ON F2.INDEX_ID=F.INDEX_ID
|
|
@@ -323,15 +323,14 @@ create index ${idx['INDEX_NAME']}
|
|
|
323
323
|
params.push(param);
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
paramsDefinition = paramsDefinition.join('\n\t,');
|
|
326
|
+
paramsDefinition = paramsDefinition.join('\n\t,').trim();
|
|
327
|
+
if(paramsDefinition) paramsDefinition=`\n\t ${paramsDefinition}\n`;
|
|
327
328
|
|
|
328
|
-
|
|
329
|
+
definition = `
|
|
329
330
|
DELIMITER //
|
|
330
331
|
DROP PROCEDURE IF EXISTS ${name};
|
|
331
|
-
CREATE PROCEDURE ${name}(
|
|
332
|
-
|
|
333
|
-
)
|
|
334
|
-
${definition}
|
|
332
|
+
CREATE PROCEDURE ${name}(${paramsDefinition})
|
|
333
|
+
${definition};
|
|
335
334
|
//
|
|
336
335
|
DELIMITER ;
|
|
337
336
|
`;
|
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -8,14 +8,14 @@ async function main(options) {
|
|
|
8
8
|
|
|
9
9
|
if(options.writeSql){
|
|
10
10
|
const done = [];
|
|
11
|
-
|
|
11
|
+
let content = [];
|
|
12
12
|
const seedContent = [];
|
|
13
13
|
const sprocContent = [];
|
|
14
14
|
const tableContent = [];
|
|
15
15
|
|
|
16
16
|
content.push(`CREATE DATABASE IF NOT EXISTS ${config.connection.database};\nUSE ${config.connection.database};`);
|
|
17
17
|
|
|
18
|
-
const processFolder = function(seedPath,
|
|
18
|
+
const processFolder = function(seedPath,contentArray) {
|
|
19
19
|
if(fs.existsSync(seedPath)) {
|
|
20
20
|
fs.readdirSync(seedPath).forEach(file => {
|
|
21
21
|
file = path.join(seedPath,file);
|
|
@@ -26,6 +26,7 @@ async function main(options) {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
tableContent.push(`USE ${config.connection.database};`);
|
|
29
30
|
const tablesPath=path.join(process.cwd(),"tables");
|
|
30
31
|
if(result[config.connection.database].tables.length>0) {
|
|
31
32
|
// write table sql
|
|
@@ -44,10 +45,11 @@ async function main(options) {
|
|
|
44
45
|
result[config.connection.database].tableOrder.forEach(table => {
|
|
45
46
|
tableContent.push(byName[table]);
|
|
46
47
|
})
|
|
47
|
-
}
|
|
48
|
+
}
|
|
48
49
|
processFolder(tablesPath,tableContent); // add files not in the database
|
|
49
50
|
|
|
50
51
|
const proceduresPath=path.join(process.cwd(),"procedures");
|
|
52
|
+
proceduresPath.push(`USE ${config.connection.database};`);
|
|
51
53
|
if(result[config.connection.database].procedures.length>0) {
|
|
52
54
|
// write routines
|
|
53
55
|
if (!fs.existsSync(proceduresPath)){
|
|
@@ -64,6 +66,7 @@ async function main(options) {
|
|
|
64
66
|
processFolder(proceduresPath,sprocContent); // add files not in the database
|
|
65
67
|
|
|
66
68
|
const seedPath = path.join(process.cwd(),"seed");
|
|
69
|
+
proceduresPath.push(`USE ${config.connection.database};`);
|
|
67
70
|
if(fs.existsSync(seedPath)) {
|
|
68
71
|
result[config.connection.database].tableOrder.forEach(table => {
|
|
69
72
|
let seedfile = path.join(seedPath,table+'.sql');
|
|
@@ -76,21 +79,22 @@ async function main(options) {
|
|
|
76
79
|
processFolder(seedPath,seedContent); // add files not in the database
|
|
77
80
|
|
|
78
81
|
const patchContent=[];
|
|
82
|
+
patchContent.push(`USE ${config.connection.database};`);
|
|
79
83
|
processFolder(path.join(process.cwd(),"patch"), patchContent);
|
|
80
84
|
|
|
81
85
|
if(content.length>0) {
|
|
82
86
|
fs.writeFileSync(path.join(process.cwd(),"0.init.sql"), content.join('\n\n') ,"utf8");
|
|
83
87
|
}
|
|
84
|
-
if(tableContent.length>
|
|
88
|
+
if(tableContent.length>1) {
|
|
85
89
|
fs.writeFileSync(path.join(process.cwd(),"1.table.sql"), tableContent.join('\n\n') ,"utf8");
|
|
86
90
|
}
|
|
87
|
-
if(seedContent.length>
|
|
91
|
+
if(seedContent.length>1) {
|
|
88
92
|
fs.writeFileSync(path.join(process.cwd(),"2.seed.sql"), seedContent.join('\n\n') ,"utf8");
|
|
89
93
|
}
|
|
90
|
-
if(sprocContent.length>
|
|
94
|
+
if(sprocContent.length>1) {
|
|
91
95
|
fs.writeFileSync(path.join(process.cwd(),"3.procedures.sql"), sprocContent.join('\n\n') ,"utf8");
|
|
92
96
|
}
|
|
93
|
-
if(patchContent.length>
|
|
97
|
+
if(patchContent.length>1) {
|
|
94
98
|
fs.writeFileSync(path.join(process.cwd(),"4.patch.sql"), patchContent.join('\n\n') ,"utf8");
|
|
95
99
|
}
|
|
96
100
|
|