@verdnatura/myt 1.6.12 → 1.6.14

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/README.md CHANGED
@@ -191,6 +191,23 @@ You can create your local fixture and structure files.
191
191
  * *dump/fixtures.after.sql*
192
192
  * *dump/fixtures.local.sql*
193
193
 
194
+ ### Realms
195
+
196
+ You can create your local realms folders.
197
+
198
+ ```text
199
+ dump
200
+ `- realms
201
+ |- marvel
202
+ | `- 00-spiderman.sql
203
+ | `- 01-hulk.sql
204
+ `- dc
205
+ `- 00-superman.sql
206
+ `- 01-batman.sql
207
+ `- 02-wonder_woman.sql
208
+ `- 03-flash.sql
209
+ ```
210
+
194
211
  ## Versioning commands
195
212
 
196
213
  ### init
@@ -279,7 +296,7 @@ Builds and starts local database server container. It only rebuilds the image
279
296
  when dump have been modified.
280
297
 
281
298
  ```text
282
- $ myt run [-c|--ci] [-r|--random] [-t|--tmpfs] [-n|--network <string>]
299
+ $ myt run [<realm>|-m|--realm <string>] [-c|--ci] [-r|--random] [-t|--tmpfs] [-n|--network <string>]
283
300
  ```
284
301
 
285
302
  ### start
@@ -7,6 +7,9 @@ mockFunctions:
7
7
  - mockUtcTime
8
8
  sumViews: true
9
9
  defaultDefiner: root@localhost
10
+ localRemotes:
11
+ - local
12
+ - docker
10
13
  deprecMarkRegex: __$
11
14
  deprecCommentRegex: ^@deprecated [0-9]{4}-[0-9]{2}-[0-9]{2}
12
15
  deprecDateRegex: '[0-9]{4}-[0-9]{2}-[0-9]{2}'
package/myt-push.js CHANGED
@@ -371,9 +371,12 @@ class Push extends Command {
371
371
  const oldSql = await engine.fetchRoutine(type, schema, name);
372
372
  const oldSum = engine.getShaSum(type, schema, name);
373
373
 
374
+ const localRemote = opts.remote == null
375
+ || opts.localRemotes?.indexOf(opts.remote) !== -1;
376
+
374
377
  const isMockFn = type == 'function'
375
378
  && schema == opts.versionSchema
376
- && opts.remote == 'local'
379
+ && localRemote
377
380
  && opts.mockDate
378
381
  && opts.mockFunctions
379
382
  && opts.mockFunctions.indexOf(name) !== -1;
package/myt-run.js CHANGED
@@ -21,8 +21,10 @@ class Run extends Command {
21
21
  network: 'Docker network to attach container to',
22
22
  random: 'Whether to use a random container name and port',
23
23
  tmpfs: 'Whether to use tmpfs mount for MySQL data',
24
- keep: 'Keep container on failure'
25
- }
24
+ keep: 'Keep container on failure',
25
+ realm: 'Name of fixture realm to use'
26
+ },
27
+ operand: 'realm'
26
28
  };
27
29
 
28
30
  static opts = {
@@ -31,7 +33,8 @@ class Run extends Command {
31
33
  network: 'n',
32
34
  random: 'r',
33
35
  tmpfs: 't',
34
- keep: 'k'
36
+ keep: 'k',
37
+ realm: 'm'
35
38
  },
36
39
  boolean: [
37
40
  'ci',
@@ -47,6 +50,7 @@ class Run extends Command {
47
50
  waitingDb: 'Waiting for MySQL init process.',
48
51
  mockingDate: 'Mocking date functions.',
49
52
  applyingFixtures: 'Applying fixtures.',
53
+ applyingRealms: 'Applying realm fixtures.',
50
54
  creatingTriggers: 'Creating triggers.'
51
55
  };
52
56
 
@@ -185,11 +189,19 @@ class Run extends Command {
185
189
  ]
186
190
  for (const file of fixturesFiles) {
187
191
  if (!await fs.exists(`${dumpDir}/${file}.sql`)) continue;
188
- await ct.exec(null, 'docker-import.sh',
189
- [`/workspace/dump/${file}`],
190
- 'spawn',
191
- true
192
- );
192
+ await execFile(`dump/${file}`)
193
+ }
194
+
195
+ // Apply realms
196
+
197
+ if(opts.realm) {
198
+ this.emit('applyingRealms');
199
+ const realmDir = `realms/${opts.realm}`;
200
+ let realmFiles = await fs.readdir(`${dumpDir}/${realmDir}`);
201
+ realmFiles = realmFiles.map(file => path.parse(file).name);
202
+ for (const file of realmFiles) {
203
+ await execFile(`${realmDir}/${file}`)
204
+ }
193
205
  }
194
206
 
195
207
  // Create triggers
@@ -216,10 +228,18 @@ class Run extends Command {
216
228
  } catch (e) {}
217
229
  throw err;
218
230
  }
231
+
232
+ async function execFile(path){
233
+ await ct.exec(null, 'docker-import.sh',
234
+ [`/workspace/${path}` ],
235
+ 'spawn',
236
+ true
237
+ );
238
+ }
219
239
  }
220
240
  }
221
241
 
222
242
  module.exports = Run;
223
243
 
224
244
  if (require.main === module)
225
- new Myt().cli(Run);
245
+ new Myt().cli(Run);
package/myt.js CHANGED
@@ -21,7 +21,7 @@ class Myt {
21
21
  workspace: 'The base directory of the project',
22
22
  debug: 'Whether to enable debug mode',
23
23
  version: 'Display the version number and exit',
24
- help: 'Display this help message'
24
+ help: 'Display this help message',
25
25
  }
26
26
  };
27
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdnatura/myt",
3
- "version": "1.6.12",
3
+ "version": "1.6.14",
4
4
  "author": "Verdnatura Levante SL",
5
5
  "description": "MySQL version control",
6
6
  "license": "GPL-3.0",
@@ -12,3 +12,4 @@ RUN echo "[LOG] Import finished." \
12
12
  && rm -rf dump
13
13
 
14
14
  COPY fixtures.*.sql dump/
15
+ COPY realms realms/