diff --git a/app/models/data_type.rb b/app/models/data_type.rb index d0b96a0d..4bd29e1e 100644 --- a/app/models/data_type.rb +++ b/app/models/data_type.rb @@ -17,6 +17,8 @@ class DataType < ApplicationRecord has_translation :display_messages, purpose: :display_message has_translation :aliases, purpose: :alias + validates :identifier, presence: true, length: { maximum: 200 }, + uniqueness: { case_sensitive: false, scope: :runtime_id } validates :type, presence: true, length: { maximum: 65_536 } validates :definition_source, length: { maximum: 50 } diff --git a/db/migrate/20260802173300_increase_data_type_identifier_limit.rb b/db/migrate/20260802173300_increase_data_type_identifier_limit.rb new file mode 100644 index 00000000..adc11771 --- /dev/null +++ b/db/migrate/20260802173300_increase_data_type_identifier_limit.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class IncreaseDataTypeIdentifierLimit < Code0::ZeroTrack::Database::Migration[1.0] + def change + remove_check_constraint :data_types, 'char_length(identifier) <= 50', name: 'check_3a7198812e' + + add_check_constraint :data_types, 'char_length(identifier) <= 200', name: 'check_3a7198812e' + end +end diff --git a/db/schema_migrations/20260802173300 b/db/schema_migrations/20260802173300 new file mode 100644 index 00000000..9107a781 --- /dev/null +++ b/db/schema_migrations/20260802173300 @@ -0,0 +1 @@ +dae616c0f9d3387cc26c3f3bd158c371757a26df88a597baf79b9e24dfbd8298 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 69a8f091..8192c80e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -169,7 +169,7 @@ CREATE TABLE data_types ( definition_source text, runtime_module_id bigint NOT NULL, CONSTRAINT check_01ca31b7b9 CHECK ((char_length(type) <= 65536)), - CONSTRAINT check_3a7198812e CHECK ((char_length(identifier) <= 50)), + CONSTRAINT check_3a7198812e CHECK ((char_length(identifier) <= 200)), CONSTRAINT check_a133157a46 CHECK ((char_length(definition_source) <= 50)) ); diff --git a/spec/models/data_type_spec.rb b/spec/models/data_type_spec.rb index 92570359..1d6f6aee 100644 --- a/spec/models/data_type_spec.rb +++ b/spec/models/data_type_spec.rb @@ -20,6 +20,9 @@ end describe 'validations' do + it { is_expected.to validate_presence_of(:identifier) } + it { is_expected.to validate_length_of(:identifier).is_at_most(200) } + it { is_expected.to validate_uniqueness_of(:identifier).case_insensitive.scoped_to(:runtime_id) } it { is_expected.to validate_presence_of(:type) } it { is_expected.to validate_length_of(:type).is_at_most(65_536) } it { is_expected.to validate_length_of(:definition_source).is_at_most(50) }