From ed2ca439af91ac82e087d58753196669de44392a Mon Sep 17 00:00:00 2001 From: TivonB-AI2 <124182151+TivonB-AI2@users.noreply.github.com> Date: Tue, 18 Nov 2025 13:05:45 -0500 Subject: [PATCH] Resolve conflict in cherry-pick of 164fb54abb75887e6b8b934e1aad7249b66294c3 and change the commit message --- .../hosted_data_stores/delete_data_store.rb | 24 +++++++ .../delete_data_store_spec.rb | 65 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 server/enterprise/app/interactors/hosted_data_stores/delete_data_store.rb create mode 100644 server/spec/enterprise/interactors/hosted_data_stores/delete_data_store_spec.rb diff --git a/server/enterprise/app/interactors/hosted_data_stores/delete_data_store.rb b/server/enterprise/app/interactors/hosted_data_stores/delete_data_store.rb new file mode 100644 index 000000000..54400f278 --- /dev/null +++ b/server/enterprise/app/interactors/hosted_data_stores/delete_data_store.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module HostedDataStores + class DeleteDataStore + include Interactor + + HANDLERS = { + "vector_store_hosted_connector" => HostedDataStores::Postgres::DeletePostgresHostDataStore + }.freeze + + def call + template_id = context.hosted_data_store.template_id + workspace = context.workspace + hosted_data_store = context.hosted_data_store + class_name = HANDLERS[template_id] || raise("Invalid template id") + result = class_name.new(workspace:, hosted_data_store:).delete_data_store + raise "Failed to delete data store" unless result.destroyed? + + context.hosted_data_store = result + rescue StandardError => e + context.fail!(errors: e.message) + end + end +end diff --git a/server/spec/enterprise/interactors/hosted_data_stores/delete_data_store_spec.rb b/server/spec/enterprise/interactors/hosted_data_stores/delete_data_store_spec.rb new file mode 100644 index 000000000..319b83e68 --- /dev/null +++ b/server/spec/enterprise/interactors/hosted_data_stores/delete_data_store_spec.rb @@ -0,0 +1,65 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe HostedDataStores::DeleteDataStore, type: :interactor do + let(:workspace) { create(:workspace) } + let(:source_connector) { create(:connector) } + let(:destination_connector) { create(:connector) } + let(:hosted_data_store) { create(:hosted_data_store, workspace:, source_connector:, destination_connector:) } + let(:hosted_data_store_table) do + create(:hosted_data_store_table, hosted_data_store:, source_connector:, destination_connector:) + end + let(:params) do + { + template_id: "vector_store_hosted_connector" + } + end + let(:mock_connection) { instance_double(PG::Connection, exec: true, close: true) } + + before do + stub_const( + "ENV", + ENV.to_h.merge( + "HOSTED_VECTOR_DB_USERNAME" => "user", + "HOSTED_VECTOR_DB_PASSWORD" => "pass", + "HOSTED_VECTOR_DB_HOST" => "127.0.0.1", + "HOSTED_VECTOR_DB_PORT" => "5432", + "HOSTED_VECTOR_DB_DATABASE" => "test_db" + ) + ) + end + + describe "#call" do + it "deletes a data store" do + handler_instance = instance_double( + HostedDataStores::Postgres::DeletePostgresHostDataStore + ) + allow(handler_instance).to receive(:delete_data_store).and_return(true) + allow(handler_instance).to receive(:fetch_hosted_data_store).and_return(hosted_data_store) + allow(hosted_data_store).to receive(:destroyed?).and_return(true) + allow(HostedDataStores::Postgres::DeletePostgresHostDataStore).to receive(:new).and_return(handler_instance) + described_class.call(workspace:, hosted_data_store:) + expect(hosted_data_store).to be_destroyed + end + + it "deletes a data store if the data store is enabled" do + hosted_data_store.update(state: "enabled") + handler_instance = instance_double( + HostedDataStores::Postgres::DeletePostgresHostDataStore + ) + allow(handler_instance).to receive(:delete_data_store).and_return(true) + allow(handler_instance).to receive(:fetch_hosted_data_store).and_return(hosted_data_store) + allow(hosted_data_store).to receive(:destroyed?).and_return(true) + allow(HostedDataStores::Postgres::DeletePostgresHostDataStore).to receive(:new).and_return(handler_instance) + described_class.call(workspace:, hosted_data_store:) + expect(hosted_data_store).to be_destroyed + end + + it "raises an error if the data store deletion fails" do + interactor = described_class.call(workspace:, hosted_data_store:) + expect(interactor.destroyed?).to be_falsey + expect(interactor.errors).to be_present + end + end +end