-- Add app_type column to distinguish between genex-mobile and admin-app
ALTER TABLE app_versions ADD COLUMN IF NOT EXISTS app_type VARCHAR(20) NOT NULL DEFAULT 'GENEX_MOBILE';

-- Drop old unique index (platform, version_code) and recreate with app_type
DROP INDEX IF EXISTS idx_app_versions_platform_code;
CREATE UNIQUE INDEX IF NOT EXISTS idx_app_versions_app_platform_code
  ON app_versions(app_type, platform, version_code);

-- Update composite index for queries
DROP INDEX IF EXISTS idx_app_versions_platform;
CREATE INDEX IF NOT EXISTS idx_app_versions_app_platform
  ON app_versions(app_type, platform, is_enabled);
