Skip to content

Commit

Permalink
Fix: change default value for WalletTransaction metadata (#2609)
Browse files Browse the repository at this point in the history
All api clients expect metadata to be returned as array (and when
records are created, it's also an array), but if we create
WalletTransaction without metadata, it takes default value of `{}` which
then breaks api-clients
  • Loading branch information
annvelents authored Sep 20, 2024
1 parent fd78551 commit ef2dfc6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

class ChangeWalletTransactionsMetadataDefault < ActiveRecord::Migration[7.1]
def up
change_column_default :wallet_transactions, :metadata, []
safety_assured do
execute <<-SQL
UPDATE wallet_transactions
SET metadata = '[]'::jsonb
WHERE metadata = '{}'::jsonb;
SQL
end
end

def down
change_column_default :wallet_transactions, :metadata, {}
safety_assured do
execute <<-SQL
UPDATE wallet_transactions
SET metadata = '{}'::jsonb
WHERE metadata = '[]'::jsonb;
SQL
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

class ChangeRecurringTransactionRulesTransactionMetadataDefault < ActiveRecord::Migration[7.1]
def up
change_column_default :recurring_transaction_rules, :transaction_metadata, []
safety_assured do
execute <<-SQL
UPDATE recurring_transaction_rules
SET transaction_metadata = '[]'::jsonb
WHERE transaction_metadata = '{}'::jsonb;
SQL
end
end

def down
change_column_default :recurring_transaction_rules, :transaction_metadata, {}
safety_assured do
execute <<-SQL
UPDATE recurring_transaction_rules
SET transaction_metadata = '{}'::jsonb
WHERE transaction_metadata = '[]'::jsonb;
SQL
end
end
end
6 changes: 3 additions & 3 deletions db/schema.rb

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 @@ -44,7 +44,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down Expand Up @@ -80,7 +80,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down Expand Up @@ -111,7 +111,7 @@
granted_credits: "0.0",
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand All @@ -136,7 +136,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down Expand Up @@ -165,7 +165,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down Expand Up @@ -199,7 +199,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand All @@ -224,7 +224,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down Expand Up @@ -253,7 +253,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand All @@ -277,7 +277,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand All @@ -302,7 +302,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down Expand Up @@ -331,7 +331,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down Expand Up @@ -426,7 +426,7 @@
granted_credits: recurring_transaction_rule.granted_credits.to_s,
source: :interval,
invoice_requires_successful_payment: true,
metadata: {}
metadata: []
}
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/services/wallets/threshold_top_up_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
granted_credits: "3.0",
source: :threshold,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down Expand Up @@ -132,7 +132,7 @@
granted_credits: "0.0",
source: :threshold,
invoice_requires_successful_payment: false,
metadata: {}
metadata: []
}
)
end
Expand Down

0 comments on commit ef2dfc6

Please sign in to comment.