Files
sure/db/migrate/20251111094448_migrate_dynamic_fields_to_individual_entries.rb
soky srm fad241c416 Fixes & Improvements (#316)
* Some improvements

- Fix issue with lunch flow accounts that were imported
- Remove the period comparison section from reports

* Add cleanup migration

* FIX for dynamic config

* Fix linter

* FIX settings setter

Reuse the base class’ atomic setter to leverage its locking and cache invalidation.

* Make upsert atomic

* Remove migration file

Signed-off-by: soky srm <sokysrm@gmail.com>

* Delete db/migrate/20251111094448_migrate_dynamic_fields_to_individual_entries.rb

Signed-off-by: soky srm <sokysrm@gmail.com>

* Fix cache reset

* Revert "Remove migration file"

This reverts commit 1f2a21ef58.

* Revert "Delete db/migrate/20251111094448_migrate_dynamic_fields_to_individual_entries.rb"

This reverts commit 29dcaaafb2.

* Fix Plaid initialiser

---------

Signed-off-by: soky srm <sokysrm@gmail.com>
2025-11-11 19:51:07 +01:00

36 lines
1.0 KiB
Ruby

class MigrateDynamicFieldsToIndividualEntries < ActiveRecord::Migration[7.2]
def up
# Find the dynamic_fields setting record
dynamic_fields_record = Setting.find_by(var: "dynamic_fields")
return unless dynamic_fields_record
# Parse the hash and create individual entries
dynamic_fields_hash = dynamic_fields_record.value || {}
dynamic_fields_hash.each do |key, value|
Setting.create!(
var: "dynamic:#{key}",
value: value
)
end
# Delete the old dynamic_fields record
dynamic_fields_record.destroy
end
def down
# Collect all dynamic: entries back into a hash
dynamic_fields_hash = {}
Setting.where("var LIKE ?", "dynamic:%").find_each do |record|
key = record.var.sub(/^dynamic:/, "")
dynamic_fields_hash[key] = record.value
record.destroy
end
# Recreate the dynamic_fields record with the hash
Setting.create!(
var: "dynamic_fields",
value: dynamic_fields_hash
) if dynamic_fields_hash.any?
end
end