// R-P11a (P11 Global Search) — typed search metadata and recent searches. // // AD-21: self-contained schema. Entity references are polymorphic bare scalars // so this slice does not touch the owning module schemas. Meilisearch remains // the keyword backend; these rows provide permission-aware metadata, recents, // and tenant snapshot/restore coverage. model SearchIndexEntry { id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt tenantId String entityType String entityId String title String subtitle String? bodyText String @default("") routePath String sourceIndex String permissionSubject String lastIndexedAt DateTime @default(now()) isArchived Boolean @default(false) isDemoData Boolean @default(false) metadata Json @default("{}") @@unique([tenantId, entityType, entityId]) @@index([tenantId, entityType, isArchived]) @@index([tenantId, permissionSubject]) @@index([tenantId, updatedAt]) } model RecentSearch { id String @id @default(cuid()) createdAt DateTime @default(now()) tenantId String userId String queryText String appliedFilters Json @default("{}") resultCount Int @default(0) @@index([tenantId, userId, createdAt(sort: Desc)]) @@index([tenantId, queryText]) }