This commit is contained in:
parent
30db53bd95
commit
0577555198
10
apps/blakus-api/seeds/_clean.js
Normal file
10
apps/blakus-api/seeds/_clean.js
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.seed = async function (knex) {
|
||||
await knex('places').del();
|
||||
await knex('subcategories').del();
|
||||
await knex('categories').del();
|
||||
await knex('users').del();
|
||||
};
|
||||
@ -1,10 +1,99 @@
|
||||
const CATEGORIES = require('./categories.json');
|
||||
const { randomUUID } = require("crypto");
|
||||
|
||||
const CUISINES = [
|
||||
"american",
|
||||
"argentinian",
|
||||
"armenian",
|
||||
"asian",
|
||||
"bakery",
|
||||
"bar_grill",
|
||||
"barbecue",
|
||||
"bavarian",
|
||||
"bbq",
|
||||
"belgian",
|
||||
"bistro",
|
||||
"breakfast",
|
||||
"bubble_tea",
|
||||
"burger",
|
||||
"cake",
|
||||
"caucasian",
|
||||
"chicken",
|
||||
"chinese",
|
||||
"chocolate",
|
||||
"coffee",
|
||||
"coffee_shop",
|
||||
"czech",
|
||||
"dessert",
|
||||
"donut",
|
||||
"eclair",
|
||||
"european",
|
||||
"falafel",
|
||||
"fast_food",
|
||||
"fine_dining",
|
||||
"fish",
|
||||
"french",
|
||||
"fries",
|
||||
"fusion",
|
||||
"georgian",
|
||||
"grill",
|
||||
"ice_cream",
|
||||
"indian",
|
||||
"international",
|
||||
"italian",
|
||||
"italian_pizza",
|
||||
"japanese",
|
||||
"jewish",
|
||||
"kebab",
|
||||
"korean",
|
||||
"latvian",
|
||||
"local",
|
||||
"lunch",
|
||||
"meat",
|
||||
"mediterranean",
|
||||
"mexican",
|
||||
"oriental",
|
||||
"oyster",
|
||||
"pancake",
|
||||
"pastry",
|
||||
"pizza",
|
||||
"ramen",
|
||||
"regional",
|
||||
"russian",
|
||||
"sandwich",
|
||||
"savory_pancakes",
|
||||
"seafood",
|
||||
"soup",
|
||||
"soviet",
|
||||
"steak_house",
|
||||
"sushi",
|
||||
"tapas",
|
||||
"tea",
|
||||
"traditional",
|
||||
"turkish",
|
||||
"ukrainian",
|
||||
"uzbek",
|
||||
"vietnamese",
|
||||
"waffle"
|
||||
]
|
||||
|
||||
const CATEGORIES = [
|
||||
{ id: randomUUID(), name: 'restaurant', subcategories: CUISINES.map(name => ({ id: randomUUID(), name })) },
|
||||
{ id: randomUUID(), name: 'cafe', subcategories: CUISINES.map(name => ({ id: randomUUID(), name })) },
|
||||
{ id: randomUUID(), name: 'bar', subcategories: CUISINES.map(name => ({ id: randomUUID(), name })) },
|
||||
{ id: randomUUID(), name: 'pub', subcategories: CUISINES.map(name => ({ id: randomUUID(), name })) },
|
||||
{ id: randomUUID(), name: 'biergarten', subcategories: CUISINES.map(name => ({ id: randomUUID(), name })) },
|
||||
{ id: randomUUID(), name: 'fast_food', subcategories: CUISINES.map(name => ({ id: randomUUID(), name })) },
|
||||
{ id: randomUUID(), name: 'food_court', subcategories: CUISINES.map(name => ({ id: randomUUID(), name })) },
|
||||
{ id: randomUUID(), name: 'ice_cream', subcategories: CUISINES.map(name => ({ id: randomUUID(), name })) },
|
||||
];
|
||||
|
||||
exports.CATEGORIES = CATEGORIES;
|
||||
|
||||
/**
|
||||
* @param { import("knex").Knex } knex
|
||||
* @returns { Promise<void> }
|
||||
*/
|
||||
exports.seed = async function (knex) {
|
||||
await knex('categories').del()
|
||||
await knex('categories').insert(CATEGORIES.map(({name}) => ({name})));
|
||||
await knex('categories').insert(CATEGORIES.map(({ name, id }) => ({ name, id })));
|
||||
await knex('subcategories').insert(CATEGORIES.flatMap(({ subcategories, id }) => subcategories.map((s) => ({ id: s.id, name: s.name, category_id: id }))));
|
||||
};
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
[
|
||||
{ "name": "restaurant", "subcategories": [] },
|
||||
{ "name": "cafe", "subcategories": [] },
|
||||
{ "name": "bar", "subcategories": [] },
|
||||
{ "name": "pub", "subcategories": [] },
|
||||
{ "name": "biergarten", "subcategories": [] },
|
||||
{ "name": "fast_food", "subcategories": [] },
|
||||
{ "name": "food_court", "subcategories": [] },
|
||||
{ "name": "ice_cream", "subcategories": [] }
|
||||
]
|
||||
@ -1,5 +1,6 @@
|
||||
const { fakerLV : faker } = require('@faker-js/faker');
|
||||
// const CATEGORIES = require('./categories.json');
|
||||
const { CATEGORIES } = require('./categories.js');
|
||||
const { randomUUID } = require('crypto');
|
||||
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;
|
||||
@ -10,8 +11,6 @@ const [ BBOX_MIN_LAT, BBOX_MIN_LON, BBOX_MAX_LAT, BBOX_MAX_LON ] = BBOX_RIGA;
|
||||
*/
|
||||
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 }),
|
||||
@ -19,6 +18,7 @@ exports.seed = async function(knex) {
|
||||
];
|
||||
|
||||
return {
|
||||
id: randomUUID(),
|
||||
name: faker.company.name(),
|
||||
coordinates: knex.raw('ST_SetSRID(ST_MakePoint(?, ?), 4326)', coords),
|
||||
country: 'LV',
|
||||
@ -28,13 +28,27 @@ exports.seed = async function(knex) {
|
||||
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)),
|
||||
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()
|
||||
const placeSubcategories = places.flatMap(place => {
|
||||
const options = CATEGORIES.find(category => category.id === place.category_id).subcategories;
|
||||
const subcategoryCount = faker.number.int({ min: 0, max: 4 });
|
||||
const subcategories = new Set();
|
||||
|
||||
for (let i = 0; i <= subcategoryCount; i++) {
|
||||
subcategories.add(faker.helpers.arrayElement(options));
|
||||
}
|
||||
|
||||
return Array.from(subcategories).map(subcategory => ({
|
||||
place_id: place.id,
|
||||
subcategory_id: subcategory.id
|
||||
}));
|
||||
});
|
||||
|
||||
await knex('places').insert(places);
|
||||
await knex('place_subcategories').insert(placeSubcategories);
|
||||
};
|
||||
|
||||
@ -21,7 +21,6 @@ exports.seed = async function(knex) {
|
||||
}
|
||||
};
|
||||
|
||||
await knex('users').del()
|
||||
await knex('users').insert([
|
||||
createUser({
|
||||
first_name: 'Broks Randolfs',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user