validating-database-integrity
БесплатноЗапускает вложенные скриптыНе проверенProcess use when you need to ensure database integrity through comprehensive data validation. This skill validates data types, ranges, formats, referential…
от jeremylongshore★ 2 961 звезда на GitHubОб этом скилле
Data Validation Engine
Overview
Implement and enforce data integrity rules at the database level using CHECK constraints, triggers, foreign keys, and custom validation functions across PostgreSQL and MySQL.
Prerequisites
- Database credentials with ALTER TABLE and CREATE FUNCTION permissions
psqlormysqlCLI for executing validation queries- Current schema documentation or access to
information_schemafor column specifications - Business rules document describing valid data ranges, formats, and relationships
- Backup of production data before applying new constraints (constraints may reject existing invalid data)
Instructions
Audit existing data quality by running validation queries before adding constraints. Check for NULL values in columns that should be required:
SELECT column_name, COUNT(*) FILTER (WHERE column_name IS NULL) AS null_count, COUNT(*) AS total FROM table_name GROUP BY column_name.Detect orphaned records (broken referential integrity):
SELECT c.id FROM child_table c LEFT JOIN parent_table p ON c.parent_id = p.id WHERE p.id IS NULL. Document all orphaned records for cleanup or archival before adding foreign key constraints.Validate data format compliance:
- Email format:
SELECT email FROM users WHERE email !~ '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$' - Phone format:
SELECT phone FROM contacts WHERE phone !~ '^\+?[1-9]\d{6,14}$' - URL format:
SELECT url FROM links WHERE url !~ '^https?://.+' - Date ranges:
SELECT * FROM events WHERE start_date > end_date
- Email format:
Check numeric range violations:
SELECT * FROM products WHERE price < 0 OR price > 999999.99andSELECT * FROM users WHERE age < 0 OR age > 150. Map each column to its valid range based on business rules.Identify duplicate records that violate intended uniqueness:
SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1. Determine which duplicate to keep (most recent, most complete) and plan deduplication.Generate CHECK constraints for validated rules:
ALTER TABLE products ADD CONSTRAINT chk_price_positive CHECK (price >= 0)ALTER TABLE users ADD CONSTRAINT chk_email_format CHECK (email ~ '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$')ALTER TABLE events ADD CONSTRAINT chk_date_order CHECK (start_date <= end_date)ALTER TABLE orders ADD CONSTRAINT chk_status_valid CHECK (status IN ('pending', 'processing', 'shipped', 'delivered', 'cancelled'))
Create foreign key constraints with appropriate cascade behavior:
ALTER TABLE orders ADD CONSTRAINT fk_orders_customer FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE RESTRICT- Use
ON DELETE CASCADEfor dependent data (order_items when order is deleted) - Use
ON DELETE SET NULLfor optional relationships (assigned_to when user is deactivated)
Implement complex business rule validation using database triggers when CHECK constraints are insufficient:
- Trigger that prevents order total from exceeding customer credit limit
- Trigger that enforces at least one admin user per organization
- Trigger that validates JSON schema for JSONB columns
Apply constraints in a safe two-phase approach:
- Phase 1: Run validation queries to find all violations. Generate data cleanup scripts. Execute cleanup.
- Phase 2: Apply constraints with
NOT VALIDoption (PostgreSQL):ALTER TABLE users ADD CONSTRAINT chk_email CHECK (email ~ '...') NOT VALIDthenALTER TABLE users VALIDATE CONSTRAINT chk_email(validates existing data without blocking writes).
Generate a data quality report summarizing: total records per table, violation counts by constraint type, cleanup actions taken, constraints applied, and remaining data quality issues requiring manual review.
Output
- Data quality audit report with violation counts, examples, and severity ratings
- Data cleanup scripts (SQL) to fix violations before constraint application
- Constraint DDL scripts with CHECK, FOREIGN KEY, NOT NULL, and UNIQUE constraints
- Validation triggers for complex business rules beyond simple constraints
- Ongoing validation queries for periodic data quality monitoring
Error Handling
| Error | Cause | Solution |
|---|---|---|
check constraint violated by existing row |
Existing data fails the new constraint | Run the validation query first to find violations; clean up data; use NOT VALID option to add constraint without checking existing data, then validate separately |
cannot add foreign key: referenced row not found |
Orphaned child records reference non-existent parent | Clean up orphaned records first with DELETE or UPDATE to valid parent; or insert missing parent records |
column cannot be made NOT NULL: contains NULL values |
Existing rows have NULL in the target column | Backfill NULLs with UPDATE table SET column = default_value WHERE column IS NULL before adding NOT NULL |
| Trigger funct |
Установить validating-database-integrity в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditGrepGlobBash(psql:*)Bash(mysql:*)Вложенные файлы
FAQ
Что делает скилл validating-database-integrity?
Process use when you need to ensure database integrity through comprehensive data validation. This skill validates data types, ranges, formats, referential integrity, and business rules. Trigger with phrases like "validate database data", "implement data validation rules", "enforce data integrity constraints", or "validate data formats".
Как установить скилл validating-database-integrity?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл validating-database-integrity запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
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