diff --git a/app/services/runtimes/data_types/update_service.rb b/app/services/runtimes/data_types/update_service.rb index 16fa2ba..7cb95c6 100644 --- a/app/services/runtimes/data_types/update_service.rb +++ b/app/services/runtimes/data_types/update_service.rb @@ -14,6 +14,9 @@ def initialize(current_runtime, data_types) def execute transactional do |t| + # rubocop:disable Rails/SkipsModelValidations -- when marking definitions as removed, we don't care about validations + DataType.where(runtime: current_runtime).update_all(removed_at: Time.zone.now) + # rubocop:enable Rails/SkipsModelValidations sort_data_types(data_types).each do |data_type| unless update_datatype(data_type, t) t.rollback_and_return! ServiceResponse.error(message: 'Failed to update data type', @@ -48,6 +51,7 @@ def sort_data_types(data_types) def update_datatype(data_type, t) db_object = DataType.find_or_initialize_by(runtime: current_runtime, identifier: data_type.identifier) + db_object.removed_at = nil db_object.variant = data_type.variant.to_s.downcase if data_type.parent_type_identifier.present? db_object.parent_type = find_datatype(data_type.parent_type_identifier, t) diff --git a/db/migrate/20250402181847_add_removed_at_to_data_types.rb b/db/migrate/20250402181847_add_removed_at_to_data_types.rb new file mode 100644 index 0000000..7b62184 --- /dev/null +++ b/db/migrate/20250402181847_add_removed_at_to_data_types.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddRemovedAtToDataTypes < Code0::ZeroTrack::Database::Migration[1.0] + def change + add_column :data_types, :removed_at, :datetime_with_timezone + end +end diff --git a/db/schema_migrations/20250402181847 b/db/schema_migrations/20250402181847 new file mode 100644 index 0000000..3568046 --- /dev/null +++ b/db/schema_migrations/20250402181847 @@ -0,0 +1 @@ +44c7c0e62c4ab733012ec9043cbb198555e48790b2c9fbb8a9f0a45590dc4289 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 70f2449..23c73d0 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -147,6 +147,7 @@ CREATE TABLE data_types ( updated_at timestamp with time zone NOT NULL, parent_type_id bigint, runtime_id bigint NOT NULL, + removed_at timestamp with time zone, CONSTRAINT check_3a7198812e CHECK ((char_length(identifier) <= 50)) ); diff --git a/spec/requests/grpc/sagittarius/data_type_service_spec.rb b/spec/requests/grpc/sagittarius/data_type_service_spec.rb index 3df9bdd..bb91a0c 100644 --- a/spec/requests/grpc/sagittarius/data_type_service_spec.rb +++ b/spec/requests/grpc/sagittarius/data_type_service_spec.rb @@ -105,5 +105,16 @@ expect(small_positive_number.parent_type).to eq(positive_number) end end + + context 'when removing datatypes' do + let!(:existing_data_type) { create(:data_type, runtime: runtime) } + let(:data_types) { [] } + + it 'marks the datatype as removed' do + stub.update(message, authorization(runtime)) + + expect(existing_data_type.reload.removed_at).to be_present + end + end end end