38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
const { fakerLV : faker } = require('@faker-js/faker');
|
|
|
|
const PLACE_COUNT = 1000;
|
|
const BBOX_RIGA = [23.755875,56.815914,24.466553,57.067617];
|
|
const [ BBOX_MIN_LAT, BBOX_MIN_LON, BBOX_MAX_LAT, BBOX_MAX_LON ] = BBOX_RIGA;
|
|
|
|
/**
|
|
* @param { import("knex").Knex } knex
|
|
* @returns { Promise<void> }
|
|
*/
|
|
exports.seed = async function(knex) {
|
|
|
|
const createPlace = () => {
|
|
const coords = [
|
|
faker.location.latitude({ min: BBOX_MIN_LAT, max: BBOX_MAX_LAT }),
|
|
faker.location.longitude({ min: BBOX_MIN_LON, max: BBOX_MAX_LON })
|
|
];
|
|
|
|
return {
|
|
name: faker.company.name(),
|
|
coordinates: knex.raw('ST_SetSRID(ST_MakePoint(?, ?), 4326)', coords),
|
|
country: 'LV',
|
|
county: faker.helpers.arrayElement(['Kurzemes', 'Latgales', 'Rīgas', 'Vidzemes', 'Zemgales']),
|
|
district: faker.location.state(),
|
|
city: faker.location.city(),
|
|
street: faker.location.street(),
|
|
house: faker.helpers.maybe(() => faker.person.lastName(), { probability: 0.1 }) || faker.location.buildingNumber(),
|
|
postalCode: faker.location.zipCode(),
|
|
}
|
|
};
|
|
|
|
// Deletes ALL existing entries
|
|
await knex('places').del()
|
|
await knex('places').insert([
|
|
...new Array(PLACE_COUNT).fill(() => createPlace()).map((fn, i) => fn(i)),
|
|
]);
|
|
};
|