This commit is contained in:
2025-09-08 18:30:34 +00:00
parent c116a85ead
commit a93493fb62
15 changed files with 134 additions and 182 deletions

View File

@@ -0,0 +1,18 @@
/*
Warnings:
- You are about to drop the column `premiumViews` on the `content` table. All the data in the column will be lost.
- You are about to drop the column `validViews` on the `content` table. All the data in the column will be lost.
- You are about to drop the column `views` on the `content` table. All the data in the column will be lost.
- You are about to drop the column `watchTime` on the `content` table. All the data in the column will be lost.
- You are about to drop the `costPerView` table. If the table is not empty, all the data it contains will be lost.
*/
-- AlterTable
ALTER TABLE `content` DROP COLUMN `premiumViews`,
DROP COLUMN `validViews`,
DROP COLUMN `views`,
DROP COLUMN `watchTime`;
-- DropTable
DROP TABLE `costPerView`;

View File

@@ -0,0 +1,49 @@
/*
Warnings:
- You are about to drop the `ContentHandle` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `userHandle` table. If the table is not empty, all the data it contains will be lost.
- Added the required column `handleId` to the `content` table without a default value. This is not possible if the table is not empty.
*/
-- DropForeignKey
ALTER TABLE `ContentHandle` DROP FOREIGN KEY `ContentHandle_contentId_fkey`;
-- DropForeignKey
ALTER TABLE `ContentHandle` DROP FOREIGN KEY `ContentHandle_handle_fkey`;
-- AlterTable
ALTER TABLE `content` ADD COLUMN `handleId` VARCHAR(191) NOT NULL;
-- DropTable
DROP TABLE `ContentHandle`;
-- DropTable
DROP TABLE `userHandle`;
-- CreateTable
CREATE TABLE `user` (
`id` VARCHAR(191) NOT NULL,
`email` VARCHAR(191) NOT NULL,
`icon` VARCHAR(191) NOT NULL DEFAULT '',
`isApproved` BOOLEAN NOT NULL DEFAULT false,
`createtime` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `handle` (
`id` VARCHAR(191) NOT NULL,
`handle` VARCHAR(191) NOT NULL,
`userId` VARCHAR(191) NOT NULL,
UNIQUE INDEX `handle_handle_key`(`handle`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `content` ADD CONSTRAINT `content_handleId_fkey` FOREIGN KEY (`handleId`) REFERENCES `handle`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `handle` ADD CONSTRAINT `handle_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -14,16 +14,54 @@ datasource db {
url = env("DATABASE_URL")
}
model content{
// user
model User {
id String @id @default(uuid())
email String
icon String @default("")
isApproved Boolean @default(false)
createtime DateTime @default(now())
RegisgerCode String @default("")
// Many-to-many: a user can have many handles
handles Handle[]
// One-to-many: a user can have many register channels
registerChannels RegisterChannel[]
}
model RegisterChannel {
id String @id @default(uuid())
handle String
// Relation: many register channels belong to one user
userId String
user User @relation(fields: [userId], references: [id])
}
// handle
model Handle {
id String @id @default(uuid())
handle String @unique
constPerView Float @default(1)
// Relations
contents Content[]
// Many-to-many: a handle can belong to many users
users User[]
}
// content
model Content{
id String @id @default(uuid())
subject String
pubDate DateTime
views Int
validViews Int
premiumViews Int
watchTime Int
// Back relation: a content may link to at most one handle
contentHandle ContentHandle?
// views Int
// validViews Int
// premiumViews Int
// watchTime Int
// Relation: many contents belong to one handle
handleId String
handle Handle @relation(fields: [handleId], references: [id])
// Back relation: one content has many day views
dayViews contentDayView[]
}
model contentDayView{
@@ -34,21 +72,13 @@ model contentDayView{
validViews Int
premiumViews Int
watchTime Int
// Relation: many day views belong to one content
content Content @relation(fields: [contentId], references: [id])
@@unique([contentId, date])
}
model userHandle {
id String @id @default(uuid())
email String
handle String @unique
icon String @default("")
isApproved Boolean @default(false)
createtime DateTime @default(now())
// Relation: a handle can be linked to many contents
contentLinks ContentHandle[]
}
// notice
model noticeBoard{
id String @id @default(uuid())
title String
@@ -59,35 +89,6 @@ model noticeBoard{
}
model registerChannel {
id String @id @default(uuid())
email String
handle String
randomcode String
createtime DateTime @default(now())
}
model costPerView{
id Int @id @default(1)
costPerView Float
}
// Mapping table: Each content can be linked to at most one handle (unique contentId)
// A handle can have many contents
model ContentHandle {
id String @id @default(uuid())
contentId String @unique
handle String
// Relations
content content @relation(fields: [contentId], references: [id])
user userHandle @relation(fields: [handle], references: [handle])
@@index([handle])
}
/*
npx prisma migrate dev --name <migration_name>