data-integrity-auditor
БесплатноБез исполняемых скриптовНе проверенDetects data integrity issues including orphaned records, broken foreign key relationships, constraint violations, and provides automated fix migrations. Use…
от patricio0312rev★ 64 звезды на GitHubОб этом скилле
Data Integrity Auditor
Detect and fix data integrity issues automatically.
Integrity Check Types
1. Orphaned Records
-- Find orphaned orders (no matching user)
SELECT o.id, o.user_id
FROM orders o
LEFT JOIN users u ON u.id = o.user_id
WHERE u.id IS NULL;
-- Find orphaned order items (no matching order)
SELECT oi.id, oi.order_id
FROM order_items oi
LEFT JOIN orders o ON o.id = oi.order_id
WHERE o.id IS NULL;
2. Broken Foreign Keys
// scripts/check-foreign-keys.ts
async function checkForeignKeys() {
const issues: string[] = [];
// Orders → Users
const orphanedOrders = await prisma.$queryRaw<any[]>`
SELECT o.id, o.user_id
FROM orders o
LEFT JOIN users u ON u.id = o.user_id
WHERE u.id IS NULL
LIMIT 100
`;
if (orphanedOrders.length > 0) {
issues.push(
`❌ Found ${orphanedOrders.length} orders with invalid user_id`
);
console.log(
" Sample IDs:",
orphanedOrders.slice(0, 5).map((o) => o.id)
);
}
// Order Items → Orders
const orphanedItems = await prisma.$queryRaw<any[]>`
SELECT oi.id, oi.order_id
FROM order_items oi
LEFT JOIN orders o ON o.id = oi.order_id
WHERE o.id IS NULL
LIMIT 100
`;
if (orphanedItems.length > 0) {
issues.push(
`❌ Found ${orphanedItems.length} order items with invalid order_id`
);
}
// Products → Categories
const orphanedProducts = await prisma.$queryRaw<any[]>`
SELECT p.id, p.category_id
FROM products p
LEFT JOIN categories c ON c.id = p.category_id
WHERE p.category_id IS NOT NULL
AND c.id IS NULL
LIMIT 100
`;
if (orphanedProducts.length > 0) {
issues.push(
`❌ Found ${orphanedProducts.length} products with invalid category_id`
);
}
return issues;
}
3. Constraint Violations
async function checkConstraints() {
const issues: string[] = [];
// Check email uniqueness (should be caught by DB, but verify)
const duplicateEmails = await prisma.$queryRaw<any[]>`
SELECT email, COUNT(*) as count
FROM users
GROUP BY email
HAVING COUNT(*) > 1
`;
if (duplicateEmails.length > 0) {
issues.push(`❌ Found ${duplicateEmails.length} duplicate emails`);
}
// Check negative quantities
const negativeStock = await prisma.$queryRaw<any[]>`
SELECT id, name, stock
FROM products
WHERE stock < 0
`;
if (negativeStock.length > 0) {
issues.push(
`❌ Found ${negativeStock.length} products with negative stock`
);
}
// Check negative prices
const negativePrices = await prisma.$queryRaw<any[]>`
SELECT id, name, price
FROM products
WHERE price < 0
`;
if (negativePrices.length > 0) {
issues.push(
`❌ Found ${negativePrices.length} products with negative prices`
);
}
// Check invalid order status
const invalidStatus = await prisma.$queryRaw<any[]>`
SELECT id, status
FROM orders
WHERE status NOT IN ('pending', 'paid', 'shipped', 'delivered', 'cancelled')
`;
if (invalidStatus.length > 0) {
issues.push(`❌ Found ${invalidStatus.length} orders with invalid status`);
}
return issues;
}
4. Missing Required Fields
async function checkMissingFields() {
const issues: string[] = [];
// Users missing required fields
const usersNoEmail = await prisma.user.count({
where: { email: null },
});
if (usersNoEmail > 0) {
issues.push(`❌ Found ${usersNoEmail} users without email`);
}
// Orders with NULL totals
const ordersNoTotal = await prisma.order.count({
where: { total: null },
});
if (ordersNoTotal > 0) {
issues.push(`❌ Found ${ordersNoTotal} orders without total`);
}
return issues;
}
Comprehensive Audit Script
// scripts/audit-data-integrity.ts
interface IntegrityIssue {
severity: "critical" | "warning" | "info";
category: string;
message: string;
count: number;
query?: string;
fix?: string;
}
async function auditDataIntegrity(): Promise<IntegrityIssue[]> {
const issues: IntegrityIssue[] = [];
console.log("🔍 Auditing data integrity...\n");
// 1. Check orphaned records
const orphanedOrders = await prisma.$queryRaw<any[]>`
SELECT COUNT(*) as count FROM orders o
LEFT JOIN users u ON u.id = o.user_id
WHERE u.id IS NULL
`;
if (orphanedOrders[0].count > 0) {
issues.push({
severity: "critical",
category: "orphaned-records",
message: "Orders with invalid user references",
count: orphanedOrders[0].count,
query:
"SELECT id, user_id FROM orders o LEFT JOIN users u ON u.id = o.user_id WHERE u.id IS NULL",
fix: "DELETE FROM orders WHERE id IN (...)",
});
}
// 2. Check duplicate unique constraints
const duplicateEmails = await prisma.$queryRaw<any[]>`
SELECT email, COUNT(*) as count
FROM users
GROUP BY email
HAVING COUNT(*) > 1
`;
if (duplicateEmails.length > 0) {
issues.push({
Установить data-integrity-auditor в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл data-integrity-auditor?
Detects data integrity issues including orphaned records, broken foreign key relationships, constraint violations, and provides automated fix migrations. Use for "data integrity", "orphaned records", "broken relationships", or "data quality".
Как установить скилл data-integrity-auditor?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл data-integrity-auditor запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic