Skip to content

Commit

Permalink
feat: update capture seed file to batch seed from json file
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Feb 24, 2022
1 parent 36a2ca2 commit fa15082
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 61 deletions.
66 changes: 18 additions & 48 deletions database/seeds/02_captures.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,23 @@ exports.seed = function (knex) {
batches.push(batch);
}

return Promise.all(
batches.map((batch) => {
// add session_id and device_configuration_id to each
for (let i = 0; i < batch.length; i += 1) {
const item = batch[i];
item.session_id = uuid.v4();
item.device_configuration_id = uuid.v4();
}
return knex('capture')
.del()
.then(function () {
return Promise.all(
batches.map((batch, index) => {
// add session_id and device_configuration_id to each
for (let i = 0; i < batch.length; i += 1) {
const item = batch[i];
item.session_id = uuid.v4();
item.device_configuration_id = uuid.v4();
}

// console.log(i, batch.length)
return knex('capture').insert(batch);
}),
);
};

/* EXAMPLE DATA */
console.log(index, batch.length);

// [
// {
// id: '6ab19f5c-931b-497c-887b-6da6a6572382',
// reference_id: 1, // -------- references original integer tree id
// tree_id: null,
// image_url:
// 'https://treetracker-production-images.s3.eu-central-1.amazonaws.com/some.jpg',
// lat: 8.434773333333334,
// lon: -13.201911666666668,
// estimated_geographic_location: 'POINT (-13.208441666666666 8.430865)',
// estimated_geometric_location: // -------- add 'SRID=4326;' to the front of the geographic_location,
// gps_accuracy: null,
// grower_id: '85fff895-33c8-4d89-a9b9-60b722beab60',
// grower_photo_url: null,
// grower_username: 'enexfy0',
// planting_organization_id: 'b972cb35-17ba-4c0a-8a63-7487f70d2a26',
// device_configuration_id: // -------- NOT NULL
// species_id: null,
// morphology: null,
// age: null,
// note: null,
// attributes: null,
// domain_specific_data: null,
// status: 'active', // -------- active/deleted, NOT NULL
// captured_at: '1/14/2022',
// created_at: '1/14/2022',
// updated_at: '1/22/2022',
// session_id: // -------- NOT NULL
// },
// ];

// DELETE FROM treetracker.capture
// WHERE session_id is null ;
// Inserts seed entries
return knex('capture').insert(batch);
}),
);
});
};
9 changes: 9 additions & 0 deletions database/seeds/03_trees.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const trees = require('./data/20220210-Trees.json');

exports.seed = function (knex) {
return knex('tree')
.del()
.then(function () {
return knex('tree').insert(trees);
});
};
13 changes: 0 additions & 13 deletions database/seeds/ignore_seed/03_trees.js

This file was deleted.

0 comments on commit fa15082

Please sign in to comment.