feat: 完善广场功能
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
CREATE TABLE `plaza_posts` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`image_generation_id` BIGINT UNSIGNED NOT NULL,
|
||||
`user_id` INT NOT NULL,
|
||||
`status` ENUM('PUBLIC', 'HIDDEN', 'REMOVED') NOT NULL DEFAULT 'PUBLIC',
|
||||
`published_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`hidden_at` DATETIME(3) NULL,
|
||||
`removed_at` DATETIME(3) NULL,
|
||||
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `plaza_posts_image_generation_id_key` (`image_generation_id`),
|
||||
INDEX `plaza_posts_status_published_at_idx` (`status`, `published_at`),
|
||||
INDEX `plaza_posts_user_id_published_at_idx` (`user_id`, `published_at`),
|
||||
CONSTRAINT `plaza_posts_image_generation_id_fkey`
|
||||
FOREIGN KEY (`image_generation_id`) REFERENCES `image_generations` (`id`)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `plaza_posts_user_id_fkey`
|
||||
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
|
||||
ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
@@ -27,6 +27,12 @@ enum ImageArchiveStatus {
|
||||
FAILED
|
||||
}
|
||||
|
||||
enum PlazaPostStatus {
|
||||
PUBLIC
|
||||
HIDDEN
|
||||
REMOVED
|
||||
}
|
||||
|
||||
model User {
|
||||
id Int @id
|
||||
username String @default("") @db.VarChar(191)
|
||||
@@ -37,6 +43,7 @@ model User {
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
imageGenerations ImageGeneration[]
|
||||
plazaPosts PlazaPost[]
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
@@ -67,6 +74,7 @@ model ImageGeneration {
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
deletedAt DateTime? @map("deleted_at")
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
plazaPost PlazaPost?
|
||||
|
||||
@@index([userId, createdAt])
|
||||
@@index([status])
|
||||
@@ -76,6 +84,24 @@ model ImageGeneration {
|
||||
@@map("image_generations")
|
||||
}
|
||||
|
||||
model PlazaPost {
|
||||
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
|
||||
imageGenerationId BigInt @unique @map("image_generation_id") @db.UnsignedBigInt
|
||||
userId Int @map("user_id")
|
||||
status PlazaPostStatus @default(PUBLIC)
|
||||
publishedAt DateTime @default(now()) @map("published_at")
|
||||
hiddenAt DateTime? @map("hidden_at")
|
||||
removedAt DateTime? @map("removed_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
imageGeneration ImageGeneration @relation(fields: [imageGenerationId], references: [id], onDelete: Cascade)
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([status, publishedAt])
|
||||
@@index([userId, publishedAt])
|
||||
@@map("plaza_posts")
|
||||
}
|
||||
|
||||
model GenerationStats {
|
||||
id String @id @db.VarChar(32)
|
||||
totalRequests Int @default(0) @map("total_requests")
|
||||
|
||||
Reference in New Issue
Block a user