-- Migration: Create application_setting table for configurable application options
-- Date: 2025-10-25
-- Description: Introduces persistent storage for application-level settings such as theme colors.

BEGIN;

CREATE TABLE IF NOT EXISTS application_setting (
    id SERIAL PRIMARY KEY,
    key VARCHAR(128) NOT NULL UNIQUE,
    value TEXT NOT NULL,
    value_type VARCHAR(32) NOT NULL DEFAULT 'string',
    category VARCHAR(32) NOT NULL DEFAULT 'general',
    description TEXT,
    is_editable BOOLEAN NOT NULL DEFAULT TRUE,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE UNIQUE INDEX IF NOT EXISTS ux_application_setting_key
    ON application_setting (key);

CREATE INDEX IF NOT EXISTS ix_application_setting_category
    ON application_setting (category);

COMMIT;
