extract-mysql-schema 0.3.0 → 0.4.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 +21 -0
  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.4.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": "./run.js",
package/run.js CHANGED
@@ -7,16 +7,24 @@ async function main(options) {
7
7
  const result = await extractSchemas(config.connection,options);
8
8
 
9
9
  if(options.writeSql){
10
+
11
+ const content = [];
10
12
  if(result[config.connection.database].tables.length>0) {
11
13
  // write table sql
12
14
  const tablesPath=path.join(process.cwd(),"tables")
13
15
  if (!fs.existsSync(tablesPath)){
14
16
  fs.mkdirSync(tablesPath);
15
17
  }
18
+ const byName = {};
16
19
  result[config.connection.database].tables.forEach(table => {
20
+ byName[table.name] = table.definition;
17
21
  if(options.verbose) console.log("writing",path.join(tablesPath,table.name+".sql"));
18
22
  fs.writeFileSync(path.join(tablesPath,table.name+".sql"), table.definition ,"utf8")
19
23
  });
24
+
25
+ result[config.connection.database].tableOrder.forEach(table => {
26
+ content.push(byName[table]);
27
+ })
20
28
  }
21
29
 
22
30
  if(result[config.connection.database].procedures.length>0) {
@@ -27,12 +35,25 @@ async function main(options) {
27
35
  }
28
36
  result[config.connection.database].procedures.forEach(proc => {
29
37
  if(options.verbose) console.log("writing",path.join(proceduresPath,proc.name+".sql"));
38
+ content.push(proc.definition);
30
39
  fs.writeFileSync(path.join(proceduresPath,proc.name+".sql"), proc.definition ,"utf8")
31
40
  });
32
41
  }
33
42
 
43
+ if(content.length>0) {
44
+ fs.writeFileSync(path.join(process.cwd(),"init.sql"), content.join('\n\n') ,"utf8");
45
+ }
34
46
  }
35
47
 
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
+
36
57
  if(options.outputFile) {
37
58
  fs.writeFileSync(path.join(process.cwd(),options.outputFile), JSON.stringify(result,null,2) ,"utf8")
38
59
  } else console.log(JSON.stringify(result,null,2));