Add type to WebhookEnpoints

Add migration to update existing endpoint to "order_cycle_opened" type
This commit is contained in:
Gaetan Craig-Riou
2025-11-24 16:13:11 +11:00
parent da7f46de1f
commit 059e36318e
4 changed files with 24 additions and 0 deletions

View File

@@ -2,5 +2,8 @@
# Records a webhook url to send notifications to
class WebhookEndpoint < ApplicationRecord
WEBHOOK_TYPES = %w(order_cycle_opened payment_status_changed).freeze
validates :url, presence: true
validates :webhook_type, presence: true, inclusion: { in: WEBHOOK_TYPES }
end

View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
class AddTypeToWebhookEndpoints < ActiveRecord::Migration[7.1]
def up
# Using "order_cycle_opened" as default will update existing record
change_table(:webhook_endpoints, bulk: true) do |t|
t.column :webhook_type, :string, limit: 255, null: false, default: "order_cycle_opened"
end
# Drop the default value
change_column_default :webhook_endpoints, :webhook_type, nil
end
def down
remove_column :webhook_endpoints, :webhook_type
end
end

View File

@@ -1143,6 +1143,7 @@ ActiveRecord::Schema[7.1].define(version: 2025_11_26_005628) do
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "user_id", default: 0, null: false
t.string "webhook_type", limit: 255, null: false
t.index ["user_id"], name: "index_webhook_endpoints_on_user_id"
end

View File

@@ -5,5 +5,9 @@ require 'spec_helper'
RSpec.describe WebhookEndpoint do
describe "validations" do
it { is_expected.to validate_presence_of(:url) }
it {
is_expected.to validate_inclusion_of(:webhook_type)
.in_array(%w(order_cycle_opened payment_status_changed))
}
end
end