From 7ab33d86f1648315e2ad7e1823cda43488d8becc Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Sun, 8 Feb 2026 14:09:28 +1100 Subject: [PATCH] Add Customer credit payment method migration --- ...4509_add_customer_credit_payment_method.rb | 33 +++++++++++++++++++ db/schema.rb | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20260206054509_add_customer_credit_payment_method.rb diff --git a/db/migrate/20260206054509_add_customer_credit_payment_method.rb b/db/migrate/20260206054509_add_customer_credit_payment_method.rb new file mode 100644 index 0000000000..6b940ccdce --- /dev/null +++ b/db/migrate/20260206054509_add_customer_credit_payment_method.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class AddCustomerCreditPaymentMethod < ActiveRecord::Migration[7.1] + def up + # Create payment method + execute(<<-SQL.squish + INSERT INTO spree_payment_methods ( type, name, description, environment, active, display_on, created_at, updated_at) + VALUES ('Spree::PaymentMethod::CustomerCredit', 'credit_payment_method.name', 'credit_payment_method.description', '#{Rails.env}', true, 'both', NOW(), NOW()) + SQL + ) + + # Link to existing hub + execute(<<-SQL.squish + INSERT INTO distributors_payment_methods (distributor_id, payment_method_id, created_at, updated_at) + SELECT id, (SELECT id FROM spree_payment_methods WHERE name = 'credit_payment_method.name' LIMIT 1) as payment_method_id, NOW() as created_at, NOW() as updated_at + FROM enterprises WHERE sells != 'none' + SQL + ) + end + + def down + execute(<<-SQL.squish + DELETE FROM distributors_payment_methods + WHERE payment_method_id = (SELECT id FROM spree_payment_methods WHERE name = 'credit_payment_method.name') + SQL + ) + + execute(<<-SQL.squish + DELETE FROM spree_payment_methods WHERE name = 'credit_payment_method.name' + SQL + ) + end +end diff --git a/db/schema.rb b/db/schema.rb index 056392e7a1..ace4561488 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2026_01_30_041706) do +ActiveRecord::Schema[7.1].define(version: 2026_02_06_054509) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql"