create-sip 1.4.1 → 1.4.3

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.
@@ -204,6 +204,41 @@ Generate a migration:
204
204
  node op make/migration thing
205
205
  ```
206
206
 
207
+ For example migration for employee table:
208
+
209
+ ```bash
210
+ node op make/migration employee
211
+ ```
212
+
213
+ ```javascript
214
+ import { DataTypes } from 'sequelize';
215
+
216
+ async function up({context: QueryInterface}) {
217
+ await QueryInterface.createTable('employees', {
218
+ id: {
219
+ allowNull: false,
220
+ autoIncrement: true,
221
+ primaryKey: true,
222
+ type: DataTypes.INTEGER
223
+ },
224
+ name: {
225
+ type: DataTypes.STRING
226
+ },
227
+ city: {
228
+ type: DataTypes.STRING
229
+ },
230
+ createdAt: { type: DataTypes.DATE },
231
+ updatedAt: { type: DataTypes.DATE }
232
+ });
233
+ }
234
+
235
+ async function down({context: QueryInterface}) {
236
+ await QueryInterface.dropTable('employees');
237
+ }
238
+
239
+ export { up, down }
240
+ ```
241
+
207
242
  Run all migration:
208
243
 
209
244
  ```bash
@@ -218,7 +253,7 @@ node op migration:run <migration_name>
218
253
  node op migrate <migration_name>
219
254
  ```
220
255
 
221
- Rollback a migration:
256
+ Rollback the last migration:
222
257
 
223
258
  ```bash
224
259
  node op migration:rollback
@@ -239,6 +274,8 @@ node op migration:reset
239
274
  node op migrate:reset
240
275
  ```
241
276
 
277
+ This command also undoes seeder operations.
278
+
242
279
  Reset the database and run all migrations:
243
280
 
244
281
  ```bash
@@ -254,6 +291,28 @@ Generate a seeder:
254
291
  node op make/seeder thing
255
292
  ```
256
293
 
294
+ Example seeder for employee table:
295
+
296
+ ```bash
297
+ node op make/seeder employee
298
+ ```
299
+
300
+ ```javascript
301
+
302
+ async function up({context: QueryInterface}) {
303
+ await QueryInterface.bulkInsert('employees', [
304
+ { id: 1, name: 'Joe Kitin' },
305
+ { id: 2, name: 'Peter Fall' }
306
+ ]);
307
+ }
308
+
309
+ async function down({context: QueryInterface}) {
310
+ await QueryInterface.bulkDelete('things', null, {});
311
+ }
312
+
313
+ export { up, down }
314
+ ````
315
+
257
316
  Run all seeders:
258
317
 
259
318
  ```bash
package/expressapi/op CHANGED
@@ -558,6 +558,8 @@ async function runMigrations() {
558
558
 
559
559
  async function resetMigrations() {
560
560
  console.log('Reset migrations...')
561
+ const umzugSeeder = await getUmzug('./database/seeders/*.js')
562
+ await umzugSeeder.down({ to: 0 })
561
563
  const umzug = await getUmzug('./database/migrations/*.js')
562
564
  await umzug.down({ to: 0 })
563
565
  }
@@ -637,7 +639,7 @@ async function runOneSeeder(name) {
637
639
  process.exit(1)
638
640
  }
639
641
 
640
- const umzug = await getUmzug('./database/seeders/*.js')
642
+ const umzug = await getUmzug(seederPath)
641
643
  await umzug.up()
642
644
  }
643
645
 
@@ -1,20 +1,12 @@
1
- import db from '../../app/models/modrels.js';
2
1
 
3
2
  async function up({context: QueryInterface}) {
4
- if(db.Thing) {
5
- await db.Thing.bulkCreate([
6
-
7
- ]);
8
- }else {
9
- await QueryInterface.bulkInsert('things', [
10
-
11
- ]);
12
- }
3
+ await QueryInterface.bulkInsert('things', [
13
4
 
5
+ ]);
14
6
  }
15
7
 
16
8
  async function down({context: QueryInterface}) {
17
- await QueryInterface.bulkDelete('things');
9
+ await QueryInterface.bulkDelete('things', null, {});
18
10
  }
19
11
 
20
12
  export { up, down }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sip",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "create-sip": "create-sip.js"