- Create settings table for site-wide key-value configuration - Create images table for BLOB storage of logo/header images - Add Setting schema with JSON/string/integer/boolean support - Add ThemeSettings embedded schema with all theme options - Add Settings context with get/put/update operations - Add Media context for image uploads and retrieval - Add Image schema with SVG detection and storage - Add 9 curated theme presets (gallery, studio, boutique, etc.) - Add comprehensive tests for Settings and Media contexts - Add seeds with default Studio preset - All tests passing (29 tests, 0 failures)
25 lines
616 B
Elixir
25 lines
616 B
Elixir
defmodule SimpleshopTheme.Settings.Setting do
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
|
|
@primary_key {:id, :binary_id, autogenerate: true}
|
|
@foreign_key_type :binary_id
|
|
|
|
schema "settings" do
|
|
field :key, :string
|
|
field :value, :string
|
|
field :value_type, :string, default: "string"
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
@doc false
|
|
def changeset(setting, attrs) do
|
|
setting
|
|
|> cast(attrs, [:key, :value, :value_type])
|
|
|> validate_required([:key, :value, :value_type])
|
|
|> validate_inclusion(:value_type, ~w(string json integer boolean))
|
|
|> unique_constraint(:key)
|
|
end
|
|
end
|