Setting schema for PhoenixKit system settings.
This schema defines system-wide settings that can be configured through the admin panel. Settings are stored as key-value pairs with timestamps.
Fields
key: Setting identifier (unique, required)value: Setting value (string format, for simple settings)value_json: Setting value (JSONB format, for complex data structures)module: Module/feature identifier for organization (optional)date_added: When the setting was first createddate_updated: When the setting was last modified
Value Storage Strategy
Settings can use either value (string) OR value_json (JSONB), but not both:
- Use
valuefor simple string settings (themes, toggles, simple config) - Use
value_jsonfor complex data (objects, arrays, nested structures) - When both are present,
value_jsontakes precedence
Default Settings
PhoenixKit includes three default system settings:
- time_zone: System timezone offset (default: "0" for UTC)
- date_format: Date display format (default: "Y-m-d")
- time_format: Time display format (default: "H:i" for 24-hour)
Usage Examples
# Create a simple string setting
%Setting{}
|> Setting.changeset(%{key: "theme", value: "dark"})
|> Repo.insert()
# Create a complex JSON setting
%Setting{}
|> Setting.changeset(%{key: "app_config", value_json: %{"theme" => "dark", "features" => ["auth", "admin"]}})
|> Repo.insert()
# Update existing setting
setting
|> Setting.changeset(%{value: "light"})
|> Repo.update()
Summary
Functions
Creates a changeset for setting creation and updates.
Creates a changeset for updating only the value field.
Functions
Creates a changeset for setting creation and updates.
Validates that key and value are present and key is unique. Automatically sets date_updated to current time on updates.
Creates a changeset for updating only the value field.
This is used when updating existing settings through the admin panel. Automatically updates the date_updated timestamp.