---
description: Database schema changes, migrations, and query optimization
globs: *.php, *.install, *.module
---
# Drupal Database Standards

Ensures proper database handling in Drupal applications.

## Rule Details

- **Name:** drupal_database_standards

- **Description:** Enforce Drupal database best practices and standards

## Filters
- file extension pattern: `\\.(php|install|module)$`

## Enforcement Checks
- Conditions:
  - pattern `db_query` – Use Database API instead of db_query
  - pattern `hook_update_N.*\\{\\s*[^}]*\\}` – Ensure hook_update_N includes proper schema changes
  - pattern `\\$query->execute\\(\\)` – Consider using try-catch block for database operations

## Suggestions
- Guidance:
Database Best Practices:
- Use Schema API for table definitions
- Implement proper error handling
- Use update hooks for schema changes
- Follow Drupal's database abstraction layer
- Implement proper indexing strategies

## Metadata
- Priority: critical
- Version: 1.1

 