@projectinvicta/nails 3.0.4 → 3.0.6

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/lib/Nails.ts CHANGED
@@ -98,7 +98,8 @@ export default class Nails {
98
98
  async initializeModels() {
99
99
  await this.loadModels(this.config.service.MODELS_ROOT);
100
100
  await Promise.all(this.modelFinalizations.map((finalization) => finalization()));
101
- await this.sequelize.sync();
101
+ // TODO: Implement a migration strategy
102
+ await this.sequelize.sync({alter: {drop: false}});
102
103
  }
103
104
 
104
105
  async startServer() {
@@ -174,9 +175,13 @@ export default class Nails {
174
175
  const schema = modelModule.schema;
175
176
  const options = modelModule.options;
176
177
  const defer = modelModule.defer as (() => Promise<void>) | undefined;
178
+ const afterInitialize = modelModule.afterInitialize as (() => Promise<void>) | undefined;
177
179
  if (modelModule.finalize) {
178
180
  this.modelFinalizations.push(modelModule.finalize as () => Promise<void>);
179
181
  }
182
+ if (modelModule.afterInitializeAll) {
183
+ this.modelFinalizations.push(modelModule.afterInitializeAll as () => Promise<void>);
184
+ }
180
185
  this.modelMigrations.push(modelModule.migrate as () => Promise<void>);
181
186
 
182
187
  modelClass.init(schema, { sequelize: this.sequelize, ...options });
@@ -185,6 +190,9 @@ export default class Nails {
185
190
  if (defer) {
186
191
  await defer();
187
192
  }
193
+ if (afterInitialize) {
194
+ await afterInitialize();
195
+ }
188
196
  await modelClass.sync();
189
197
  }
190
198
  else console.warn("No model found at:", absolutePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectinvicta/nails",
3
- "version": "3.0.4",
3
+ "version": "3.0.6",
4
4
  "description": "A node.js webserver scaffold",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -10,5 +10,4 @@ export default class Dog extends Model {};
10
10
 
11
11
  export async function finalize() {
12
12
  Dog.belongsTo(Owner);
13
- await Dog.sync({alter: {drop: false}});
14
13
  }
@@ -9,5 +9,4 @@ export default class Owner extends Model {};
9
9
 
10
10
  export async function defer() {
11
11
  Owner.hasMany(Dog);
12
- await Dog.sync({alter: {drop: false}});
13
12
  }