Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/models/node_parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class NodeParameter < ApplicationRecord

validate :only_one_value_present

before_destroy :destroy_value_objects

def to_grpc
param = Tucana::Shared::NodeParameter.new(
database_id: id,
Expand Down Expand Up @@ -35,4 +37,9 @@ def only_one_value_present

errors.add(:value, 'Only one of literal_value, reference_value, or function_value must be present')
end

def destroy_value_objects
reference_value.destroy if reference_value.present?
function_value.destroy if function_value.present?
end
end
4 changes: 2 additions & 2 deletions app/services/namespaces/projects/flows/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def update_node_parameters(t, current_node, current_node_input, all_nodes)

db_parameters[index].function_value = node[:node]
else
db_parameters[index].function_value = nil
db_parameters[index].function_value&.destroy
end

if parameter.value.reference_value.present?
Expand Down Expand Up @@ -227,7 +227,7 @@ def update_node_parameters(t, current_node, current_node_input, all_nodes)
reference_paths: reference_paths
)
else
db_parameters[index].reference_value = nil
db_parameters[index].reference_value&.destroy
end

next if db_parameters[index].valid?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class MakeNodeFunctionConstraintsDeferrable < Code0::ZeroTrack::Database::Migration[1.0]
def change
remove_foreign_key :reference_values,
:node_functions,
on_delete: :restrict

add_foreign_key :reference_values,
:node_functions,
deferrable: :deferred

remove_foreign_key :node_functions,
:node_functions,
column: :next_node_id,
on_delete: :restrict

add_foreign_key :node_functions,
:node_functions,
column: :next_node_id,
deferrable: :deferred
end
end
1 change: 1 addition & 0 deletions db/schema_migrations/20260213230904
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
501fc65ab83b207de468a27d7e65c82b75fcf7f55def5678bd84e666b16dbd7f
4 changes: 2 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ ALTER TABLE ONLY node_functions
ADD CONSTRAINT fk_rails_8615bd0635 FOREIGN KEY (flow_id) REFERENCES flows(id) ON DELETE CASCADE;

ALTER TABLE ONLY reference_values
ADD CONSTRAINT fk_rails_8b9d8f68cc FOREIGN KEY (node_function_id) REFERENCES node_functions(id) ON DELETE RESTRICT;
ADD CONSTRAINT fk_rails_8b9d8f68cc FOREIGN KEY (node_function_id) REFERENCES node_functions(id) DEFERRABLE INITIALLY DEFERRED;

ALTER TABLE ONLY data_type_identifiers
ADD CONSTRAINT fk_rails_8d8385e8ec FOREIGN KEY (runtime_id) REFERENCES runtimes(id) ON DELETE CASCADE;
Expand Down Expand Up @@ -1415,4 +1415,4 @@ ALTER TABLE ONLY flow_type_settings
ADD CONSTRAINT fk_rails_f6af7d8edf FOREIGN KEY (flow_type_id) REFERENCES flow_types(id) ON DELETE CASCADE;

ALTER TABLE ONLY node_functions
ADD CONSTRAINT fk_rails_fbc91a3407 FOREIGN KEY (next_node_id) REFERENCES node_functions(id) ON DELETE RESTRICT;
ADD CONSTRAINT fk_rails_fbc91a3407 FOREIGN KEY (next_node_id) REFERENCES node_functions(id) DEFERRABLE INITIALLY DEFERRED;