Skip to content

Preserve max_length and decimal constraints in alter_column replay#25

Merged
mr-fatalyst merged 1 commit into
mr-fatalyst:mainfrom
ebrake:fix/migration-alter-column-replay
Apr 16, 2026
Merged

Preserve max_length and decimal constraints in alter_column replay#25
mr-fatalyst merged 1 commit into
mr-fatalyst:mainfrom
ebrake:fix/migration-alter-column-replay

Conversation

@ebrake
Copy link
Copy Markdown
Contributor

@ebrake ebrake commented Apr 15, 2026

This PR preserves constraint-related alter_column changes during migration generation and replay.

Specifically, it keeps these fields from being dropped when migrations are generated or replayed:

  • max_length
  • max_digits
  • decimal_places

It also adds focused regression tests for those cases.

Problem

makemigrations could repeatedly generate the same alter_column(...) operations for constraint-only field changes because those constraint fields were not preserved
through the Python migration round-trip.

That meant Oxyde could detect the change, write the migration, and then lose part of that change when replaying migrations to rebuild schema state.

Changes

  • preserve max_length, max_digits, and decimal_places in migration generation
  • preserve the same fields in migration replay
  • preserve the same fields when building new_field for alter_column
  • add targeted tests in test_migrations_detection.py

Scope

This fixes constraint-field round-tripping for alter_column.

It does not attempt to fix other unrelated repeated alter_column diffs.

Testing

oxyde/tests/unit/test_migrations_detection.py

@ebrake
Copy link
Copy Markdown
Contributor Author

ebrake commented Apr 15, 2026

@mr-fatalyst I just patched the ones I was running into, which are common, but there are others! https://pydantic.dev/docs/validation/1.10/usage/types/

@mr-fatalyst
Copy link
Copy Markdown
Owner

I recently added this fields and didn't test everything yet. Thanks for PR!

@mr-fatalyst mr-fatalyst merged commit df593a0 into mr-fatalyst:main Apr 16, 2026
5 checks passed
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.

2 participants