Repository navigation
Commit bdaa142
committed
feat(schema): implement schema-diff support and DataType refactoring for PostgreSQL backend (#46)
* feat(types): implement PostgreSQL DataType subclasses and type support mixin
- Add ~45 PostgreSQL-specific DataType subclasses in expression/types.py
- Add PostgresTypeFormatSupportMixin with TypeFormattingSupport + TypeParsingSupport
- Integrate type support into PostgresDialect
- Update exports in __init__.py, expression/__init__.py, mixins/__init__.py, mixins/types/__init__.py
* refactor(types): add __eq__/__hash__, remove synonyms, add CharacterVaryingType
- Replace _type_params() with __eq__/__hash__ in PostgresBitType,
PostgresVarBitType, PostgresVectorType
- Remove synonyms() from PostgresSmallSerialType, PostgresSerialType,
PostgresBigSerialType
- Add PostgresCharacterVaryingType(VarCharType) for CHARACTER VARYING(n)
- Register new type in data_type_formatting mixin
- Clean up unused imports (ClassVar, Set, Tuple)
* feat(schema): add parsed_data_type to PostgreSQL _parse_columns
Call DataType.parse_data_type_str(dialect, data_type) when
constructing ColumnInfo so that introspection results carry
structured DataType instances for schema comparison.
* feat(types): add synonyms to PostgreSQL types
- PostgresSerialType ↔ IntegerType/SerialType
- PostgresSmallSerialType ↔ SmallIntType/SmallSerialType
- PostgresBigSerialType ↔ BigIntType/BigSerialType
- PostgresCharacterVaryingType ↔ VarCharType
* feat(types): add synonyms to PostgresByteaType
PostgresByteaType ↔ BlobType for cross-backend schema comparison.
* refactor(types): inherit DDLTypeMixin in Postgres type formatting
* refactor(types): update to DDLTypeSupport protocol
* refactor(types): use @DDLTypeMixin.handles, remove format_data_type override
- Add @DDLTypeMixin.handles decorators to all 56 formatter methods
- Remove custom format_data_type() dispatch and supports_data_types() list
- Move Postgres type imports from TYPE_CHECKING to runtime
* fix(types): rewrite Postgres core type formatters, fix missing PostgresTypeFormatSupportMixin base
- Replace _default_sql() calls with explicit PostgreSQL SQL strings
for all 18 core type handlers (SmallIntType→SMALLINT, etc.)
- Add PostgresTypeFormatSupportMixin as base of PostgresDialect
(was imported but never used as base, causing format_data_type
to resolve to protocol stub and return None)
- Create test_core_type_mappings.py with 15 tests for core type→SQL
rendering via PostgreSQL dialect
* feat(postgres): implement array type support
- Add PostgresArrayType parameterised container type (element_type, dimensions)
- Add format_data_type_array handler that recursively formats element types
- Update parse_type to detect ARRAY keyword and [] suffix before standard dispatch
- Add 25 tests covering core type mappings and array rendering/parsing
* refactor(postgres): use core ArrayType, keep PostgresArrayType as alias
- PostgresArrayType is now just 'PostgresArrayType = ArrayType'
- Update handler registration to use core ArrayType
- Update parse_type to return ArrayType directly
- Add test for is_element_type_equivalent
* feat(postgres): add element type validation and PostgresArrayType subclass
- format_data_type_array validates element_type is in _type_formatters
- PostgresArrayType is now a proper subclass with is_equivalent ignoring
dimensions (PG normalises multi-dim arrays to 1-D internally)
- parse_type always creates PostgresArrayType with dimensions=1
- Update tests for new PostgresArrayType subclass and PG array semantics
* feat(schema): add PostgresSchemaDiffer
Column order has no semantic meaning in PostgreSQL; array dimension
equivalence is handled by PostgresArrayType.is_equivalent().
* feat(schema): add schema-diff examples and refactor for PostgreSQL backend
- Add 6 schema-diff example scripts: table_changes, column_order_irrelevant, postgres10_identity, array_type_diff, index_type_diff, serialization_roundtrip
- All DDL uses expression objects, call introspect_and_adapt() after connect
- Refactor format_column_definition to use col_def.data_type.to_sql() and add identity dialect_options support
- Update existing DDL examples to use expression API (table param, QueryExpression for verification)
* refactor(types): remove _default_sql(), make format_data_type return Tuple[str, tuple]
- Delete all _default_sql() methods from Postgres expression types
- Change all PostgresTypeFormatSupportMixin formatters to return Tuple[str, tuple]
- Inline _default_sql() logic directly into each format_data_type_* method
- Unpack format_data_type() call in array formatter
* style(types): add complete type annotations to all format_data_type_* methods
* feat(examples): strengthen serialization roundtrip with table data assertions
* fix(tests): replace string data_type with DataType instances across 22 test files
ColumnDefinition now validates that data_type must be a DataType
instance. Replace all string data_type values (SERIAL, TEXT, INTEGER,
etc.) with proper instance references.
Also add PostgresCitextType, PostgresCubeType, PostgresLtreeType,
PostgresRasterType missing extension DataType subclasses.
Update security injection tests to verify TypeError at construction
time instead of ValueError at format time.
* docs: add changelog fragment for PR #46
* fix(tests): replace positional string data_type with DataType instances in 6 more files
* fix(types): register PostgresCitextType, PostgresCubeType, PostgresLtreeType, PostgresRasterType formatters
* fix: restore PostgresCidrType import accidentally removed in type formatter registration1 parent 5d6850a commit bdaa142
52 files changed
Lines changed: 3137 additions & 386 deletions
File tree
- changelog.d
- src/rhosocial/activerecord/backend/impl/postgres
- examples
- ddl
- schema_diff
- expression
- introspection
- mixins
- types
- schema
- tests
- providers
- rhosocial/activerecord_postgres_test/feature/backend
- postgres
- extensions
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 | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
26 | 75 | | |
27 | 76 | | |
28 | 77 | | |
| |||
505 | 554 | | |
506 | 555 | | |
507 | 556 | | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
508 | 605 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
169 | 170 | | |
170 | 171 | | |
171 | 172 | | |
| 173 | + | |
172 | 174 | | |
173 | 175 | | |
174 | 176 | | |
| |||
400 | 402 | | |
401 | 403 | | |
402 | 404 | | |
| 405 | + | |
403 | 406 | | |
404 | 407 | | |
405 | 408 | | |
| |||
524 | 527 | | |
525 | 528 | | |
526 | 529 | | |
| 530 | + | |
| 531 | + | |
527 | 532 | | |
528 | 533 | | |
529 | 534 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
419 | 461 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
157 | 165 | | |
| 166 | + | |
| 167 | + | |
158 | 168 | | |
159 | 169 | | |
160 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
| 95 | + | |
| 96 | + | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
0 commit comments