|
| 1 | +component { |
| 2 | + |
| 3 | + function up( schema, qb ) { |
| 4 | + schema.create( "inventory_batches", function( t ) { |
| 5 | + t.unsignedInteger( "id" ).primaryKey(); |
| 6 | + t.string( "name" ); |
| 7 | + } ); |
| 8 | + |
| 9 | + schema.create( "trades", function( t ) { |
| 10 | + t.increments( "id" ); |
| 11 | + t.unsignedInteger( "inventoryBatchId" ).references( "id" ).onTable( "inventory_batches" ); |
| 12 | + } ); |
| 13 | + |
| 14 | + qb.newQuery().table( "inventory_batches" ).insert( [ |
| 15 | + { "id": 1, "name": "Batch 1" }, |
| 16 | + { "id": 2, "name": "Batch 2" }, |
| 17 | + { "id": 3, "name": "Batch 3" } |
| 18 | + ] ); |
| 19 | + |
| 20 | + qb.table( "trades" ).insert( [ |
| 21 | + { "id": 1, "inventoryBatchId": 1 }, |
| 22 | + { "id": 2, "inventoryBatchId": 1 }, |
| 23 | + { "id": 3, "inventoryBatchId": 2 }, |
| 24 | + { "id": 4, "inventoryBatchId": 3 }, |
| 25 | + { "id": 5, "inventoryBatchId": 3 }, |
| 26 | + { "id": 6, "inventoryBatchId": 3 } |
| 27 | + ] ); |
| 28 | + } |
| 29 | + |
| 30 | + function down( schema, qb ) { |
| 31 | + schema.drop( "trades" ); |
| 32 | + schema.drop( "inventory_batches" ); |
| 33 | + } |
| 34 | + |
| 35 | +} |
0 commit comments