@keltoi/hydra 2.3.3 → 2.3.5

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/index.js +15 -11
  2. package/package.json +2 -4
package/index.js CHANGED
@@ -358,10 +358,11 @@ class Migration{
358
358
  .#db('migration')
359
359
  .where({ name })
360
360
  .update({ iteration })
361
-
362
- #create = ({ iteration=0,name='' })=>this
363
- .#db('migration')
364
- .insert({ iteration,name })
361
+ .then(affected=>{
362
+ if (affected == 0) return this
363
+ .#db('migration')
364
+ .insert({ iteration,name })
365
+ })
365
366
 
366
367
  async runMigrations({ entity = Entity, migrations=[async ()=>{}] }){
367
368
  const name = entity.name;
@@ -372,12 +373,11 @@ class Migration{
372
373
 
373
374
  if (iteration >= listSize) return
374
375
 
375
- for (let index = iteration; index < listSize; index++) {
376
- await migrations[index]();
377
- }
376
+ for (let index = iteration; index < listSize; index++)
377
+ await migrations[index]()
378
+ .catch(err=>console.log(err));
378
379
 
379
- if (listSize === 1) await this.#create({ iteration:listSize,name });
380
- else await this.#update({ iteration:listSize,name });
380
+ await this.#update({ iteration:listSize,name });
381
381
  }
382
382
 
383
383
  static structMe(db=knex()){
@@ -431,9 +431,13 @@ let Context$2 = class Context{
431
431
  const migration = new Migration(this.#db);
432
432
 
433
433
  const promises = models.map(model=>
434
- model.structMe(this.#db)
434
+ model
435
+ .structMe(this.#db)
435
436
  .then(()=>migration
436
- .runMigrations({ entity: model, migrations: model.migrations(this.#db) })
437
+ .runMigrations({
438
+ entity: model,
439
+ migrations: model.migrations(this.#db)
440
+ })
437
441
  )
438
442
  );
439
443
 
package/package.json CHANGED
@@ -1,12 +1,10 @@
1
1
  {
2
2
  "name": "@keltoi/hydra",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "Boilerplate to start your API from zero using Repository Pattern",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
7
- "files": [
8
- "index.js"
9
- ],
7
+ "files": [ "index.js" ],
10
8
  "type": "module",
11
9
  "scripts": {
12
10
  "test": "npm run build & npm link",