Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration helpers for local defaults #295

Merged
merged 7 commits into from
Mar 6, 2025
Merged

Conversation

devkral
Copy link
Contributor

@devkral devkral commented Feb 27, 2025

Problem:

Sometimes you want to add new fields (note: not column) with a default (edgy) to the database.
This is until this PR quite cumbersome.

The most important change by this PR is adding a help command/API which temporarily make the affected columns nullable and tries to use the default or an additional given default.

Changes:

  • null-field or nf parameter for makemigrations/revision.
  • The default migration templates allow now to use complex defaults for migrations.
  • Fields must use get_columns_nullable instead of ColumnDefinitionModel null. for determining if the columns should be nullable.
  • ForeignKeys aren't required to be saved models when passed.
  • Cli command revision takes now also the arg argument.
  • Revisioning works now with relative revisions with - (e.g. -2).
  • Downgrades are now possible with unique_together. Build a constraint name from the fields.
  • streamline contentype fields with CURRENT_FIELD_CONTEXT contextvar
  • update docs
  • fix migration issues with FileFields

@devkral devkral force-pushed the devkral/fixes/alembic_defaults branch 3 times, most recently from 84679d7 to 1323e59 Compare March 2, 2025 06:40
devkral added 2 commits March 2, 2025 13:33
Changes:

- fixes regarding fks and UniqueConstraint
- add helpers for making columns temporarily nullable (needs docs)
- some changes see rl notes
@devkral devkral force-pushed the devkral/fixes/alembic_defaults branch from 1323e59 to dd69ef3 Compare March 2, 2025 12:33
- update docs
- fail for some fields when specifying server_defaults
- remove special parameter force_non_partial_update, it was way too
  special
@devkral devkral changed the title WIP: migration helpers for local defaults migration helpers for local defaults Mar 3, 2025
@devkral devkral requested a review from tarsil March 5, 2025 08:31
@devkral devkral merged commit ce626e3 into main Mar 6, 2025
10 checks passed
@devkral devkral deleted the devkral/fixes/alembic_defaults branch March 6, 2025 11:39
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