extract-mysql-schema 0.4.0 → 0.5.0
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/package.json +1 -1
- package/run.js +38 -16
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -7,53 +7,75 @@ async function main(options) {
|
|
|
7
7
|
const result = await extractSchemas(config.connection,options);
|
|
8
8
|
|
|
9
9
|
if(options.writeSql){
|
|
10
|
-
|
|
10
|
+
const done = [];
|
|
11
11
|
const content = [];
|
|
12
|
+
const processFolder = function(seedPath) {
|
|
13
|
+
if(fs.existsSync(seedPath)) {
|
|
14
|
+
fs.readdirSync(seedPath).forEach(file => {
|
|
15
|
+
file = path.join(seedPath,file);
|
|
16
|
+
if(done.indexOf(file)<0){
|
|
17
|
+
content.push(fs.readFileSync(file,"utf8"));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const tablesPath=path.join(process.cwd(),"tables");
|
|
12
24
|
if(result[config.connection.database].tables.length>0) {
|
|
13
25
|
// write table sql
|
|
14
|
-
const tablesPath=path.join(process.cwd(),"tables")
|
|
15
26
|
if (!fs.existsSync(tablesPath)){
|
|
16
27
|
fs.mkdirSync(tablesPath);
|
|
17
28
|
}
|
|
18
29
|
const byName = {};
|
|
19
30
|
result[config.connection.database].tables.forEach(table => {
|
|
20
31
|
byName[table.name] = table.definition;
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
let file = path.join(tablesPath,table.name+".sql");
|
|
33
|
+
done.push(file);
|
|
34
|
+
if(options.verbose) console.log("writing",file);
|
|
35
|
+
fs.writeFileSync(file, table.definition ,"utf8")
|
|
23
36
|
});
|
|
24
37
|
|
|
25
38
|
result[config.connection.database].tableOrder.forEach(table => {
|
|
26
39
|
content.push(byName[table]);
|
|
27
40
|
})
|
|
28
41
|
}
|
|
42
|
+
processFolder(tablesPath);
|
|
29
43
|
|
|
44
|
+
const proceduresPath=path.join(process.cwd(),"procedures");
|
|
30
45
|
if(result[config.connection.database].procedures.length>0) {
|
|
31
46
|
// write routines
|
|
32
|
-
const proceduresPath=path.join(process.cwd(),"procedures")
|
|
33
47
|
if (!fs.existsSync(proceduresPath)){
|
|
34
48
|
fs.mkdirSync(proceduresPath);
|
|
35
49
|
}
|
|
36
50
|
result[config.connection.database].procedures.forEach(proc => {
|
|
37
|
-
|
|
51
|
+
let file = path.join(proceduresPath,proc.name+".sql");
|
|
52
|
+
done.push(file);
|
|
53
|
+
if(options.verbose) console.log("writing",file);
|
|
38
54
|
content.push(proc.definition);
|
|
39
|
-
fs.writeFileSync(
|
|
55
|
+
fs.writeFileSync(file, proc.definition ,"utf8")
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
processFolder(proceduresPath);
|
|
59
|
+
|
|
60
|
+
const seedPath = path.join(process.cwd(),"seed");
|
|
61
|
+
if(fs.existsSync(seedPath)) {
|
|
62
|
+
result[config.connection.database].tableOrder.forEach(table => {
|
|
63
|
+
let seedfile = path.join(seedPath,table+'.sql');
|
|
64
|
+
if (fs.existsSync(seedfile)){
|
|
65
|
+
done.push(seedfile);
|
|
66
|
+
content.push(fs.readFileSync(seedfile,"utf8"));
|
|
67
|
+
}
|
|
40
68
|
});
|
|
41
69
|
}
|
|
70
|
+
processFolder(seedPath);
|
|
71
|
+
|
|
72
|
+
processFolder(path.join(process.cwd(),"override"));
|
|
42
73
|
|
|
43
74
|
if(content.length>0) {
|
|
44
75
|
fs.writeFileSync(path.join(process.cwd(),"init.sql"), content.join('\n\n') ,"utf8");
|
|
45
76
|
}
|
|
46
77
|
}
|
|
47
78
|
|
|
48
|
-
const seedList = [];
|
|
49
|
-
result[config.connection.database].tableOrder.forEach(table => {
|
|
50
|
-
let seedfile = path.join(process.cwd(),"seed",table+'.sql');
|
|
51
|
-
seedList.push(seedfile);
|
|
52
|
-
if (!fs.existsSync(seedfile)){
|
|
53
|
-
content.push(fs.readFileSync(seedfile,"utf8"));
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
|
|
57
79
|
if(options.outputFile) {
|
|
58
80
|
fs.writeFileSync(path.join(process.cwd(),options.outputFile), JSON.stringify(result,null,2) ,"utf8")
|
|
59
81
|
} else console.log(JSON.stringify(result,null,2));
|