Repository navigation
Commit bc45fdc
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
- .github/workflows
- changelog.d
- docs
- en_US/postgres_specific_features
- zh_CN/postgres_specific_features
- src/rhosocial/activerecord/backend/impl/postgres
- adapters
- backend
- functions
- introspection
- mixins
- ddl
- dml
- extensions
- types
- protocols
- ddl
- dml
- extensions
- types
- types
- tests/rhosocial/activerecord_postgres_test/feature/backend/introspection
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
0 commit comments