PhoenixKit.Migrations.Postgres.V12 (phoenix_kit v1.5.1)

View Source

PhoenixKit V12 Migration: JSON Settings Support

This migration adds JSONB support to the settings system, enabling storage of complex structured data alongside traditional string-based settings.

Changes

Settings Table Enhancement

  • Adds value_json column to phoenix_kit_settings table
  • Uses PostgreSQL JSONB type for optimal performance and indexing
  • Nullable field maintains backward compatibility
  • Supports complex configuration objects and arrays

New Features

  • JSON Data Storage: Store complex objects, arrays, and nested data
  • Native JSONB Performance: PostgreSQL's optimized JSONB operations
  • Backward Compatible: Existing string settings continue to work
  • Dual Storage Model: Settings can use either string OR JSON values
  • Cache Integration: JSON data cached efficiently with existing system

PostgreSQL Support

  • Leverages PostgreSQL's native JSONB data type
  • Supports prefix for schema isolation
  • Optimal storage and query performance for JSON data
  • Safe nullable field addition (no data migration required)

Usage Examples

# Traditional string setting (unchanged)
PhoenixKit.Settings.update_setting("theme", "dark")

# New JSON setting
config = %{
  "colors" => %{"primary" => "#3b82f6", "secondary" => "#64748b"},
  "features" => ["dark_mode", "notifications"],
  "limits" => %{"max_users" => 1000, "storage_gb" => 100}
}
PhoenixKit.Settings.update_json_setting("app_config", config)

Summary

Functions

Rollback the V12 migration.

Run the V12 migration to add JSON support to settings.

Functions

down(opts)

Rollback the V12 migration.

up(opts)

Run the V12 migration to add JSON support to settings.