Skip to content

Allow TextField indexes on PostgreSQL - #2264

Open
evstratbg wants to merge 1 commit into
tortoise:developfrom
evstratbg:feature/postgres-textfield-indexes
Open

Allow TextField indexes on PostgreSQL#2264
evstratbg wants to merge 1 commit into
tortoise:developfrom
evstratbg:feature/postgres-textfield-indexes

Conversation

@evstratbg

Copy link
Copy Markdown
Contributor

Description

Allow TextField(unique=True) and TextField(db_index=True) when the configured database dialect is PostgreSQL.

This adds dialect-aware indexability validation and applies it consistently to schema generation and the migration schema editor. Other backends continue to reject indexed TextField declarations when generating or migrating schema. CharField behavior is unchanged.

Motivation and Context

PostgreSQL supports B-tree indexes and unique constraints on TEXT, but Tortoise currently rejects these declarations before the database dialect is known.

This addresses the TextField indexing portion of #384. The separate CharField request in that issue is intentionally out of scope.

How Has This Been Tested?

  • Added asyncpg and psycopg schema-generation tests for TEXT UNIQUE and CREATE INDEX ... (text_column).
  • Added SQLite rejection coverage to verify that the behavior remains PostgreSQL-only.
  • Added migration schema editor tests for PostgreSQL support and non-PostgreSQL rejection.
  • Ran the full SQLite test suite: 1913 passed, 148 skipped, 2 xfailed.
  • Ran the affected test files: 76 passed.
  • Ran Ruff format/check, Bandit, package build, Twine checks, and the documentation build.

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing evstratbg:feature/postgres-textfield-indexes (52bc5ad) with develop (c5e5c4b)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant