Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seed data for places #293

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon index.js"
"start": "nodemon index.js",
"seed": "node prisma/seed.js"
},
"keywords": [],
"author": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- A unique constraint covering the columns `[host]` on the table `Place` will be added. If there are existing duplicate values, this will fail.

*/
-- CreateIndex
CREATE UNIQUE INDEX "Place_host_key" ON "Place"("host");
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Warnings:

- A unique constraint covering the columns `[title]` on the table `Place` will be added. If there are existing duplicate values, this will fail.

*/
-- DropIndex
DROP INDEX "Place_host_key";

-- CreateIndex
CREATE UNIQUE INDEX "Place_title_key" ON "Place"("title");
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- DropIndex
DROP INDEX "Place_title_key";
110 changes: 52 additions & 58 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}
Expand All @@ -14,62 +8,62 @@ datasource db {
}

model User {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
name String
email String
password String
}

model Place {
id Int @id @default(autoincrement())
title String
host String
price String
accommodation String
address String
guests Int
bedrooms Int
beds Int
baths Int
starGrade Float
reviewsCount Int
highlightCheckIn String?
highlightAward String?
highlightWifi String?
highlightCancellation String?
amenitiesKitchen Boolean?
amenitiesWorkspace Boolean?
amenitiesSauna Boolean?
amenitiesBalcony Boolean?
amenitiesFireplace Boolean?
amenitiesWifi Boolean?
amenitiesParking Boolean?
amenitiesPets Boolean?
amenitiesBackyard Boolean?
amenitiesFirepit Boolean?
reviewSummaryTotalAvgRating Float
id Int @id @default(autoincrement())
title String
host String
price String
accommodation String
address String
guests Int
bedrooms Int
beds Int
baths Int
starGrade Float
reviewsCount Int
highlightCheckIn String?
highlightAward String?
highlightWifi String?
highlightCancellation String?
amenitiesKitchen Boolean?
amenitiesWorkspace Boolean?
amenitiesSauna Boolean?
amenitiesBalcony Boolean?
amenitiesFireplace Boolean?
amenitiesWifi Boolean?
amenitiesParking Boolean?
amenitiesPets Boolean?
amenitiesBackyard Boolean?
amenitiesFirepit Boolean?
reviewSummaryTotalAvgRating Float
reviewSummaryTotalReviewsCount Int
cleanlinessAvgRating Float
accuracyAvgRating Float
checkInAvgRating Float
communicationAvgRating Float
locationAvgRating Float
valueAvgRating Float
starTotalFiveStar Int
starTotalFourStar Int
starTotalThreeStar Int
starTotalTwoStar Int
starTotalOneStar Int
lon Float
lat Float
mapAddress String
mapAddressDescription String
hostName String
hostingDuration Int
role String
hostProfilePicUrl String
descriptionPlace String
descriptionSpace String
guestAccess String
otherThings String
}
cleanlinessAvgRating Float
accuracyAvgRating Float
checkInAvgRating Float
communicationAvgRating Float
locationAvgRating Float
valueAvgRating Float
starTotalFiveStar Int
starTotalFourStar Int
starTotalThreeStar Int
starTotalTwoStar Int
starTotalOneStar Int
lon Float
lat Float
mapAddress String
mapAddressDescription String
hostName String
hostingDuration Int
role String
hostProfilePicUrl String
descriptionPlace String
descriptionSpace String
guestAccess String
otherThings String
}
72 changes: 72 additions & 0 deletions server/prisma/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const {PrismaClient}= require('@prisma/client');
const places = require('../src/data/places.json');

const prisma = new PrismaClient();

async function main() {
for(const place of places) {
await prisma.place.create({
data: {
title: place.title,
host: place.host,
price: place.price,
accommodation: place.productSummary.accommodation,
address: place.productSummary.address,
guests: place.productSummary.guests.value,
bedrooms: place.productSummary.bedrooms.value,
beds: place.productSummary.beds.value,
baths: place.productSummary.baths.value,
starGrade: place.productSummary.starGrade,
reviewsCount: place.productSummary.reviews,
highlightCheckIn: place.highlights.find(h => h.type === "CHECK_IN")?.text || null,
highlightAward: place.highlights.find(h => h.type === "AWARD")?.text || null,
highlightWifi: place.highlights.find(h => h.type === "WIFI")?.text || null,
highlightCancellation: place.highlights.find(h => h.type === "CANCELLATION")?.text || null,
amenitiesKitchen: place.amenities.some(a => a.type === "kitchen"),
amenitiesWorkspace: place.amenities.some(a => a.type === "workspace"),
amenitiesSauna: place.amenities.some(a => a.type === "sauna"),
amenitiesBalcony: place.amenities.some(a => a.type === "balcony"),
amenitiesFireplace: place.amenities.some(a => a.type === "fireplace"),
amenitiesWifi: place.amenities.some(a => a.type === "wifi"),
amenitiesParking: place.amenities.some(a => a.type === "parking"),
amenitiesPets: place.amenities.some(a => a.type === "pets"),
amenitiesBackyard: place.amenities.some(a => a.type === "backyard"),
amenitiesFirepit: place.amenities.some(a => a.type === "firepit"),
reviewSummaryTotalAvgRating: place.reviewSummary.totalAvgRating,
reviewSummaryTotalReviewsCount: place.reviewSummary.totalReviewsCount,
cleanlinessAvgRating: place.reviewSummary.ratings.cleanlinessAvgRating,
accuracyAvgRating: place.reviewSummary.ratings.accuracyAvgRating,
checkInAvgRating: place.reviewSummary.ratings.checkInAvgRating,
communicationAvgRating: place.reviewSummary.ratings.communicationAvgRating,
locationAvgRating: place.reviewSummary.ratings.locationAvgRating,
valueAvgRating: place.reviewSummary.ratings.valueAvgRating,
starTotalFiveStar: place.reviewSummary.ratings.starTotals.fiveStar,
starTotalFourStar: place.reviewSummary.ratings.starTotals.fourStar,
starTotalThreeStar: place.reviewSummary.ratings.starTotals.threeStar,
starTotalTwoStar: place.reviewSummary.ratings.starTotals.twoStar,
starTotalOneStar: place.reviewSummary.ratings.starTotals.oneStar,
lon: place.mapView.lon,
lat: place.mapView.lat,
mapAddress: place.mapView.address,
mapAddressDescription: place.mapView.addressDescription,
hostName: place.hostSummary.hostName,
hostingDuration: place.hostSummary.hostingDuration,
role: place.hostSummary.role,
hostProfilePicUrl: place.hostSummary.profilePicUrl,
descriptionPlace: place.productDescription.descriptionPlace,
descriptionSpace: place.productDescription.descriptionSpace,
guestAccess: place.productDescription.guestAccess,
otherThings: place.productDescription.otherThings,
},
});
}
}

main()
.catch(e =>{
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
})
Loading