Search documentation of phoenix_kit

# PhoenixKit.Migrations.Postgres.V18 (phoenix_kit v1.6.19)

View Source

PhoenixKit V18 Migration: User Custom Fields

Adds JSONB `custom_fields` column to phoenix_kit_users table for storing arbitrary custom data per user (phone numbers, addresses, preferences, metadata, etc.)

## Changes

### Users Table (phoenix_kit_users)

- Adds `custom_fields` JSONB column (nullable, default: %{})
- Stores flexible key-value data without schema changes
- Leverages PostgreSQL's native JSONB type for performance

## Features

- Flexible Schema: Add any custom user data without migrations
- PostgreSQL JSONB: Native JSON storage with indexing support
- Default Empty Map: New users start with `%{}`
- Queryable: Use PostgreSQL JSONB operators for filtering

## Usage Examples

    # Store custom fields
    Auth.register_user(%{
      email: "user@example.com",
      custom_fields: %{
        "phone" => "555-1234",
        "department" => "Engineering"
      }
    })

    # Update fields
    Auth.update_user_custom_fields(user, %{"linkedin" => "https://..."})

    # Access directly
    user.custom_fields["phone"]

# Summary

## Functions

down(opts)

Rollback the V18 migration.

up(opts)

Run the V18 migration to add custom_fields column to users table.

# Functions

# down(opts)

Rollback the V18 migration.

# up(opts)

Run the V18 migration to add custom_fields column to users table.