-- Migration: Admin Panel v2
-- Run manually in Supabase SQL Editor (Dashboard → SQL Editor → New Query)

-- 1. Settings table for configurable pricing
CREATE TABLE settings (
  key TEXT PRIMARY KEY,
  value TEXT NOT NULL,
  updated_at TIMESTAMPTZ DEFAULT now()
);

INSERT INTO settings (key, value) VALUES
  ('price_200', '2000'),
  ('price_300', '3000');

ALTER TABLE settings ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Anyone can read settings"
  ON settings FOR SELECT USING (true);

CREATE POLICY "Auth users can update settings"
  ON settings FOR UPDATE USING (auth.role() = 'authenticated');

-- 2. New contact fields on orders
ALTER TABLE orders
  ADD COLUMN IF NOT EXISTS telegram_username TEXT,
  ADD COLUMN IF NOT EXISTS max_username TEXT,
  ADD COLUMN IF NOT EXISTS address TEXT;
