extract-mysql-schema 0.6.6 → 0.7.1
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 +35 -12
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,17 +8,19 @@ async function main(options) {
|
|
|
8
8
|
|
|
9
9
|
if(options.writeSql){
|
|
10
10
|
const done = [];
|
|
11
|
-
|
|
11
|
+
let content = [];
|
|
12
|
+
const seedContent = [];
|
|
13
|
+
const sprocContent = [];
|
|
14
|
+
const tableContent = [];
|
|
12
15
|
|
|
13
16
|
content.push(`CREATE DATABASE IF NOT EXISTS ${config.connection.database};\nUSE ${config.connection.database};`);
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
const processFolder = function(seedPath) {
|
|
18
|
+
const processFolder = function(seedPath,contentArray) {
|
|
17
19
|
if(fs.existsSync(seedPath)) {
|
|
18
20
|
fs.readdirSync(seedPath).forEach(file => {
|
|
19
21
|
file = path.join(seedPath,file);
|
|
20
22
|
if(done.indexOf(file)<0){
|
|
21
|
-
|
|
23
|
+
contentArray.push(fs.readFileSync(file,"utf8"));
|
|
22
24
|
}
|
|
23
25
|
});
|
|
24
26
|
}
|
|
@@ -40,10 +42,10 @@ async function main(options) {
|
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
result[config.connection.database].tableOrder.forEach(table => {
|
|
43
|
-
|
|
45
|
+
tableContent.push(byName[table]);
|
|
44
46
|
})
|
|
45
47
|
}
|
|
46
|
-
processFolder(tablesPath);
|
|
48
|
+
processFolder(tablesPath,tableContent); // add files not in the database
|
|
47
49
|
|
|
48
50
|
const proceduresPath=path.join(process.cwd(),"procedures");
|
|
49
51
|
if(result[config.connection.database].procedures.length>0) {
|
|
@@ -55,11 +57,11 @@ async function main(options) {
|
|
|
55
57
|
let file = path.join(proceduresPath,proc.name+".sql");
|
|
56
58
|
done.push(file);
|
|
57
59
|
if(options.verbose) console.log("writing",file);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
fs.writeFileSync(file, proc.definition ,"utf8");
|
|
61
|
+
sprocContent.push(proc.definition);
|
|
60
62
|
});
|
|
61
63
|
}
|
|
62
|
-
processFolder(proceduresPath);
|
|
64
|
+
processFolder(proceduresPath,sprocContent); // add files not in the database
|
|
63
65
|
|
|
64
66
|
const seedPath = path.join(process.cwd(),"seed");
|
|
65
67
|
if(fs.existsSync(seedPath)) {
|
|
@@ -67,14 +69,35 @@ async function main(options) {
|
|
|
67
69
|
let seedfile = path.join(seedPath,table+'.sql');
|
|
68
70
|
if (fs.existsSync(seedfile)){
|
|
69
71
|
done.push(seedfile);
|
|
70
|
-
|
|
72
|
+
seedContent.push(fs.readFileSync(seedfile,"utf8"));
|
|
71
73
|
}
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
|
-
processFolder(seedPath);
|
|
76
|
+
processFolder(seedPath,seedContent); // add files not in the database
|
|
77
|
+
|
|
78
|
+
const patchContent=[];
|
|
79
|
+
processFolder(path.join(process.cwd(),"patch"), patchContent);
|
|
75
80
|
|
|
76
|
-
|
|
81
|
+
if(content.length>0) {
|
|
82
|
+
fs.writeFileSync(path.join(process.cwd(),"0.init.sql"), content.join('\n\n') ,"utf8");
|
|
83
|
+
}
|
|
84
|
+
if(tableContent.length>0) {
|
|
85
|
+
fs.writeFileSync(path.join(process.cwd(),"1.table.sql"), tableContent.join('\n\n') ,"utf8");
|
|
86
|
+
}
|
|
87
|
+
if(seedContent.length>0) {
|
|
88
|
+
fs.writeFileSync(path.join(process.cwd(),"2.seed.sql"), seedContent.join('\n\n') ,"utf8");
|
|
89
|
+
}
|
|
90
|
+
if(sprocContent.length>0) {
|
|
91
|
+
fs.writeFileSync(path.join(process.cwd(),"3.procedures.sql"), sprocContent.join('\n\n') ,"utf8");
|
|
92
|
+
}
|
|
93
|
+
if(patchContent.length>0) {
|
|
94
|
+
fs.writeFileSync(path.join(process.cwd(),"4.patch.sql"), patchContent.join('\n\n') ,"utf8");
|
|
95
|
+
}
|
|
77
96
|
|
|
97
|
+
content=content.concat(tableContent);
|
|
98
|
+
content=content.concat(seedContent);
|
|
99
|
+
content=content.concat(sprocContent);
|
|
100
|
+
content=content.concat(patchContent);
|
|
78
101
|
if(content.length>0) {
|
|
79
102
|
fs.writeFileSync(path.join(process.cwd(),"init.sql"), content.join('\n\n') ,"utf8");
|
|
80
103
|
}
|