extract-mysql-schema 0.6.6 → 0.7.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/run.js +35 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extract-mysql-schema",
3
- "version": "0.6.6",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": "./run.js",
package/run.js CHANGED
@@ -9,16 +9,18 @@ async function main(options) {
9
9
  if(options.writeSql){
10
10
  const done = [];
11
11
  const 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,fileList,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
- content.push(fs.readFileSync(file,"utf8"));
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
- content.push(byName[table]);
45
+ tableContent.push(byName[table]);
44
46
  })
45
- }
46
- processFolder(tablesPath);
47
+ }
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
- content.push(proc.definition);
59
- fs.writeFileSync(file, proc.definition ,"utf8")
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
- content.push(fs.readFileSync(seedfile,"utf8"));
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
- processFolder(path.join(process.cwd(),"override"));
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
  }