-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
224 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import mongoose from "mongoose"; | ||
import products from "./mock.js"; | ||
import { Product } from "../models/product.js"; | ||
import { config } from "dotenv"; | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
config(); | ||
const prisma = new PrismaClient(); | ||
|
||
await mongoose.connect(process.env.DATABASE_URL); | ||
async function main() { | ||
try { | ||
await prisma.product.deleteMany({}); | ||
await prisma.product.createMany({ | ||
data: products, | ||
skipDuplicates: true, | ||
}); | ||
} catch (e) { | ||
throw e; | ||
} finally { | ||
await prisma.$disconnect(); | ||
} | ||
} | ||
|
||
await Product.deleteMany({}); | ||
await Product.insertMany(products); | ||
|
||
mongoose.connection.close(); | ||
// 실행 | ||
main().catch((e) => { | ||
process.exit(1); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
prisma/migrations/20241209095510_first_migrate_add_product_and_article/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-- CreateTable | ||
CREATE TABLE "Product" ( | ||
"id" TEXT NOT NULL, | ||
"name" TEXT NOT NULL, | ||
"description" TEXT NOT NULL, | ||
"price" INTEGER NOT NULL, | ||
"tags" TEXT[], | ||
"favoriteCount" INTEGER NOT NULL, | ||
"images" TEXT[], | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Product_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "Article" ( | ||
"id" TEXT NOT NULL, | ||
"title" TEXT NOT NULL, | ||
"content" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Article_pkey" PRIMARY KEY ("id") | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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" | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Product { | ||
id String @id @default(uuid()) | ||
name String | ||
description String | ||
price Int | ||
tags String[] | ||
favoriteCount Int | ||
images String[] | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
} | ||
|
||
model Article { | ||
id String @id @default(uuid()) | ||
title String | ||
content String | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as s from "superstruct"; | ||
import isEmail from "is-email"; | ||
import isUuid from "is-uuid"; | ||
|
||
export const CreateProduct = s.object({ | ||
name: s.size(s.string(), 1, 10), | ||
description: s.size(s.string(), 10, 100), | ||
price: s.min(s.number(), 0), | ||
tags: s.array(s.size(s.string(), 1, 5)), | ||
favoriteCount: s.optional(s.min(s.number(), 0)), | ||
images: s.optional(s.array(s.string())), | ||
}); | ||
|
||
const PatchProdcut = s.partial(CreateProduct); |