mckaywrigley/chatbot-ui

Updating existing file "20240125192042_upgrade_openai_models.sql" is not OK for migration

Opened this issue · 1 comments

In order to perform a correct supabase upgrade with an existing DB, I think it is mandatory to create a new file to do the migration between existing sql schema or value and new ones.

The content of this new migration file could be (to move from 'gpt-4-turbo-preview' to 'gpt-4-turbo'):

-- WORKSPACES

UPDATE workspaces
SET default_model = 'gpt-4-turbo'
WHERE default_model = 'gpt-4-turbo-preview';

-- PRESETS

UPDATE presets
SET model = 'gpt-4-turbo'
WHERE model = 'gpt-4-turbo-preview';

-- ASSISTANTS

UPDATE assistants
SET model = 'gpt-4-turbo'
WHERE model = 'gpt-4-turbo-preview';

-- CHATS

UPDATE chats
SET model = 'gpt-4-turbo'
WHERE model = 'gpt-4-turbo-preview';

-- MESSAGES

UPDATE messages
SET model = 'gpt-4-turbo'
WHERE model = 'gpt-4-turbo-preview';

-- PROFILES

CREATE OR REPLACE FUNCTION create_profile_and_workspace() 
RETURNS TRIGGER
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
DECLARE
    random_username TEXT;
BEGIN
    -- Generate a random username
    random_username := 'user' || substr(replace(gen_random_uuid()::text, '-', ''), 1, 16);

    -- Create a profile for the new user
    INSERT INTO public.profiles(user_id, anthropic_api_key, azure_openai_35_turbo_id, azure_openai_45_turbo_id, azure_openai_45_vision_id, azure_openai_api_key, azure_openai_endpoint, google_gemini_api_key, has_onboarded, image_url, image_path, mistral_api_key, display_name, bio, openai_api_key, openai_organization_id, perplexity_api_key, profile_context, use_azure_openai, username)
    VALUES(
        NEW.id,
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        FALSE,
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        '',
        FALSE,
        random_username
    );

    INSERT INTO public.workspaces(user_id, is_home, name, default_context_length, default_model, default_prompt, default_temperature, description, embeddings_provider, include_profile_context, include_workspace_instructions, instructions)
    VALUES(
        NEW.id,
        TRUE,
        'Home',
        4096,
        'gpt-4-turbo', -- Updated default model
        'You are a friendly, helpful AI assistant.',
        0.5,
        'My home workspace.',
        'openai',
        TRUE,
        TRUE,
        ''
    );

    RETURN NEW;
END;
$$;

I agree. The recent PR #1672 should not have been merged. There are some problems with it, including this issue, that should have been fixed before merging.

Details written in the PR review.