ylahav

payload db check

by ylahav
Databases & data
v3
^3.0.0
MIT

Overview

Summary generated from the README

Adds a DB consistency page and sidebar shortcut to the Payload admin. It checks any collection for duplicates, broken references, one-sided relationships and drafts documents missing a latest version. Repairs such as merging duplicates, clearing or rebuilding references and backfilling versions are opt-in and preview first. Requires Payload 3, and reference rebuild reads from another MongoDB database on the same server.

Features

  • Duplicate detection on configurable key fields, including likely duplicates sharing a primary identity
  • Broken reference detection across nested arrays, groups, tabs and blocks
  • One-sided relationship detection with confirmed mirror pairs
  • Merge duplicates with per-field value choice and inbound references repointed to the survivor
  • Backfill missing latest versions so drafts-enabled documents reappear in the admin list
  • Access predicate and per-collection mergeable option to restrict destructive actions

Use cases

  • Clean up duplicate contact records after importing data from several sources
  • Repair dangling relationships left behind by deleted documents
  • Restore admin list visibility for documents inserted in bulk on a drafts-enabled collection

From the author

Admin UI for Payload CMS that reports database consistency problems (duplicates, broken references, one-sided relationships) across any collection, with opt-in repairs: merge duplicates, clear or rebuild references. Includes a /admin/db-check view and a sidebar shortcut.

Installation

npm i @yairl/payload-db-check

0

Stars

0

Forks

1

Open Issues

4 months ago

Last Updated

10

Weekly Downloads

v0.2.0

npm Version

318.3 KB

Unpacked Size

0

Dependencies

GitHub stars

00 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
Oct 31, 20260
Oct 30, 20260
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260
Oct 24, 20260
Oct 23, 20260
Oct 22, 20260
Oct 21, 20260
Oct 20, 20260
Oct 19, 20260
Oct 18, 20260
Oct 17, 20260
Oct 16, 20260
Oct 15, 20260
Oct 14, 20260
Oct 13, 20260
Oct 12, 20260
Oct 11, 20260
Oct 10, 20260
Oct 9, 20260
Oct 8, 20260
Oct 7, 20260
Oct 6, 20260
Oct 5, 20260
Oct 4, 20260
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20260
Sep 25, 20260
Sep 24, 20260
Sep 23, 20260
Sep 22, 20260
Sep 21, 20260
Sep 20, 20260
Sep 19, 20260
Sep 18, 20260
Sep 17, 20260
Sep 16, 20260
Sep 15, 20260
Sep 14, 20260
Sep 13, 20260
Sep 12, 20260
Sep 11, 20260
Sep 10, 20260
Sep 9, 20260
Sep 8, 20260
Sep 7, 20260
Sep 6, 20260
npm weekly downloads

7−1 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20267
Dec 4, 20266
Dec 3, 20266
Dec 2, 20264
Dec 1, 20268
Nov 30, 20268
Nov 29, 20267
Nov 28, 20267
Nov 27, 20269
Nov 26, 20269
Nov 25, 202610
Nov 24, 202621
Nov 23, 202621
Nov 22, 202622
Nov 21, 202621
Nov 20, 202620
Nov 19, 202621
Nov 18, 202621
Nov 17, 20266
Nov 16, 20267
Nov 15, 20265
Nov 14, 20265
Nov 13, 20263
Nov 12, 20262
Nov 11, 20261
Nov 10, 20263
Nov 9, 20264
Nov 8, 20264
Nov 7, 20264
Nov 6, 202610
Nov 5, 202610
Nov 4, 202610
Nov 3, 20268
Nov 2, 20267
Nov 1, 20267
Oct 31, 20268
Oct 30, 20262
Oct 29, 20262
Oct 28, 20262
Oct 27, 20264
Oct 26, 20264
Oct 25, 20264
Oct 24, 20265
Oct 23, 20265
Oct 22, 202612
Oct 21, 202612
Oct 20, 202610
Oct 19, 20269
Oct 18, 202614
Oct 17, 202616
Oct 16, 202618
Oct 15, 202614
Oct 14, 202615
Oct 13, 202615
Oct 12, 202616
Oct 11, 202613
Oct 10, 202610
Oct 9, 20269
Oct 8, 20267
Oct 7, 20267
Oct 6, 20267
Oct 5, 20267
Oct 4, 20265
Oct 3, 20266
Oct 2, 20266
Oct 1, 20265
Sep 30, 20267
Sep 29, 20267
Sep 28, 20266
Sep 27, 20268
Sep 26, 20269
Sep 25, 20269
Sep 24, 20269
Sep 23, 20268
Sep 22, 20269
Sep 21, 202613
Sep 20, 202612
Sep 19, 20269
Sep 18, 20269
Sep 17, 202612
Sep 16, 202614
Sep 15, 202613
Sep 14, 20269
Sep 13, 20268
Sep 12, 20268
Sep 11, 20269
Sep 10, 20266
Sep 9, 20262
Sep 8, 20263
Sep 7, 20264
Sep 6, 20268

Each point is npm's rolling 7-day download count.

Health Score

39/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1303697862-root.svg)](https://payloaddirectory.dev/plugins/1303697862-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1303697862-root"><img src="https://payloaddirectory.dev/badge/1303697862-root.svg" alt="Payload Directory"></a>
Updated Jul 26, 2026Created Jul 17, 2026Published Jul 26, 2026

README

@yairl/payload-db-check

An admin plugin for Payload CMS 3 that finds and fixes database consistency problems across your collections — without leaving the admin panel.

It adds a DB consistency page and a sidebar shortcut. Everything is read-only until you explicitly run a repair, and every repair previews what it will do first.

What it checks

Pick a collection, choose which checks to run, and press Start checks:

  • Duplicates — records that share a key you define (e.g. fullName + birthday). The first key field is the "primary identity", so records sharing it but differing on the rest are surfaced separately as likely-but-unconfirmed duplicates.
  • Broken references — relationship or upload fields pointing at documents that no longer exist. Every relationship field is discovered from the schema, including those nested in arrays, groups, tabs and blocks.
  • One-sided links — two-way relationships where only one side was written. Candidate mirror pairs are detected from the schema; you confirm which are real.
  • Missing versions — documents on a drafts-enabled collection that have no latest version row. Because the admin list reads through the versions system (draft=true), such a document is live and served publicly yet invisible in the admin list. This happens after a bulk insert, or when drafts is enabled on a collection that already had data. Only offered for collections with drafts.

What it can repair

All repairs are opt-in, preview first, and require confirmation.

  • Merge duplicates — pick the surviving record; choose per field which copy's value wins; tick which copies contribute. Inbound references are repointed to the survivor before the copies are deleted, so a merge never creates the dangling references this tool exists to find. A bulk "merge all identical groups" handles the safe case where every copy matches on every field.
  • Clear broken references — strip dead ids, keeping the valid ones.
  • Reconnect / rebuild references — recover a deleted record's name from another database on the same server and re-link by name (single or bulk).
  • Backfill missing versions — re-save each affected document through the local API so Payload writes a fresh latest version, making it visible in the admin list again. Document content is not changed. Backfill all missing, or tick specific rows and backfill only those. Idempotent — a document that already has a latest version is skipped, so a re-run is a no-op.

Merging deletes records, so it is opt-in per collection via the mergeable option. Checks run against any collection.

Install

pnpm add @yairl/payload-db-check

Peer dependencies (you already have these in a Payload 3 app): payload, @payloadcms/next, @payloadcms/ui, react.

Usage

// payload.config.ts
import { buildConfig } from 'payload'
import { dbCheckPlugin } from '@yairl/payload-db-check'

export default buildConfig({
  // ...
  plugins: [
    dbCheckPlugin({
      // Collections that may be merged (merging deletes records). Optional.
      mergeable: ['contacts', 'people'],
      // Suggested duplicate key per collection, prefilled in the UI. Optional.
      defaultKeyFields: {
        people: ['fullName', 'birthday'],
        contacts: ['fullName', 'phone'],
      },
    }),
  ],
})

Then regenerate the admin import map so it can resolve the view:

payload generate:importmap

Open /admin/db-check (or your custom route), or use the sidebar link. The sidebar link shows a badge with the total number of documents missing a latest version across all drafts-enabled collections, so the problem is visible without opening the page first.

Options

OptionTypeDefaultDescription
enabledbooleantrueSet false to leave the config untouched (e.g. per environment).
mergeablestring[][]Collection slugs that may be merged. Merging deletes records, so it is opt-in.
defaultKeyFieldsRecord<string, string[]>{}Suggested duplicate key per collection slug, prefilled in the UI.
route`/${string}`/db-checkAdmin route for the page, relative to /admin.
showInSidebarbooleantrueAdd a link to the admin sidebar.
access(req) => boolean | Promise<boolean>any logged-in userWho may run checks and repairs. Reports can expose personal data; repairs delete.
packageNamestring@yairl/payload-db-checkOnly set if you re-publish under a different name (used to build component paths).

Endpoints

The plugin registers these under your Payload API, all gated by access:

  • GET /api/db-check/schema — collections, usable key fields, mirror candidates
  • GET /api/db-check/databases — other databases on the server (rebuild source)
  • GET /api/db-check/missing-versions-count — total documents missing a latest version (sidebar badge)
  • POST /api/db-check/run — run the checks
  • POST /api/db-check/merge — build a merge plan (dry run) or apply it
  • POST /api/db-check/repair — bulk merge-identical / clear-broken / backfill-versions
  • POST /api/db-check/fix — suggest / apply / rebuild references by name

Notes

  • The report can expose personal data (e.g. phone, email) and repairs delete records, so everything is authenticated — by default any logged-in user, or your own access predicate.
  • Reference rebuild reads from another database on the same MongoDB server; it never writes to the source.
  • Styles ship as a namespaced global stylesheet (.dbc-* classes), imported by the view — no CSS-module or Sass setup required in the host.

License

MIT © Yair Lahav

Similar plugins