Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
final-exam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
final-exam
Commits
d633fd8e
Commit
d633fd8e
authored
Sep 29, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prisma create schema for database and migrate
parent
502f668a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
294 additions
and
5 deletions
+294
-5
migration.sql
prisma/migrations/20230929051549_dev/migration.sql
+122
-0
migration.sql
prisma/migrations/20230929051908_/migration.sql
+92
-0
schema.prisma
prisma/schema.prisma
+80
-5
No files found.
prisma/migrations/20230929051549_dev/migration.sql
0 → 100644
View file @
d633fd8e
/*
Warnings:
- You are about to drop the `users` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
DROP
TABLE
`users`
;
-- CreateTable
CREATE
TABLE
`user`
(
`id`
INTEGER
NOT
NULL
AUTO_INCREMENT
,
`name`
VARCHAR
(
191
)
NOT
NULL
,
`email`
VARCHAR
(
191
)
NOT
NULL
,
`phone`
VARCHAR
(
191
)
NOT
NULL
,
`photo`
VARCHAR
(
191
)
NOT
NULL
,
`google_token`
VARCHAR
(
191
)
NOT
NULL
,
`username`
VARCHAR
(
191
)
NOT
NULL
,
`password`
VARCHAR
(
191
)
NOT
NULL
,
`rank`
BOOLEAN
NOT
NULL
,
`register_date`
DATETIME
(
3
)
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
(
3
),
UNIQUE
INDEX
`user_username_key`
(
`username`
),
PRIMARY
KEY
(
`id`
)
)
DEFAULT
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
;
-- CreateTable
CREATE
TABLE
`product`
(
`id`
INTEGER
NOT
NULL
AUTO_INCREMENT
,
`name`
VARCHAR
(
191
)
NOT
NULL
,
`detail`
VARCHAR
(
191
)
NOT
NULL
,
`price`
INTEGER
NOT
NULL
,
`discount`
INTEGER
NOT
NULL
,
`cateId`
INTEGER
NOT
NULL
,
`watch_count`
INTEGER
NOT
NULL
,
`buy_count`
INTEGER
NOT
NULL
,
`image`
VARCHAR
(
191
)
NOT
NULL
,
`stock`
INTEGER
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
)
DEFAULT
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
;
-- CreateTable
CREATE
TABLE
`category`
(
`id`
INTEGER
NOT
NULL
AUTO_INCREMENT
,
`name`
VARCHAR
(
191
)
NOT
NULL
,
UNIQUE
INDEX
`category_name_key`
(
`name`
),
PRIMARY
KEY
(
`id`
)
)
DEFAULT
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
;
-- CreateTable
CREATE
TABLE
`wishlist`
(
`id`
INTEGER
NOT
NULL
AUTO_INCREMENT
,
`productId`
INTEGER
NOT
NULL
,
`userId`
INTEGER
NOT
NULL
,
`date`
DATETIME
(
3
)
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
(
3
),
PRIMARY
KEY
(
`id`
)
)
DEFAULT
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
;
-- CreateTable
CREATE
TABLE
`cart`
(
`id`
INTEGER
NOT
NULL
AUTO_INCREMENT
,
`userId`
INTEGER
NOT
NULL
,
`productId`
INTEGER
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
)
DEFAULT
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
;
-- CreateTable
CREATE
TABLE
`order`
(
`id`
INTEGER
NOT
NULL
AUTO_INCREMENT
,
`userId`
INTEGER
NOT
NULL
,
`total_price`
INTEGER
NOT
NULL
,
`product_count`
INTEGER
NOT
NULL
,
`date`
DATETIME
(
3
)
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
(
3
),
`shipping_price`
INTEGER
NOT
NULL
,
`pay_status`
INTEGER
NOT
NULL
,
`send_status`
INTEGER
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
)
DEFAULT
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
;
-- CreateTable
CREATE
TABLE
`order_detail`
(
`id`
INTEGER
NOT
NULL
AUTO_INCREMENT
,
`orderId`
INTEGER
NOT
NULL
,
`userId`
INTEGER
NOT
NULL
,
`productId`
INTEGER
NOT
NULL
,
`product_price`
INTEGER
NOT
NULL
,
`product_discount`
INTEGER
NOT
NULL
,
PRIMARY
KEY
(
`id`
)
)
DEFAULT
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
;
-- AddForeignKey
ALTER
TABLE
`product`
ADD
CONSTRAINT
`product_cateId_fkey`
FOREIGN
KEY
(
`cateId`
)
REFERENCES
`category`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`wishlist`
ADD
CONSTRAINT
`wishlist_productId_fkey`
FOREIGN
KEY
(
`productId`
)
REFERENCES
`product`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`wishlist`
ADD
CONSTRAINT
`wishlist_userId_fkey`
FOREIGN
KEY
(
`userId`
)
REFERENCES
`user`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`cart`
ADD
CONSTRAINT
`cart_userId_fkey`
FOREIGN
KEY
(
`userId`
)
REFERENCES
`user`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`cart`
ADD
CONSTRAINT
`cart_productId_fkey`
FOREIGN
KEY
(
`productId`
)
REFERENCES
`product`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`order`
ADD
CONSTRAINT
`order_userId_fkey`
FOREIGN
KEY
(
`userId`
)
REFERENCES
`user`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`order_detail`
ADD
CONSTRAINT
`order_detail_orderId_fkey`
FOREIGN
KEY
(
`orderId`
)
REFERENCES
`order`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`order_detail`
ADD
CONSTRAINT
`order_detail_userId_fkey`
FOREIGN
KEY
(
`userId`
)
REFERENCES
`user`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`order_detail`
ADD
CONSTRAINT
`order_detail_productId_fkey`
FOREIGN
KEY
(
`productId`
)
REFERENCES
`product`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
prisma/migrations/20230929051908_/migration.sql
0 → 100644
View file @
d633fd8e
/*
Warnings:
- You are about to drop the column `productId` on the `cart` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `cart` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `order` table. All the data in the column will be lost.
- You are about to drop the column `orderId` on the `order_detail` table. All the data in the column will be lost.
- You are about to drop the column `productId` on the `order_detail` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `order_detail` table. All the data in the column will be lost.
- You are about to drop the column `productId` on the `wishlist` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `wishlist` table. All the data in the column will be lost.
- Added the required column `product_id` to the `cart` table without a default value. This is not possible if the table is not empty.
- Added the required column `user_id` to the `cart` table without a default value. This is not possible if the table is not empty.
- Added the required column `user_id` to the `order` table without a default value. This is not possible if the table is not empty.
- Added the required column `order_id` to the `order_detail` table without a default value. This is not possible if the table is not empty.
- Added the required column `product_id` to the `order_detail` table without a default value. This is not possible if the table is not empty.
- Added the required column `user_id` to the `order_detail` table without a default value. This is not possible if the table is not empty.
- Added the required column `product_id` to the `wishlist` table without a default value. This is not possible if the table is not empty.
- Added the required column `user_id` to the `wishlist` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER
TABLE
`cart`
DROP
FOREIGN
KEY
`cart_productId_fkey`
;
-- DropForeignKey
ALTER
TABLE
`cart`
DROP
FOREIGN
KEY
`cart_userId_fkey`
;
-- DropForeignKey
ALTER
TABLE
`order`
DROP
FOREIGN
KEY
`order_userId_fkey`
;
-- DropForeignKey
ALTER
TABLE
`order_detail`
DROP
FOREIGN
KEY
`order_detail_orderId_fkey`
;
-- DropForeignKey
ALTER
TABLE
`order_detail`
DROP
FOREIGN
KEY
`order_detail_productId_fkey`
;
-- DropForeignKey
ALTER
TABLE
`order_detail`
DROP
FOREIGN
KEY
`order_detail_userId_fkey`
;
-- DropForeignKey
ALTER
TABLE
`wishlist`
DROP
FOREIGN
KEY
`wishlist_productId_fkey`
;
-- DropForeignKey
ALTER
TABLE
`wishlist`
DROP
FOREIGN
KEY
`wishlist_userId_fkey`
;
-- AlterTable
ALTER
TABLE
`cart`
DROP
COLUMN
`productId`
,
DROP
COLUMN
`userId`
,
ADD
COLUMN
`product_id`
INTEGER
NOT
NULL
,
ADD
COLUMN
`user_id`
INTEGER
NOT
NULL
;
-- AlterTable
ALTER
TABLE
`order`
DROP
COLUMN
`userId`
,
ADD
COLUMN
`user_id`
INTEGER
NOT
NULL
;
-- AlterTable
ALTER
TABLE
`order_detail`
DROP
COLUMN
`orderId`
,
DROP
COLUMN
`productId`
,
DROP
COLUMN
`userId`
,
ADD
COLUMN
`order_id`
INTEGER
NOT
NULL
,
ADD
COLUMN
`product_id`
INTEGER
NOT
NULL
,
ADD
COLUMN
`user_id`
INTEGER
NOT
NULL
;
-- AlterTable
ALTER
TABLE
`wishlist`
DROP
COLUMN
`productId`
,
DROP
COLUMN
`userId`
,
ADD
COLUMN
`product_id`
INTEGER
NOT
NULL
,
ADD
COLUMN
`user_id`
INTEGER
NOT
NULL
;
-- AddForeignKey
ALTER
TABLE
`wishlist`
ADD
CONSTRAINT
`wishlist_product_id_fkey`
FOREIGN
KEY
(
`product_id`
)
REFERENCES
`product`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`wishlist`
ADD
CONSTRAINT
`wishlist_user_id_fkey`
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`cart`
ADD
CONSTRAINT
`cart_user_id_fkey`
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`cart`
ADD
CONSTRAINT
`cart_product_id_fkey`
FOREIGN
KEY
(
`product_id`
)
REFERENCES
`product`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`order`
ADD
CONSTRAINT
`order_user_id_fkey`
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`order_detail`
ADD
CONSTRAINT
`order_detail_order_id_fkey`
FOREIGN
KEY
(
`order_id`
)
REFERENCES
`order`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`order_detail`
ADD
CONSTRAINT
`order_detail_user_id_fkey`
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
-- AddForeignKey
ALTER
TABLE
`order_detail`
ADD
CONSTRAINT
`order_detail_product_id_fkey`
FOREIGN
KEY
(
`product_id`
)
REFERENCES
`product`
(
`id`
)
ON
DELETE
RESTRICT
ON
UPDATE
CASCADE
;
prisma/schema.prisma
View file @
d633fd8e
...
...
@@ -10,9 +10,84 @@ datasource db {
url
=
env
(
"DATABASE_URL"
)
}
model
users
{
id
Int
@
id
@
default
(
autoincrement
())
name
String
username
String
@
unique
password
String
model
user
{
id
Int
@
id
@
default
(
autoincrement
())
name
String
email
String
phone
String
photo
String
google_token
String
username
String
@
unique
password
String
rank
Boolean
register_date
DateTime
@
default
(
now
())
wishlist
wishlist
[]
cart
cart
[]
order
order
[]
order_detail
order_detail
[]
}
model
product
{
id
Int
@
id
@
default
(
autoincrement
())
name
String
detail
String
price
Int
discount
Int
cate
category
@
relation
(
fields
:
[
cateId
],
references
:
[
id
])
cateId
Int
watch_count
Int
buy_count
Int
image
String
stock
Int
wishlist
wishlist
[]
cart
cart
[]
order_detail
order_detail
[]
}
model
category
{
id
Int
@
id
@
default
(
autoincrement
())
name
String
@
unique
product
product
[]
}
model
wishlist
{
id
Int
@
id
@
default
(
autoincrement
())
product_id
Int
product
product
@
relation
(
fields
:
[
product_id
],
references
:
[
id
])
user_id
Int
user
user
@
relation
(
fields
:
[
user_id
],
references
:
[
id
])
date
DateTime
@
default
(
now
())
}
model
cart
{
id
Int
@
id
@
default
(
autoincrement
())
user_id
Int
user
user
@
relation
(
fields
:
[
user_id
],
references
:
[
id
])
product_id
Int
product
product
@
relation
(
fields
:
[
product_id
],
references
:
[
id
])
}
model
order
{
id
Int
@
id
@
default
(
autoincrement
())
user_id
Int
user
user
@
relation
(
fields
:
[
user_id
],
references
:
[
id
])
total_price
Int
product_count
Int
date
DateTime
@
default
(
now
())
shipping_price
Int
pay_status
Int
send_status
Int
order_detail
order_detail
[]
}
model
order_detail
{
id
Int
@
id
@
default
(
autoincrement
())
order_id
Int
order
order
@
relation
(
fields
:
[
order_id
],
references
:
[
id
])
user_id
Int
user
user
@
relation
(
fields
:
[
user_id
],
references
:
[
id
])
product_id
Int
product
product
@
relation
(
fields
:
[
product_id
],
references
:
[
id
])
product_price
Int
product_discount
Int
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment