Skip to content

Handle datatype deletion #428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2025
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
4 changes: 4 additions & 0 deletions app/services/runtimes/data_types/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20250402181847_add_removed_at_to_data_types.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions db/schema_migrations/20250402181847
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
44c7c0e62c4ab733012ec9043cbb198555e48790b2c9fbb8a9f0a45590dc4289
1 change: 1 addition & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);

Expand Down
11 changes: 11 additions & 0 deletions spec/requests/grpc/sagittarius/data_type_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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