diff --git a/next/.env.example b/next/.env.example new file mode 100644 index 000000000..6d6948f78 --- /dev/null +++ b/next/.env.example @@ -0,0 +1,3 @@ +POSTGRES_PRISMA_URL=postgresql://postgres:postgres@localhost:5433/myapp +POSTGRES_URL_NON_POOLING=postgresql://postgres:postgres@localhost:5433/myapp +NEXT_PUBLIC_DSN=... \ No newline at end of file diff --git a/next/.gitignore b/next/.gitignore index e985853ed..96fd40ffa 100644 --- a/next/.gitignore +++ b/next/.gitignore @@ -1 +1,4 @@ .vercel +.env + +migrations \ No newline at end of file diff --git a/next/README.md b/next/README.md index 6f3e455da..a1646b649 100644 --- a/next/README.md +++ b/next/README.md @@ -1,6 +1,34 @@ -## About +## Local Development -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +### Database Setup + +1. Start the PostgreSQL database using Docker Compose: + +```bash +docker compose up -d +``` + +2. Create a `.env` file in the root directory using `.env.example` as a template: + +e.g. + +```bash +POSTGRES_PRISMA_URL=postgresql://postgres:postgres@localhost:5433/myapp +POSTGRES_URL_NON_POOLING=postgresql://postgres:postgres@localhost:5433/myapp +NEXT_PUBLIC_DSN=... +``` + +3. Initialize the database schema: + +```bash +npx prisma migrate dev --name init +``` + +4. Seed the database with initial data: + +```bash +npx prisma db seed +``` ## Deploy diff --git a/next/docker-compose.yml b/next/docker-compose.yml new file mode 100644 index 000000000..585e1e686 --- /dev/null +++ b/next/docker-compose.yml @@ -0,0 +1,16 @@ +services: + db: + image: postgres:15 + restart: always + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - POSTGRES_DB=myapp + ports: + - '5433:5432' + volumes: + - db:/var/lib/postgresql/data + +volumes: + db: + driver: local diff --git a/next/package-lock.json b/next/package-lock.json index 00d5064a8..e940fba6f 100644 --- a/next/package-lock.json +++ b/next/package-lock.json @@ -45,7 +45,8 @@ "npm": "^10.8.2", "prettier": "^3.3.3", "react-app-rewired": "~2.2.1", - "redux-mock-store": "^1.5.4" + "redux-mock-store": "^1.5.4", + "ts-node": "^10.9.2" }, "engines": { "node": ">=18.0.0 <19.0.0", @@ -1908,6 +1909,28 @@ "version": "0.2.3", "license": "MIT" }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "devOptional": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "devOptional": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@csstools/normalize.css": { "version": "12.1.1", "license": "CC0-1.0" @@ -6821,6 +6844,30 @@ "node": ">=10.13.0" } }, + "node_modules/@tsconfig/node10": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", + "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", + "devOptional": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "devOptional": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "devOptional": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "devOptional": true + }, "node_modules/@types/aria-query": { "version": "5.0.4", "license": "MIT", @@ -9077,6 +9124,12 @@ "node": ">=10" } }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "devOptional": true + }, "node_modules/cross-spawn": { "version": "7.0.3", "license": "MIT", @@ -9726,6 +9779,15 @@ "version": "1.2.2", "license": "Apache-2.0" }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "devOptional": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/diff-sequences": { "version": "29.6.3", "license": "MIT", @@ -16326,6 +16388,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "devOptional": true + }, "node_modules/makeerror": { "version": "1.0.12", "license": "BSD-3-Clause", @@ -23607,6 +23675,67 @@ "version": "0.1.13", "license": "Apache-2.0" }, + "node_modules/ts-node": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", + "devOptional": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/ts-node/node_modules/acorn-walk": { + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", + "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", + "devOptional": true, + "dependencies": { + "acorn": "^8.11.0" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/ts-node/node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "devOptional": true + }, "node_modules/tsconfig-paths": { "version": "3.15.0", "license": "MIT", @@ -23962,6 +24091,12 @@ "uuid": "dist/bin/uuid" } }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "devOptional": true + }, "node_modules/v8-to-istanbul": { "version": "8.1.1", "license": "ISC", @@ -24922,6 +25057,15 @@ "node": ">=8" } }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "devOptional": true, + "engines": { + "node": ">=6" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "license": "MIT", diff --git a/next/package.json b/next/package.json index 98693fa68..f4f0e7636 100644 --- a/next/package.json +++ b/next/package.json @@ -11,6 +11,7 @@ "@testing-library/react": "~11.1.0", "@testing-library/user-event": "~12.1.10", "@vercel/postgres": "^0.10.0", + "dompurify": "^3.1.7", "history": "~5.3.0", "next": "^15.0.1", "prisma": "^5.21.1", @@ -22,8 +23,7 @@ "react-scripts": "~5.0.1", "redux": "~4.1.0", "redux-logger": "~3.0.6", - "web-vitals": "~1.0.1", - "dompurify": "^3.1.7" + "web-vitals": "~1.0.1" }, "scripts": { "dev": "next dev", @@ -76,10 +76,14 @@ "npm": "^10.8.2", "prettier": "^3.3.3", "react-app-rewired": "~2.2.1", - "redux-mock-store": "^1.5.4" + "redux-mock-store": "^1.5.4", + "ts-node": "^10.9.2" }, "volta": { "node": "18.19.1", "npm": "10.5.0" + }, + "prisma": { + "seed": "ts-node seed.ts" } -} +} \ No newline at end of file diff --git a/next/seed.ts b/next/seed.ts new file mode 100644 index 000000000..0bc1c7713 --- /dev/null +++ b/next/seed.ts @@ -0,0 +1,94 @@ +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +async function main() { + // Seed products + const products = await prisma.products.createMany({ + data: [ + { + title: 'Mood Planter', + description: 'A stylish planter that adds character to any room', + descriptionfull: + 'This unique planter brings both style and functionality to your space. Perfect for small to medium-sized plants, its modern design complements any interior décor.', + price: 2999, // $29.99 + img: '/assets/mood-planter.jpg', + imgcropped: '/assets/mood-planter-cropped.jpg', + }, + { + title: 'Spider Plant', + description: 'Easy-care spider plant that purifies your air', + descriptionfull: + 'The Spider Plant is one of the most adaptable houseplants and is perfect for beginners. These plants are excellent air purifiers and look great in hanging baskets.', + price: 1999, // $19.99 + img: '/assets/plant-spider.jpg', + imgcropped: '/assets/plant-spider-cropped.jpg', + }, + { + title: 'Text Plant', + description: 'A decorative plant with unique text-like patterns', + descriptionfull: + 'This fascinating plant features distinctive leaf patterns that resemble text, making it a perfect conversation starter. Low maintenance and suitable for indoor environments.', + price: 2499, // $24.99 + img: '/assets/plant-to-text.jpg', + imgcropped: '/assets/plant-to-text-cropped.jpg', + }, + ], + }); + + // Seed inventory + const inventory = await prisma.inventory.createMany({ + data: [ + { + sku: 'MOOD-001', + count: 25, + productid: 1, + }, + { + sku: 'SPDR-001', + count: 30, + productid: 2, + }, + { + sku: 'TEXT-001', + count: 20, + productid: 3, + }, + ], + }); + + // Seed reviews + const reviews = await prisma.reviews.createMany({ + data: [ + { + productid: 1, + rating: 5, + customerid: 1, + description: 'Beautiful planter, perfect size for my snake plant!', + }, + { + productid: 2, + rating: 5, + customerid: 2, + description: 'My spider plant is thriving and so easy to care for.', + }, + { + productid: 3, + rating: 4, + customerid: 3, + description: 'Unique plant, gets lots of comments from visitors.', + }, + ], + }); + + console.log('Database has been seeded! 🌱'); +} + +main() + .catch((e) => { + console.error(e); + process.exit(1); + }) + .finally(async () => { + await prisma.$disconnect(); + });