Skip to content

Commit bc45fdc

Browse files
vistartclaude
andauthored
feat: add PostgreSQL introspection support (#14)
* feat(backend): add PostgreSQL introspection support with AbstractIntrospector Implement introspection for PostgreSQL backend using pg_catalog system tables: - Add PostgreSQLIntrospector using pg_catalog for metadata queries - Add IntrospectorBackendMixin to PostgresBackend - Add complete test suite covering all introspection features Key features: - Queries pg_class, pg_attribute, pg_index, pg_constraint, pg_trigger - Default schema is 'public' - Supports tables, columns, indexes, foreign keys, views, triggers This aligns PostgreSQL with the new introspection architecture. * refactor(backend): separate sync/async introspector implementations Split PostgreSQLIntrospector into: - PostgreSQLIntrospectorMixin: shared non-I/O logic - SyncPostgreSQLIntrospector: synchronous introspector - AsyncPostgreSQLIntrospector: asynchronous introspector This aligns with the core package refactoring and follows the project's sync/async parity principle where sync and async are separate and cannot coexist in the same class. * feat(backend): add introspect subcommand to PostgreSQL CLI Add a new 'introspect' subcommand to the PostgreSQL backend CLI for database introspection operations: - Tables, views, columns listing - Indexes, foreign keys, triggers info - Database information Also includes code style fixes across all files: - Format code with ruff format - Fix line length violations (E501) - Remove unused imports (F401) - Add 'from None' to exception chaining (B904) * refactor(cli): use explicit subcommand mode and fix Chinese to English - Use parent parser pattern for shared connection parameters - Separate query and introspect subcommands explicitly - Fix Chinese comments to English in design notes - Rename args.query to args.sql for consistency * refactor(backend): delegate PostgreSQL introspection SQL generation to dialect Remove _build_*_sql() methods from PostgreSQLIntrospectorMixin, relying on the base class implementation that delegates to Expression.to_sql(). PostgresIntrospectionCapabilityMixin.format_*_query() methods already exist and now handle all SQL generation. Changes: - Removed 8 _build_*_sql() methods from introspector.py - Updated _parse_database_info() to use 'version' and 'collation' columns - Updated _parse_triggers() to use 'timing' column from Dialect - Removed get_database_info() override (Dialect returns version in single query) - Fixed psycopg3 % escaping: 'pg_%' -> 'pg_%%' No functional changes - SQL output and API remain identical. * fix(introspection): correct PostgreSQL trigger timing detection The tgtype bitmask was incorrectly interpreted for trigger timing: - Bit 2 (4) is INSERT event, not AFTER timing - Bit 3 (8) is DELETE event, not INSTEAD OF timing - AFTER timing has neither bit 1 nor bit 6 set (default case) - INSTEAD OF uses bit 6 (64), not bit 3 Corrected SQL CASE expression: - INSTEAD OF: bit 6 (64) set - BEFORE: bit 1 (2) set - AFTER: neither (default) Added comprehensive test cases for: - AFTER INSERT trigger - AFTER UPDATE trigger - AFTER DELETE trigger - INSTEAD OF trigger on view All 24 trigger introspection tests now pass. * ci: update rhosocial-activerecord to git+https with release/v1.0.0.dev20 Change installation source from PyPI version 1.0.0.dev19 to git repository branch release/v1.0.0.dev20 for CI testing. * fix(introspection): handle PostgreSQL 14+ reltuples returning -1 for unanalyzed tables PostgreSQL 14+ returns -1 for pg_class.reltuples when a table has never been vacuumed or analyzed. This commit converts -1 to None to maintain cross-version consistency. - Converts reltuples=-1 to row_count=None in _parse_tables() - Ensures consistent behavior across PostgreSQL 9-18 - Fixes test_table_row_count failure on PostgreSQL 14+ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: add changelog fragment for PR #14 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8824411 commit bc45fdc

118 files changed

Lines changed: 7413 additions & 2829 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ jobs:
6565
pip install -r requirements.txt
6666
pip install -r requirements-dev.txt
6767
68-
- name: Install activerecord and testsuite from PyPI
68+
- name: Install activerecord and testsuite from git
6969
run: |
70-
pip install rhosocial-activerecord==1.0.0.dev19
70+
pip install git+https://github.com/rhosocial/python-activerecord.git@release/v1.0.0.dev20
7171
pip install rhosocial-activerecord-testsuite==1.0.0.dev7
7272
7373
- name: Create postgres scenario config

‎changelog.d/14.added.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added PostgreSQL introspection support with AbstractIntrospector for database schema discovery, including tables, columns, indexes, foreign keys, views, and triggers.

‎docs/en_US/postgres_specific_features/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PostgreSQL offers many advanced features beyond standard SQL. This section cover
99
- **[Advanced Indexing](./indexing.md)**: GIN, GiST, BRIN indexes
1010
- **[RETURNING Clause](./returning.md)**: Get data back from DML operations
1111
- **[Protocol Support Matrix](./protocol_support.md)**: Comprehensive protocol support and version compatibility
12+
- **[Database Introspection](./introspection.md)**: Query metadata using pg_catalog
1213

1314
## Feature Highlights
1415

0 commit comments

Comments
 (0)