CREATE TABLE IF NOT EXISTS menu_categories (id serial PRIMARY KEY, slug text NOT NULL UNIQUE, name text NOT NULL, yandex_category_id integer NOT NULL UNIQUE, sort_order integer NOT NULL DEFAULT 0, is_active boolean NOT NULL DEFAULT true, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now());
CREATE TABLE IF NOT EXISTS menu_items (id serial PRIMARY KEY, slug text NOT NULL UNIQUE, category_id integer NOT NULL REFERENCES menu_categories(id), name text NOT NULL, description text, short_description text, ingredients text, weight_text text, image_url text, is_available boolean NOT NULL DEFAULT true, is_alcohol boolean NOT NULL DEFAULT false, alcohol_percent text, country text, producer text, show_on_website boolean NOT NULL DEFAULT true, publish_to_yandex boolean NOT NULL DEFAULT false, allow_online_order boolean NOT NULL DEFAULT true, allow_delivery boolean NOT NULL DEFAULT true, sort_order integer NOT NULL DEFAULT 0, source text NOT NULL DEFAULT 'manual', source_external_id text UNIQUE, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now());
CREATE TABLE IF NOT EXISTS menu_item_variants (id serial PRIMARY KEY, item_id integer NOT NULL REFERENCES menu_items(id) ON DELETE CASCADE, label text NOT NULL, volume_ml integer, weight_grams integer, price_kopecks integer NOT NULL, yandex_offer_id text NOT NULL UNIQUE, is_available boolean NOT NULL DEFAULT true, sort_order integer NOT NULL DEFAULT 0, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now());
CREATE TABLE IF NOT EXISTS menu_feed_requests (id serial PRIMARY KEY, requested_at timestamptz NOT NULL DEFAULT now(), user_agent text, response_status integer NOT NULL, items_count integer NOT NULL DEFAULT 0, feed_version text NOT NULL);
CREATE INDEX IF NOT EXISTS menu_items_category_idx ON menu_items(category_id); CREATE INDEX IF NOT EXISTS menu_item_variants_item_idx ON menu_item_variants(item_id);
CREATE TABLE IF NOT EXISTS sbis_catalog_items (id serial PRIMARY KEY, sbis_id text NOT NULL UNIQUE, category_id text, category_name text NOT NULL, name text NOT NULL, price_kopecks integer NOT NULL, available boolean NOT NULL DEFAULT true, variant_of text, updated_at timestamptz NOT NULL DEFAULT now());
CREATE INDEX IF NOT EXISTS sbis_catalog_items_category_idx ON sbis_catalog_items(category_id);
CREATE TABLE IF NOT EXISTS auth_users (id serial PRIMARY KEY, email text, display_name text NOT NULL, avatar_url text, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now());
CREATE TABLE IF NOT EXISTS auth_accounts (id serial PRIMARY KEY, user_id integer NOT NULL REFERENCES auth_users(id) ON DELETE CASCADE, provider text NOT NULL, provider_account_id text NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), UNIQUE(provider, provider_account_id));
CREATE TABLE IF NOT EXISTS site_contact_settings (key text PRIMARY KEY, value text NOT NULL, updated_at timestamptz NOT NULL DEFAULT now());
