const { fakerLV : faker } = require('@faker-js/faker'); // const CATEGORIES = require('./categories.json'); 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 } */ exports.seed = async function(knex) { const categories = await knex('categories').select('id'); 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(), category_id: faker.helpers.arrayElement(categories.map(c => c.id)), } }; const places = new Array(PLACE_COUNT).fill(() => createPlace()).map((fn, i) => fn(i)); // Deletes ALL existing entries await knex('places').del() await knex('places').insert(places); };