CREATE TABLE IF NOT EXISTS bazzar_pos.app_settings (
    id SMALLINT PRIMARY KEY DEFAULT 1,
    store_name VARCHAR(200) NOT NULL DEFAULT 'POS Bazzar',
    store_phone VARCHAR(50) NOT NULL DEFAULT '',
    single_device_session BOOLEAN NOT NULL DEFAULT TRUE,
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    CONSTRAINT app_settings_singleton CHECK (id = 1)
);

INSERT INTO bazzar_pos.app_settings (id, store_name, store_phone, single_device_session)
VALUES (1, 'POS Bazzar', '', TRUE)
ON CONFLICT (id) DO NOTHING;

ALTER TABLE bazzar_pos.users
ADD COLUMN IF NOT EXISTS active_session_id VARCHAR(120);

CREATE INDEX IF NOT EXISTS idx_users_active_session_id ON bazzar_pos.users (active_session_id);

