PhoenixKit.Migrations.Postgres.V30 (phoenix_kit v1.7.69)

Copy Markdown View Source

Migration V30: Move preferred_locale from column to custom_fields JSONB.

This migration removes the dedicated preferred_locale column and stores the value in the existing custom_fields JSONB column instead. This reduces schema complexity by leveraging the flexible JSONB storage for user preferences.

Changes

  • Migrates existing preferred_locale values into custom_fields JSONB
  • Drops the preferred_locale index
  • Drops the preferred_locale column

Requirements

  • PostgreSQL database
  • PhoenixKit V29 or higher
  • The custom_fields JSONB column must exist (added in V18)

Data Migration

Existing preferred_locale values are preserved by copying them into custom_fields:

  • user.preferred_locale = "en-GB" becomes user.custom_fields["preferred_locale"] = "en-GB"
  • NULL values are not migrated (same behavior: use system default)

Backward Compatibility

  • Reading: get_in(user.custom_fields, ["preferred_locale"]) or user.custom_fields["preferred_locale"]
  • Writing: Merge into custom_fields map
  • NULL handling: Missing key = use system default (same as before)

Rollback

The down migration restores the column and migrates data back from custom_fields.

Summary

Functions

down(opts)

up(opts)