Skip to content

Commit ef8a85f

Browse files
authored
Merge pull request #428 from code0-tech/411-handle-datatype-deletion
Handle datatype deletion
2 parents a16018c + 5162281 commit ef8a85f

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

app/services/runtimes/data_types/update_service.rb

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def initialize(current_runtime, data_types)
1414

1515
def execute
1616
transactional do |t|
17+
# rubocop:disable Rails/SkipsModelValidations -- when marking definitions as removed, we don't care about validations
18+
DataType.where(runtime: current_runtime).update_all(removed_at: Time.zone.now)
19+
# rubocop:enable Rails/SkipsModelValidations
1720
sort_data_types(data_types).each do |data_type|
1821
unless update_datatype(data_type, t)
1922
t.rollback_and_return! ServiceResponse.error(message: 'Failed to update data type',
@@ -48,6 +51,7 @@ def sort_data_types(data_types)
4851

4952
def update_datatype(data_type, t)
5053
db_object = DataType.find_or_initialize_by(runtime: current_runtime, identifier: data_type.identifier)
54+
db_object.removed_at = nil
5155
db_object.variant = data_type.variant.to_s.downcase
5256
if data_type.parent_type_identifier.present?
5357
db_object.parent_type = find_datatype(data_type.parent_type_identifier, t)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AddRemovedAtToDataTypes < Code0::ZeroTrack::Database::Migration[1.0]
4+
def change
5+
add_column :data_types, :removed_at, :datetime_with_timezone
6+
end
7+
end

db/schema_migrations/20250402181847

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
44c7c0e62c4ab733012ec9043cbb198555e48790b2c9fbb8a9f0a45590dc4289

db/structure.sql

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ CREATE TABLE data_types (
147147
updated_at timestamp with time zone NOT NULL,
148148
parent_type_id bigint,
149149
runtime_id bigint NOT NULL,
150+
removed_at timestamp with time zone,
150151
CONSTRAINT check_3a7198812e CHECK ((char_length(identifier) <= 50))
151152
);
152153

spec/requests/grpc/sagittarius/data_type_service_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,16 @@
105105
expect(small_positive_number.parent_type).to eq(positive_number)
106106
end
107107
end
108+
109+
context 'when removing datatypes' do
110+
let!(:existing_data_type) { create(:data_type, runtime: runtime) }
111+
let(:data_types) { [] }
112+
113+
it 'marks the datatype as removed' do
114+
stub.update(message, authorization(runtime))
115+
116+
expect(existing_data_type.reload.removed_at).to be_present
117+
end
118+
end
108119
end
109120
end

0 commit comments

Comments
 (0)