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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion app/models/flow_type_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/services/runtimes/grpc/flow_types/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions db/schema_migrations/20260112204516
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ddb715acbe8013d0a78d72037bd745fc87ccb7520b1653b13240320432e43b79
4 changes: 2 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/flow_type_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/models/flow_type_setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 15 additions & 3 deletions spec/requests/grpc/sagittarius/flow_type_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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: [
Expand Down Expand Up @@ -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')
Expand Down