Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing columns breaks older logs #70

Closed
Frexuz opened this issue Apr 30, 2018 · 2 comments
Closed

Removing columns breaks older logs #70

Frexuz opened this issue Apr 30, 2018 · 2 comments
Labels

Comments

@Frexuz
Copy link
Contributor

Frexuz commented Apr 30, 2018

Possibly related to #59
We have this migration:

class ChangeIsAgentToAccountType < ActiveRecord::Migration[5.2]
  def up
    add_column :users, :account_type, :integer, default: 0, null: false

    User.all.each do |user|
      user.update(account_type: user.is_agent ? User.account_types[:agent] : User.account_types[:user])
    end

    remove_column :users, :is_agent
  end

  def down
    add_column :users, :is_agent, :boolean, default: false, null: false

    User.all.each do |user|
      user.update(is_agent: user.account_type_agent? ? true : false)
    end

    remove_column :users, :account_type
  end
end

so, is_agent column is now gone, but it is still in the log data.

In our admin, we print all changes for a specific record:

panel 'Version history' do
  versions = []
  log_size = resource.log_size
  (1..log_size).each do |version|
    #versions << resource.at(version: version)
  end
  table_for versions.reverse! do
    column('Version', &:log_version)
    column('Change') { |resource| log_data_change(resource) }
    column('Actions') { |resource| link_to 'Restore', "#{resource.id}/restore?log_version=#{resource.log_version}", method: :put, data: { confirm: t('are_you_sure') } }
  end
end

Error: can't write unknown attribute is_agentAt:resource.at(version: version)`

Stacktrace:

activemodel (5.2.0) lib/active_model/attribute.rb:207:in `with_value_from_database'
activemodel (5.2.0) lib/active_model/attribute_set.rb:57:in `write_from_user'
activerecord (5.2.0) lib/active_record/attribute_methods/write.rb:51:in `_write_attribute'
activerecord (5.2.0) lib/active_record/attribute_methods/write.rb:45:in `write_attribute'
logidze (0.6.3) lib/logidze/model.rb:206:in `apply_column_diff'
logidze (0.6.3) lib/logidze/model.rb:198:in `block in apply_diff'
logidze (0.6.3) lib/logidze/model.rb:197:in `each'
logidze (0.6.3) lib/logidze/model.rb:197:in `apply_diff'
logidze (0.6.3) lib/logidze/model.rb:211:in `build_dup'
logidze (0.6.3) lib/logidze/model.rb:112:in `at_version'
logidze (0.6.3) lib/logidze/model.rb:70:in `at'

Seems like it could be fixed by the gem. Is there any temporary fix we could do?

UPDATE:
Temporary fix: resource.log_data.data['h'].map{|l| l['c'].delete('is_agent') }

@palkan
Copy link
Owner

palkan commented Apr 30, 2018

Fixed by #71 and released as 0.6.4

@Frexuz
Copy link
Contributor Author

Frexuz commented May 1, 2018

So fast! :D <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants