-- Migration 018: Add provider_name column to all_repositories table
-- This migration adds support for multiple repository providers (GitHub, GitLab, Bitbucket, etc.)

-- Add provider_name column to all_repositories table
ALTER TABLE all_repositories 
ADD COLUMN IF NOT EXISTS provider_name VARCHAR(50) DEFAULT 'github' NOT NULL;

-- Create index for provider_name for better query performance
CREATE INDEX IF NOT EXISTS idx_all_repos_provider_name ON all_repositories(provider_name);

-- Add comment to document the column purpose
COMMENT ON COLUMN all_repositories.provider_name IS 'Repository provider (github, gitlab, bitbucket, etc.)';

-- Update existing records to have 'github' as provider_name (if any exist without it)
UPDATE all_repositories 
SET provider_name = 'github' 
WHERE provider_name IS NULL OR provider_name = '';
