zeche 0.0.8 → 0.1.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.
@@ -90,12 +90,25 @@ class DeployDatabase {
90
90
  }
91
91
  }
92
92
 
93
- const filename = `${TMP_DIR}/${fromEnvironment.db.database}__${moment().
93
+ let tmpDirFrom = TMP_DIR;
94
+ if (fromEnvironment.paths.tmpDir) {
95
+ tmpDirFrom = fromEnvironment.paths.tmpDir;
96
+ }
97
+
98
+ let tmpDirTo = TMP_DIR;
99
+ if (toEnvironment.paths.tmpDir) {
100
+ tmpDirTo = toEnvironment.paths.tmpDir;
101
+ }
102
+
103
+ const filenameFrom = `${tmpDirFrom}/${fromEnvironment.db.database}__${moment().
104
+ format('YYYY_MM_DD_HH_mm_ss')}.sql`;
105
+
106
+ const filenameTo = `${tmpDirTo}/${fromEnvironment.db.database}__${moment().
94
107
  format('YYYY_MM_DD_HH_mm_ss')}.sql`;
95
108
 
96
109
  /** 1. Export dump on source environment: */
97
110
  let exportCommands = [
98
- `mysqldump --opt -h ${fromEnvironment.db.host} -P ${fromEnvironment.db.port} -u ${fromEnvironment.db.user} -p'${fromEnvironment.db.password}' ${fromEnvironment.db.database} > ${filename}`,
111
+ `mysqldump --opt -h ${fromEnvironment.db.host} -P ${fromEnvironment.db.port} -u ${fromEnvironment.db.user} -p'${fromEnvironment.db.password}' ${fromEnvironment.db.database} > ${filenameFrom}`,
99
112
  ];
100
113
 
101
114
  /** Container exec for docker/vagrant: */
@@ -106,7 +119,7 @@ class DeployDatabase {
106
119
  }
107
120
 
108
121
  /** Create tmp dir: */
109
- exportCommands.unshift(`mkdir -p ${TMP_DIR}`);
122
+ exportCommands.unshift(`mkdir -p ${tmpDirFrom}`);
110
123
 
111
124
  if (this.services.sshService.useSsh(fromEnvironment)) {
112
125
  exportCommands = exportCommands.map(command => {
@@ -117,12 +130,12 @@ class DeployDatabase {
117
130
  this.services.execService.exec(exportCommands);
118
131
 
119
132
  /** 2. Copy dump to target environment: */
120
- this.services.syncService.sync(filename, filename, fromEnvironment,
133
+ this.services.syncService.sync(filenameFrom, filenameTo, fromEnvironment,
121
134
  toEnvironment);
122
135
 
123
136
  /** 3. Import dump on target environment: */
124
137
  let importCommands = [
125
- `mysql -h ${toEnvironment.db.host} -P ${toEnvironment.db.port} -u ${toEnvironment.db.user} -p'${toEnvironment.db.password}' ${toEnvironment.db.database} < ${filename}`,
138
+ `mysql -h ${toEnvironment.db.host} -P ${toEnvironment.db.port} -u ${toEnvironment.db.user} -p'${toEnvironment.db.password}' ${toEnvironment.db.database} < ${filenameTo}`,
126
139
  ];
127
140
 
128
141
  /** Container exec for docker/vagrant: */
@@ -132,6 +145,9 @@ class DeployDatabase {
132
145
  });
133
146
  }
134
147
 
148
+ /** Create tmp dir to: */
149
+ exportCommands.unshift(`mkdir -p ${tmpDirTo}`);
150
+
135
151
  if (this.services.sshService.useSsh(toEnvironment)) {
136
152
  importCommands = importCommands.map(command => {
137
153
  return this.services.sshService.wrapCommand(command, toEnvironment);
@@ -140,7 +156,7 @@ class DeployDatabase {
140
156
  this.services.execService.exec(importCommands);
141
157
 
142
158
  /** Remove dump on export environment: */
143
- let cleanUpExportCommands = [`rm ${filename}`];
159
+ let cleanUpExportCommands = [`rm ${filenameFrom}`];
144
160
  if (this.services.sshService.useSsh(fromEnvironment)) {
145
161
  cleanUpExportCommands = cleanUpExportCommands.map(command => {
146
162
  return this.services.sshService.wrapCommand(command, fromEnvironment);
@@ -149,7 +165,7 @@ class DeployDatabase {
149
165
  this.services.execService.exec(cleanUpExportCommands);
150
166
 
151
167
  /** Remove dump on import environment: */
152
- let cleanUpImportCommands = [`rm ${filename}`];
168
+ let cleanUpImportCommands = [`rm ${filenameTo}`];
153
169
  if (this.services.sshService.useSsh(toEnvironment)) {
154
170
  cleanUpImportCommands = cleanUpImportCommands.map(command => {
155
171
  return this.services.sshService.wrapCommand(command, toEnvironment);
@@ -160,4 +176,4 @@ class DeployDatabase {
160
176
 
161
177
  }
162
178
 
163
- module.exports = DeployDatabase;
179
+ module.exports = DeployDatabase;
@@ -2,7 +2,6 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const moment = require('moment');
5
- const TMP_DIR = '/tmp/zechetmp';
6
5
 
7
6
  module.exports = class DumpDatabase {
8
7
 
@@ -177,6 +176,7 @@ module.exports = class DumpDatabase {
177
176
  `mysql -h ${environment.db.host} -P ${environment.db.port} -u ${environment.db.user} -p'${environment.db.password}' ${environment.db.database} < ${path}/${fullFilename}`,
178
177
  ];
179
178
 
179
+
180
180
  /** Container exec for docker/vagrant: */
181
181
  if (environment.db.container_exec) {
182
182
  commands = commands.map(command => {
@@ -192,4 +192,4 @@ module.exports = class DumpDatabase {
192
192
 
193
193
  this.services.execService.exec(commands);
194
194
  }
195
- };
195
+ };
package/lib/action/ssh.js CHANGED
@@ -63,7 +63,6 @@ module.exports = class Ssh {
63
63
  }
64
64
 
65
65
  init(environment) {
66
- console.log('iniinit', environment);
67
66
  if (!_.has(this.config, `environments.${environment}`)) {
68
67
  this.services.outputService.print(
69
68
  `environment ${environment} does not exist in configuration`,
@@ -94,4 +93,4 @@ module.exports = class Ssh {
94
93
  this.services.execService.exec(commands);
95
94
 
96
95
  }
97
- };
96
+ };
@@ -33,4 +33,4 @@ class ExecService {
33
33
  }
34
34
  }
35
35
 
36
- module.exports = ExecService;
36
+ module.exports = ExecService;
@@ -84,4 +84,4 @@ class OutputService {
84
84
 
85
85
  }
86
86
 
87
- module.exports = OutputService;
87
+ module.exports = OutputService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zeche",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "CLI software project handling tool",
5
5
  "repository": {
6
6
  "type": "git",