From ddc72ef901298d0bfd15dd8b006f02565dd301ad Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Mon, 12 Jan 2026 22:03:48 +0100 Subject: [PATCH] Update tucana and fix FlowTypes::UpdateService --- Gemfile | 2 +- Gemfile.lock | 6 +++--- app/models/flow_type_setting.rb | 14 +++++++++++++- .../runtimes/grpc/flow_types/update_service.rb | 4 ++-- ..._change_flow_type_setting_unique_to_enum.rb | 8 ++++++++ db/schema_migrations/20260112204516 | 1 + db/structure.sql | 4 ++-- spec/factories/flow_type_settings.rb | 2 +- spec/models/flow_type_setting_spec.rb | 3 ++- .../grpc/sagittarius/flow_type_service_spec.rb | 18 +++++++++++++++--- 10 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20260112204516_change_flow_type_setting_unique_to_enum.rb create mode 100644 db/schema_migrations/20260112204516 diff --git a/Gemfile b/Gemfile index 7b39784f..00d7d8c4 100644 --- a/Gemfile +++ b/Gemfile @@ -79,7 +79,7 @@ gem 'good_job', '~> 4.0' gem 'rotp' gem 'grpc', '~> 1.67' -gem 'tucana', '0.0.49' +gem 'tucana', '0.0.50' gem 'code0-identities', '~> 0.0.3' diff --git a/Gemfile.lock b/Gemfile.lock index 043d69cc..2479dce1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -135,7 +135,7 @@ GEM fugit (>= 1.11.0) railties (>= 6.1.0) thor (>= 1.0.0) - google-protobuf (4.33.2) + google-protobuf (4.33.4) bigdecimal rake (>= 13) googleapis-common-protos-types (1.22.0) @@ -377,7 +377,7 @@ GEM thor (1.4.0) timeout (0.6.0) tsort (0.2.0) - tucana (0.0.49) + tucana (0.0.50) grpc (~> 1.64) tzinfo (2.0.6) concurrent-ruby (~> 1.0) @@ -431,7 +431,7 @@ DEPENDENCIES simplecov (~> 0.22.0) simplecov-cobertura (~> 3.0) test-prof (~> 1.0) - tucana (= 0.0.49) + tucana (= 0.0.50) tzinfo-data RUBY VERSION diff --git a/app/models/flow_type_setting.rb b/app/models/flow_type_setting.rb index 6392d4b4..2c925d0e 100644 --- a/app/models/flow_type_setting.rb +++ b/app/models/flow_type_setting.rb @@ -3,10 +3,22 @@ class FlowTypeSetting < ApplicationRecord belongs_to :flow_type, inverse_of: :flow_type_settings + UNIQUENESS_SCOPE = { + unknown: 0, + none: 1, + project: 2, + }.with_indifferent_access + + enum :unique, UNIQUENESS_SCOPE, prefix: :unique + belongs_to :data_type validates :identifier, presence: true, uniqueness: { scope: :flow_type_id } - validates :unique, inclusion: { in: [true, false] } + validates :unique, presence: true, + inclusion: { + in: UNIQUENESS_SCOPE.keys.map(&:to_s), + }, + exclusion: [0, :unknown, 'unknown'] has_many :names, -> { by_purpose(:name) }, class_name: 'Translation', as: :owner, inverse_of: :owner has_many :descriptions, -> { by_purpose(:description) }, class_name: 'Translation', as: :owner, inverse_of: :owner diff --git a/app/services/runtimes/grpc/flow_types/update_service.rb b/app/services/runtimes/grpc/flow_types/update_service.rb index 5221a893..0aa90509 100644 --- a/app/services/runtimes/grpc/flow_types/update_service.rb +++ b/app/services/runtimes/grpc/flow_types/update_service.rb @@ -71,8 +71,8 @@ def update_flowtype(flow_type, t) def update_settings(flow_type_settings, flow_type, t) flow_type.flow_type_settings = flow_type_settings.map do |setting| db_setting = FlowTypeSetting.find_or_initialize_by(flow_type: flow_type, identifier: setting.identifier) - db_setting.unique = setting.unique - db_setting.default_value = setting.default_value.to_ruby + db_setting.unique = setting.unique.to_s.downcase + db_setting.default_value = setting.default_value&.to_ruby db_setting.descriptions = update_translations(setting.description, db_setting.descriptions) db_setting.names = update_translations(setting.name, db_setting.names) db_setting.data_type = find_data_type(setting.data_type_identifier, t) diff --git a/db/migrate/20260112204516_change_flow_type_setting_unique_to_enum.rb b/db/migrate/20260112204516_change_flow_type_setting_unique_to_enum.rb new file mode 100644 index 00000000..05f7f886 --- /dev/null +++ b/db/migrate/20260112204516_change_flow_type_setting_unique_to_enum.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class ChangeFlowTypeSettingUniqueToEnum < Code0::ZeroTrack::Database::Migration[1.0] + def change + remove_column :flow_type_settings, :unique, :boolean, null: false, default: false + add_column :flow_type_settings, :unique, :integer, null: false, default: 0 + end +end diff --git a/db/schema_migrations/20260112204516 b/db/schema_migrations/20260112204516 new file mode 100644 index 00000000..522704a0 --- /dev/null +++ b/db/schema_migrations/20260112204516 @@ -0,0 +1 @@ +ddb715acbe8013d0a78d72037bd745fc87ccb7520b1653b13240320432e43b79 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 9212942a..219d2880 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -205,11 +205,11 @@ CREATE TABLE flow_type_settings ( id bigint NOT NULL, flow_type_id bigint NOT NULL, identifier text NOT NULL, - "unique" boolean DEFAULT false NOT NULL, data_type_id bigint NOT NULL, default_value jsonb, created_at timestamp with time zone NOT NULL, - updated_at timestamp with time zone NOT NULL + updated_at timestamp with time zone NOT NULL, + "unique" integer DEFAULT 0 NOT NULL ); CREATE SEQUENCE flow_type_settings_id_seq diff --git a/spec/factories/flow_type_settings.rb b/spec/factories/flow_type_settings.rb index 27eb0af3..51d25cec 100644 --- a/spec/factories/flow_type_settings.rb +++ b/spec/factories/flow_type_settings.rb @@ -6,7 +6,7 @@ factory :flow_type_setting do flow_type identifier { generate(:flow_type_setting_identifier) } - unique { false } + unique { :none } data_type default_value { '' } end diff --git a/spec/models/flow_type_setting_spec.rb b/spec/models/flow_type_setting_spec.rb index c351ae2b..dc84d887 100644 --- a/spec/models/flow_type_setting_spec.rb +++ b/spec/models/flow_type_setting_spec.rb @@ -15,6 +15,7 @@ describe 'validations' do it { is_expected.to validate_presence_of(:identifier) } it { is_expected.to validate_uniqueness_of(:identifier).scoped_to(:flow_type_id) } - it { is_expected.to allow_values(true, false).for(:unique) } + it { is_expected.to allow_values(:none, :project, 'none', 'project').for(:unique) } + it { is_expected.not_to allow_value(:unknown, 'unknown', 0).for(:unique) } end end diff --git a/spec/requests/grpc/sagittarius/flow_type_service_spec.rb b/spec/requests/grpc/sagittarius/flow_type_service_spec.rb index 02738e7f..a6d5409b 100644 --- a/spec/requests/grpc/sagittarius/flow_type_service_spec.rb +++ b/spec/requests/grpc/sagittarius/flow_type_service_spec.rb @@ -21,7 +21,7 @@ settings: [ { identifier: 'some_setting_identifier', - unique: true, + unique: :PROJECT, data_type_identifier: create(:data_type, runtime: runtime).identifier, default_value: Tucana::Shared::Value.from_ruby({ 'value' => 'some default value' }), name: [ @@ -30,6 +30,18 @@ description: [ { code: 'en_US', content: 'This is a setting' } ], + }, + { + identifier: 'without_default', + unique: :NONE, + data_type_identifier: create(:data_type, runtime: runtime).identifier, + default_value: nil, + name: [ + { code: 'en_US', content: 'Some Setting' } + ], + description: [ + { code: 'en_US', content: 'This is a setting' } + ], } ], name: [ @@ -80,10 +92,10 @@ expect(flow_type.return_type.identifier).to eq('some_return_type_identifier') expect(flow_type.version).to eq('0.0.0') - expect(flow_type.flow_type_settings.count).to eq(1) + expect(flow_type.flow_type_settings.count).to eq(2) setting = flow_type.flow_type_settings.first expect(setting.identifier).to eq('some_setting_identifier') - expect(setting.unique).to be true + expect(setting.unique).to eq('project') expect(setting.default_value).to eq('value' => 'some default value') expect(setting.names.count).to eq(1) expect(setting.names.first.code).to eq('en_US')