generated from Greenstand/treetracker-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from gwynndp/seed-files
Seed files
- Loading branch information
Showing
13 changed files
with
990,852 additions
and
51,074 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,31 @@ | ||
const captures = require('./data/Captures-1.json'); | ||
const uuid = require('uuid'); | ||
const captures = require('./data/20220210-Captures.json'); | ||
|
||
exports.seed = function (knex) { | ||
// Deletes ALL existing entries | ||
// return ( | ||
// knex('capture') | ||
// // .del() | ||
// .then(function () { | ||
// // Inserts seed entries | ||
return knex('capture').insert(captures); | ||
// }) | ||
// ); | ||
}; | ||
// takes the ~ 20,000 captures and splits them into batches of 1000 for seeding | ||
const batches = []; | ||
for (let i = 0; i < captures.length; i += 1000) { | ||
const batch = captures.slice(i, i + 1000); | ||
batches.push(batch); | ||
} | ||
|
||
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(); | ||
} | ||
|
||
/* EXAMPLE DATA */ | ||
console.log(index, batch.length); | ||
|
||
// [ | ||
// { | ||
// id: '6ab19f5c-931b-497c-887b-6da6a6572382', | ||
// reference_id: 1, // same as id? but set as integer not null | ||
// tree_id: null, | ||
// image_url: | ||
// 'https://treetracker-production-images.s3.eu-central-1.amazonaws.com/2021.03.17.23.33.54_8.43099064_-13.20422315_de873a43-c21a-40f8-adea-dfc58ef60468_IMG_20210311_123611_1990079067.jpg', | ||
// lat: 8.434773333333334, | ||
// lon: -13.201911666666668, | ||
// estimated_geographic_location: 'POINT (-13.208441666666666 8.430865)', | ||
// estimated_geometric_location: | ||
// 'SRID=4326;POINT (-13.208441666666666 8.430865)', | ||
// 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: 'ef01ef97-55a2-4474-9c25-821fe9c5917c', // NOT NULL | ||
// species_id: null, | ||
// morphology: null, | ||
// age: null, | ||
// note: null, | ||
// attributes: null, | ||
// domain_specific_data: null, | ||
// status: 'active', // active/deleted NOT NULL | ||
// created_at: '1/14/2022', | ||
// updated_at: '1/22/2022', | ||
// session_id: '6ab19f5c-931b-497c-887b-6da6a6572382', // NOT NULL | ||
// }, | ||
// ]; | ||
// Inserts seed entries | ||
return knex('capture').insert(batch); | ||
}), | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
const trees = require('./data/Trees-1.json'); | ||
const trees = require('./data/20220210-Trees.json'); | ||
|
||
exports.seed = function (knex) { | ||
// Deletes ALL existing entries | ||
// return ( | ||
// knex('capture') | ||
// // .del() | ||
// .then(function () { | ||
// // Inserts seed entries | ||
return knex('tree').insert(trees); | ||
// }) | ||
// ); | ||
return knex('tree') | ||
.del() | ||
.then(function () { | ||
return knex('tree').insert(trees); | ||
}); | ||
}; |
Oops, something went wrong.