Skip to content

Commit 3bff269

Browse files
committed
feat: Implement backend for bulk CSV product upload
1 parent d03a689 commit 3bff269

36 files changed

Lines changed: 1580 additions & 339 deletions

File tree

prisma/migrations/20240414064137_added_category_table_and_added_role_column/migration.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- AlterTable
2-
ALTER TABLE `user` ADD COLUMN `role` VARCHAR(191) NULL DEFAULT 'user';
2+
ALTER TABLE `User` ADD COLUMN `role` VARCHAR(191) NULL DEFAULT 'user';
33

44
-- CreateTable
55
CREATE TABLE `Category` (
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
Warnings:
33
4-
- You are about to drop the column `category` on the `product` table. All the data in the column will be lost.
4+
- You are about to drop the column `category` on the `Product` table. All the data in the column will be lost.
55
- Added the required column `categoryId` to the `Product` table without a default value. This is not possible if the table is not empty.
66
77
*/
88
-- AlterTable
9-
ALTER TABLE `product` DROP COLUMN `category`,
9+
ALTER TABLE `Product` DROP COLUMN `category`,
1010
ADD COLUMN `categoryId` VARCHAR(191) NOT NULL;

prisma/migrations/20240418151340_added_new_customer_order_table/migration.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
*/
77
-- DropTable
8-
DROP TABLE `order`;
8+
DROP TABLE IF EXISTS `Order`;
99

1010
-- CreateTable
1111
CREATE TABLE `Customer_order` (

prisma/migrations/20240515154444_added_necessary_fields_for_customer_order_table/migration.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
77
*/
88
-- AlterTable
9-
ALTER TABLE `customer_order` ADD COLUMN `city` VARCHAR(191) NOT NULL,
9+
ALTER TABLE `Customer_order` ADD COLUMN `city` VARCHAR(191) NOT NULL,
1010
ADD COLUMN `country` VARCHAR(191) NOT NULL,
1111
ADD COLUMN `orderNotice` VARCHAR(191) NULL;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- DropForeignKey
2-
ALTER TABLE `wishlist` DROP FOREIGN KEY `Wishlist_userId_fkey`;
2+
ALTER TABLE `Wishlist` DROP FOREIGN KEY `Wishlist_userId_fkey`;
33

44
-- AddForeignKey
55
ALTER TABLE `Wishlist` ADD CONSTRAINT `Wishlist_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- DropForeignKey
2-
ALTER TABLE `product` DROP FOREIGN KEY `Product_categoryId_fkey`;
2+
ALTER TABLE `Product` DROP FOREIGN KEY `Product_categoryId_fkey`;
33

44
-- AddForeignKey
55
ALTER TABLE `Product` ADD CONSTRAINT `Product_categoryId_fkey` FOREIGN KEY (`categoryId`) REFERENCES `Category`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- DropForeignKey
2-
ALTER TABLE `wishlist` DROP FOREIGN KEY `Wishlist_productId_fkey`;
2+
ALTER TABLE `Wishlist` DROP FOREIGN KEY `Wishlist_productId_fkey`;
33

44
-- AddForeignKey
55
ALTER TABLE `Wishlist` ADD CONSTRAINT `Wishlist_productId_fkey` FOREIGN KEY (`productId`) REFERENCES `Product`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
2-
# It should be added in your version-control system (i.e. Git)
3-
provider = "mysql"
2+
# It should be added in your version-control system (e.g., Git)
3+
provider = "mysql"

prisma/schema.prisma

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ model Product {
2727
category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade)
2828
customerOrders customer_order_product[]
2929
Wishlist Wishlist[]
30+
// Back relation for bulk upload items
31+
bulkUploadItems bulk_upload_item[] @relation("ProductBulkItems")
3032
}
3133

3234
model Image {
@@ -41,6 +43,8 @@ model User {
4143
password String?
4244
role String? @default("user")
4345
Wishlist Wishlist[]
46+
// Back relation for bulk upload batches
47+
bulkUploadBatches bulk_upload_batch[] @relation("UserBatches")
4448
}
4549

4650
model Customer_order {
@@ -84,3 +88,52 @@ model Wishlist {
8488
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
8589
userId String
8690
}
91+
92+
model bulk_upload_batch {
93+
id String @id @default(uuid())
94+
createdAt DateTime @default(now())
95+
status BulkUploadStatus @default(PENDING)
96+
itemCount Int @default(0)
97+
errorCount Int @default(0)
98+
items bulk_upload_item[]
99+
100+
// optional uploader link if you later associate sessions/users
101+
userId String?
102+
user User? @relation(name: "UserBatches", fields: [userId], references: [id])
103+
}
104+
105+
model bulk_upload_item {
106+
id String @id @default(uuid())
107+
batchId String
108+
batch bulk_upload_batch @relation(fields: [batchId], references: [id], onDelete: Cascade)
109+
110+
// created product reference
111+
productId String?
112+
product Product? @relation(name: "ProductBulkItems", fields: [productId], references: [id], onDelete: SetNull)
113+
114+
// snapshot fields for auditing and re-commit edits
115+
title String
116+
slug String
117+
price Int
118+
manufacturer String?
119+
description String?
120+
mainImage String?
121+
categoryId String
122+
inStock Int
123+
124+
status BulkUploadItemStatus @default(CREATED)
125+
error String?
126+
}
127+
128+
enum BulkUploadStatus {
129+
PENDING
130+
COMPLETED
131+
PARTIAL
132+
FAILED
133+
}
134+
135+
enum BulkUploadItemStatus {
136+
CREATED
137+
UPDATED
138+
ERROR
139+
}

product.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
title,price,description,manufacturer,category,inStock,mainImage,rating
2+
"Samsung Galaxy S24 Ultra","15999999","Smartphone flagship dengan kamera 200MP dan S Pen","Samsung","Smartphones","50","/samsung-s24.jpg","5"
3+
"iPhone 15 Pro Max","17999999","iPhone terbaru dengan chip A17 Pro dan kamera titanium","Apple","Smartphones","30","/iphone-15.jpg","5"
4+
"MacBook Pro M3","25999999","Laptop untuk profesional dengan chip M3 yang powerful","Apple","Laptops","20","/macbook-m3.jpg","4"
5+
"Sony WH-1000XM5","4999999","Headphone noise cancelling terbaik dari Sony","Sony","Headphones","75","/sony-wh1000xm5.jpg","4"

0 commit comments

Comments
 (0)