Sha256: 66e1ea27cab5d1a5b2e67afe8aa2ea562b655741a364a2229492922077edbf87
Contents?: true
Size: 1.72 KB
Versions: 28
Compression:
Stored size: 1.72 KB
Contents
class RemoveOldOrganizationSettings < ActiveRecord::Migration[5.1] def current_tenant @current_tenant ||= PandaPal::Organization.find_by_name(Apartment::Tenant.current) end def up # don't rerun this if it was already run before we renamed the migration. existing_versions = execute ("SELECT * from schema_migrations where version = '30171205194657'") if (existing_versions.count > 0) execute "DELETE from schema_migrations where version = '30171205194657'" return end # migrations run for public and local tenants. However, PandaPal::Organization # is going to always go to public tenant. So don't do this active record # stuff unless we are on the public tenant. if current_tenant == 'public' #PandaPal::Organization.connection.schema_cache.clear! #PandaPal::Organization.reset_column_information PandaPal::Organization.find_each do |o| # Would like to just be able to do this: # o.settings = YAML.load(o.old_settings) # o.save! # but for some reason that is always making the settings null. Instead we will encrypt the settings manually. iv = SecureRandom.random_bytes(12) key = o.encryption_key encrypted_settings = PandaPal::Organization.encrypt_settings(YAML.load(o.old_settings), iv: iv, key: key) o.update_columns(encrypted_settings_iv: [iv].pack("m"), encrypted_settings: encrypted_settings) end end remove_column :panda_pal_organizations, :old_settings end def down add_column :panda_pal_organizations, :old_settings, :text if current_tenant == 'public' PandaPal::Organization.find_each do |o| o.old_settings = o.settings.to_yaml o.save end end end end
Version data entries
28 entries across 28 versions & 1 rubygems