extract-mysql-schema 0.3.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/run.js +49 -6
  3. package/schema.json +0 -18534
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extract-mysql-schema",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": "./run.js",
package/run.js CHANGED
@@ -7,30 +7,73 @@ async function main(options) {
7
7
  const result = await extractSchemas(config.connection,options);
8
8
 
9
9
  if(options.writeSql){
10
+ const done = [];
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");
10
24
  if(result[config.connection.database].tables.length>0) {
11
25
  // write table sql
12
- const tablesPath=path.join(process.cwd(),"tables")
13
26
  if (!fs.existsSync(tablesPath)){
14
27
  fs.mkdirSync(tablesPath);
15
28
  }
29
+ const byName = {};
16
30
  result[config.connection.database].tables.forEach(table => {
17
- if(options.verbose) console.log("writing",path.join(tablesPath,table.name+".sql"));
18
- fs.writeFileSync(path.join(tablesPath,table.name+".sql"), table.definition ,"utf8")
31
+ byName[table.name] = table.definition;
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")
19
36
  });
37
+
38
+ result[config.connection.database].tableOrder.forEach(table => {
39
+ content.push(byName[table]);
40
+ })
20
41
  }
42
+ processFolder(tablesPath);
21
43
 
44
+ const proceduresPath=path.join(process.cwd(),"procedures");
22
45
  if(result[config.connection.database].procedures.length>0) {
23
46
  // write routines
24
- const proceduresPath=path.join(process.cwd(),"procedures")
25
47
  if (!fs.existsSync(proceduresPath)){
26
48
  fs.mkdirSync(proceduresPath);
27
49
  }
28
50
  result[config.connection.database].procedures.forEach(proc => {
29
- if(options.verbose) console.log("writing",path.join(proceduresPath,proc.name+".sql"));
30
- fs.writeFileSync(path.join(proceduresPath,proc.name+".sql"), proc.definition ,"utf8")
51
+ let file = path.join(proceduresPath,proc.name+".sql");
52
+ done.push(file);
53
+ if(options.verbose) console.log("writing",file);
54
+ content.push(proc.definition);
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
+ }
31
68
  });
32
69
  }
70
+ processFolder(seedPath);
33
71
 
72
+ processFolder(path.join(process.cwd(),"override"));
73
+
74
+ if(content.length>0) {
75
+ fs.writeFileSync(path.join(process.cwd(),"init.sql"), content.join('\n\n') ,"utf8");
76
+ }
34
77
  }
35
78
 
36
79
  if(options.outputFile) {