diff --git a/server/package.json b/server/package.json index bd7d9534..a024b66a 100644 --- a/server/package.json +++ b/server/package.json @@ -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": "", diff --git a/server/prisma/migrations/20241115114049_add_unique_constraint/migration.sql b/server/prisma/migrations/20241115114049_add_unique_constraint/migration.sql new file mode 100644 index 00000000..b01ca94f --- /dev/null +++ b/server/prisma/migrations/20241115114049_add_unique_constraint/migration.sql @@ -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"); diff --git a/server/prisma/migrations/20241115114119_add_unique_constraint/migration.sql b/server/prisma/migrations/20241115114119_add_unique_constraint/migration.sql new file mode 100644 index 00000000..4e002c2a --- /dev/null +++ b/server/prisma/migrations/20241115114119_add_unique_constraint/migration.sql @@ -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"); diff --git a/server/prisma/migrations/20241115114745_remove_unique_constraint/migration.sql b/server/prisma/migrations/20241115114745_remove_unique_constraint/migration.sql new file mode 100644 index 00000000..f31fe96c --- /dev/null +++ b/server/prisma/migrations/20241115114745_remove_unique_constraint/migration.sql @@ -0,0 +1,2 @@ +-- DropIndex +DROP INDEX "Place_title_key"; diff --git a/server/prisma/schema.prisma b/server/prisma/schema.prisma index 8db3f356..e948985f 100644 --- a/server/prisma/schema.prisma +++ b/server/prisma/schema.prisma @@ -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" } @@ -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 -} \ No newline at end of file + 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 +} diff --git a/server/prisma/seed.js b/server/prisma/seed.js new file mode 100644 index 00000000..5191db1a --- /dev/null +++ b/server/prisma/seed.js @@ -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(); + }) \ No newline at end of file