Skip to content

Commit

Permalink
return result_id if the row does not exists yet
Browse files Browse the repository at this point in the history
  • Loading branch information
nudded committed Dec 19, 2024
1 parent 6da0c9e commit e7534d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/models/subscription_event_trigger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

class SubscriptionEventTrigger < ApplicationRecord
validates :organization_id, :external_subscription_id, :created_at, presence: true

def self.trigger(organization_id:, external_subscription_id:)
connection.select_all sanitize_sql_array(["call trigger_subscription_update(?,?, null)", organization_id, external_subscription_id])
end
end

# == Schema Information
Expand Down
9 changes: 5 additions & 4 deletions db/events_structure.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ def up
execute "
CREATE OR REPLACE PROCEDURE trigger_subscription_update(
p_organization_id UUID,
p_external_subscription_id varchar
p_external_subscription_id varchar,
result_id INOUT UUID
)
LANGUAGE plpgsql
AS $$
Expand All @@ -21,7 +22,8 @@ def up
p_external_subscription_id,
NOW()
)
ON CONFLICT DO NOTHING;
ON CONFLICT DO NOTHING
RETURNING id INTO result_id;
END;
$$;"
end
Expand Down
9 changes: 5 additions & 4 deletions db/structure.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7534d3

Please sign in to comment.