Ensure index is not already covered in SQLAlchemy
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Install this rule for wispbit
Add this rule to wispbit and it will run when you open a pull request
Install this rule for Coderabbit
Copy the configuration below and add it to your repository as .coderabbit.yml
in your project root.
reviews:
path_instructions:
- path: "*.py"
instructions: |
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Install this rule for Greptile
Greptile rules can be added through the web interface. Please see this documentation for details on how to add custom rules and context.
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
File Path Patterns:
Install this rule for GitHub Copilot
Copilot instructions can be added through the interface. See the documentation for details on how to create coding guidelines.
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
File Path Patterns:
Install this rule for Graphite Diamond
Diamond custom rules can be added through the interface. See the documentation for details on how to create custom rules.
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
File Path Patterns:
Use with Cline
Copy the rule below and ask Cline to review your code using this rule
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Use with OpenAI Codex
Copy the rule below and ask OpenAI Codex to review your code using this rule
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Use with Cursor
Copy the rule below and ask Cursor to review your code using this rule
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Use with Claude Code
Copy the rule below and ask Claude Code to review your code using this rule
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Install this rule for Windsurf
To set up rules for Windsurf Reviews, please see this documentation
Ensure that individual column indexes in SQLAlchemy are not covered by existing composite indexes.
Bad:
```python
class User(Base):
__tablename__ = "users"
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255), index=True) # covered by email_username_idx
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```
Good:
```python
class User(Base):
__tablename__ = "users"
# Only composite index needed - covers both email and email+username queries
__table_args__ = (
Index("email_username_idx", "email", "username"),
)
id: Mapped[int] = mapped_column(primary_key=True)
email: Mapped[str] = mapped_column(String(255))
username: Mapped[str] = mapped_column(String(100))
status: Mapped[str] = mapped_column(String(20))
```