fix: restore complete admin feature dependencies

This commit is contained in:
Simo committed 2026-07-11 21:15:54 +02:00
1 parent 5b4228261a
commit 0cd753c735
115 files changed
+18565 -4930

No files matched your search

@@ -0,0 +1,114 @@
-- CMS-owned tables required by the restored administration modules.
-- Idempotent and deliberately free of foreign keys so it can be applied to
-- existing emulator databases whose users table may use different engines.
CREATE TABLE IF NOT EXISTS website_tickets (
id INT NOT NULL AUTO_INCREMENT,
subject VARCHAR(255) NOT NULL,
category VARCHAR(50) NOT NULL DEFAULT 'general',
priority VARCHAR(20) NOT NULL DEFAULT 'normal',
status VARCHAR(20) NOT NULL DEFAULT 'open',
creator_id INT NOT NULL,
assignee_id INT NULL,
closed_at DATETIME NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY website_tickets_creator_idx (creator_id),
KEY website_tickets_assignee_idx (assignee_id),
KEY website_tickets_status_idx (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS website_ticket_messages (
id INT NOT NULL AUTO_INCREMENT,
ticket_id INT NOT NULL,
user_id INT NOT NULL,
message TEXT NOT NULL,
is_staff INT NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY website_ticket_messages_ticket_idx (ticket_id),
KEY website_ticket_messages_user_idx (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS website_ticket_templates (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
category VARCHAR(50) NOT NULL DEFAULT 'general',
sort_order INT NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS user_watch (
id INT NOT NULL AUTO_INCREMENT,
staff_id INT NOT NULL,
target_user_id INT NOT NULL,
reason VARCHAR(255) NOT NULL DEFAULT '',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY user_watch_unique (staff_id, target_user_id),
KEY user_watch_target_idx (target_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS admin_audit_log (
id INT NOT NULL AUTO_INCREMENT,
user_id INT NOT NULL,
action VARCHAR(191) NOT NULL DEFAULT '',
target VARCHAR(191) NOT NULL DEFAULT '',
target_id INT NULL,
details TEXT NULL,
`before` TEXT NULL,
`after` TEXT NULL,
diff TEXT NULL,
ip_address VARCHAR(45) NULL,
created_at VARCHAR(64) NOT NULL DEFAULT '',
updated_at VARCHAR(64) NULL,
PRIMARY KEY (id),
KEY admin_audit_log_user_idx (user_id),
KEY admin_audit_log_target_idx (target, target_id),
KEY admin_audit_log_action_idx (action)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS acl_roles (
id INT NOT NULL AUTO_INCREMENT,
slug VARCHAR(191) NOT NULL,
title VARCHAR(255) NOT NULL DEFAULT '',
description TEXT NULL,
created_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY acl_roles_slug_unique (slug)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS acl_permissions (
id INT NOT NULL AUTO_INCREMENT,
slug VARCHAR(191) NOT NULL,
title VARCHAR(255) NOT NULL DEFAULT '',
created_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY acl_permissions_slug_unique (slug)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS acl_model_roles (
id INT NOT NULL AUTO_INCREMENT,
model_type VARCHAR(191) NOT NULL DEFAULT 'User',
model_id INT NOT NULL,
role_id INT NOT NULL,
PRIMARY KEY (id),
KEY acl_model_roles_role_idx (role_id),
UNIQUE KEY acl_model_roles_unique (model_type, model_id, role_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS acl_model_permissions (
id INT NOT NULL AUTO_INCREMENT,
model_type VARCHAR(191) NOT NULL DEFAULT 'Role',
model_id INT NOT NULL,
permission_id INT NOT NULL,
PRIMARY KEY (id),
KEY acl_model_permissions_model_idx (model_id),
KEY acl_model_permissions_permission_idx (permission_id),
UNIQUE KEY acl_model_permissions_unique (model_type, model_id, permission_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+135
View File
@@ -65,6 +65,11 @@ model User {
twoFactorRecoveryCodes String? @map("two_factor_recovery_codes") @db.Text
twoFactorConfirmedAt DateTime? @map("two_factor_confirmed_at") @db.Timestamp(0)
createdTickets WebsiteTicket[] @relation("ticketCreator")
assignedTickets WebsiteTicket[] @relation("ticketAssignee")
ticketMessages WebsiteTicketMessage[]
auditLogs AdminAuditLog[]
@@map("users")
}
@@ -1933,6 +1938,136 @@ model WebsiteHelpCenterTicketReplies {
@@map("website_help_center_ticket_replies")
}
model WebsiteTicket {
id Int @id @default(autoincrement())
subject String @db.VarChar(255)
category String @default("general") @db.VarChar(50)
priority String @default("normal") @db.VarChar(20)
status String @default("open") @db.VarChar(20)
creatorId Int @map("creator_id")
assigneeId Int? @map("assignee_id")
closedAt DateTime? @map("closed_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
creator User @relation("ticketCreator", fields: [creatorId], references: [id])
assignee User? @relation("ticketAssignee", fields: [assigneeId], references: [id])
messages WebsiteTicketMessage[]
@@index([creatorId])
@@index([assigneeId])
@@index([status])
@@map("website_tickets")
}
model WebsiteTicketMessage {
id Int @id @default(autoincrement())
ticketId Int @map("ticket_id")
userId Int @map("user_id")
message String @db.Text
isStaff Int @default(0) @map("is_staff")
createdAt DateTime @default(now()) @map("created_at")
ticket WebsiteTicket @relation(fields: [ticketId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id])
@@index([ticketId])
@@index([userId])
@@map("website_ticket_messages")
}
model WebsiteTicketTemplate {
id Int @id @default(autoincrement())
title String @db.VarChar(255)
content String @db.Text
category String @default("general") @db.VarChar(50)
sortOrder Int @default(0) @map("sort_order")
createdAt DateTime @default(now()) @map("created_at")
@@map("website_ticket_templates")
}
model UserWatch {
id Int @id @default(autoincrement())
staffId Int @map("staff_id")
targetUserId Int @map("target_user_id")
reason String @default("") @db.VarChar(255)
createdAt DateTime @default(now()) @map("created_at")
@@unique([staffId, targetUserId])
@@index([targetUserId])
@@map("user_watch")
}
model AdminAuditLog {
id Int @id @default(autoincrement())
userId Int @map("user_id")
action String @default("")
target String @default("")
targetId Int? @map("target_id")
details String? @db.Text
before String? @db.Text
after String? @db.Text
diff String? @db.Text
ipAddress String? @map("ip_address") @db.VarChar(45)
createdAt String @default("") @map("created_at")
updatedAt String? @map("updated_at")
user User @relation(fields: [userId], references: [id])
@@index([userId])
@@index([target, targetId])
@@index([action])
@@map("admin_audit_log")
}
model AclRole {
id Int @id @default(autoincrement())
slug String @unique
title String @default("")
description String? @db.Text
createdAt DateTime? @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
rolePermissions AclModelPermission[]
modelRoles AclModelRole[]
@@map("acl_roles")
}
model AclPermission {
id Int @id @default(autoincrement())
slug String @unique
title String @default("")
createdAt DateTime? @default(now()) @map("created_at")
updatedAt DateTime? @updatedAt @map("updated_at")
modelPermissions AclModelPermission[]
@@map("acl_permissions")
}
model AclModelRole {
id Int @id @default(autoincrement())
modelType String @default("User") @map("model_type")
modelId Int @map("model_id")
roleId Int @map("role_id")
role AclRole @relation(fields: [roleId], references: [id], onDelete: Cascade)
@@index([roleId])
@@map("acl_model_roles")
}
model AclModelPermission {
id Int @id @default(autoincrement())
modelType String @default("Role") @map("model_type")
modelId Int @map("model_id")
permissionId Int @map("permission_id")
role AclRole @relation(fields: [modelId], references: [id], onDelete: Cascade)
permission AclPermission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
@@index([modelId])
@@index([permissionId])
@@map("acl_model_permissions")
}
model AlertLogs {
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
type String @db.VarChar(255)