Merge script error when copying tags

Looks like a very cool and useful script, but I encountered an error when I attempted this.
Any pointers to how I can resolve it? (no ruby experience)
Error message:

...
copying post_stats...
copying incoming_emails...
copying post_details...
copying post_revisions...
merging tags...
Traceback (most recent call last):
	4: from script/bulk_import/discourse_merger.rb:797:in `<main>'
	3: from script/bulk_import/discourse_merger.rb:65:in `start'
	2: from /home/xxxxx/discourse/script/bulk_import/base.rb:81:in `run'
	1: from script/bulk_import/discourse_merger.rb:81:in `execute'
script/bulk_import/discourse_merger.rb:271:in `copy_tags': undefined method `+' for nil:NilClass (NoMethodError)

Using the latest version of Discourse ( v2.2.0.beta2 +5 ) for both the sites.

1 Like

@jrgen I committed a fix for that problem:

https://github.com/discourse/discourse/commit/b9891c26417df1777b0cfc89ec41466436e10801

6 Likes

Thanks for that! I found a couple more errors while trying to merge two (small-ish) forums;

  1. Duplicate slug:
[...]
copying user_archived_messages...
copying unsubscribe_keys...
copying group_mentions...
copying user_histories...
copying user_warnings...
copying group_archived_messages...
copying notifications...
copying category_groups...
copying group_histories...
copying badge_groupings...
merging badges...
copying user_badges...
updating foreign keys in the users table...
updating category description topic ids...
Traceback (most recent call last):
	19: from script/bulk_import/discourse_merger.rb:798:in `<main>'
	18: from script/bulk_import/discourse_merger.rb:66:in `start'
	17: from /home/u/discourse/script/bulk_import/base.rb:81:in `run'
	16: from script/bulk_import/discourse_merger.rb:88:in `execute'
	15: from script/bulk_import/discourse_merger.rb:219:in `fix_category_descriptions'
	14: from script/bulk_import/discourse_merger.rb:219:in `each'
	13: from script/bulk_import/discourse_merger.rb:223:in `block in fix_category_descriptions'
	12: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/suppressor.rb:48:in `save!'
	11: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:315:in `save!'
	10: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:383:in `with_transaction_returning_status'
	 9: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:212:in `transaction'
	 8: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `transaction'
	 7: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:227:in `within_new_transaction'
	 6: from /home/u/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
	 5: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:230:in `block in within_new_transaction'
	 4: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `block in transaction'
	 3: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:386:in `block in with_transaction_returning_status'
	 2: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:315:in `block in save!'
	 1: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/validations.rb:52:in `save!'
/home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/validations.rb:80:in `raise_validation_error': Validation failed: Slug is already in use (ActiveRecord::RecordInvalid)
  1. Double nesting of categories (not sure how this can happen):
[...]
copying notifications...
copying category_groups...
copying group_histories...
copying badge_groupings...
merging badges...
copying user_badges...
updating foreign keys in the users table...
updating category description topic ids...
Traceback (most recent call last):
	19: from script/bulk_import/discourse_merger.rb:799:in `<main>'
	18: from script/bulk_import/discourse_merger.rb:66:in `start'
	17: from /home/u/discourse/script/bulk_import/base.rb:81:in `run'
	16: from script/bulk_import/discourse_merger.rb:88:in `execute'
	15: from script/bulk_import/discourse_merger.rb:219:in `fix_category_descriptions'
	14: from script/bulk_import/discourse_merger.rb:219:in `each'
	13: from script/bulk_import/discourse_merger.rb:224:in `block in fix_category_descriptions'
	12: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/suppressor.rb:48:in `save!'
	11: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:315:in `save!'
	10: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:383:in `with_transaction_returning_status'
	 9: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:212:in `transaction'
	 8: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `transaction'
	 7: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:227:in `within_new_transaction'
	 6: from /home/u/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
	 5: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/transaction.rb:230:in `block in within_new_transaction'
	 4: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `block in transaction'
	 3: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:386:in `block in with_transaction_returning_status'
	 2: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/transactions.rb:315:in `block in save!'
	 1: from /home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/validations.rb:52:in `save!'
/home/u/.rvm/gems/ruby-2.5.1/gems/activerecord-5.2.0/lib/active_record/validations.rb:80:in `raise_validation_error': Validation failed: You can't nest a subcategory under another (ActiveRecord::RecordInvalid)

Do you have two categories with the same slug but different names? :thinking: I guess the script should be merging categories based on slug (/c/:category/:subcategory) instead of name.

2 Likes

Yes, probably.
One of the sites is imported from vbulletin, the other from a new discourse-install. Most of the categories exist in both sites, I will try to align all names and slugs before trying again

3 Likes

This may have been what I was seeing as well (previous topic thread) as I was merging from a bbepress-to-discourse into a vb4-to-discourse.

best,
Walker

I made the merge tool smarter when merging/copying categories. It was only looking at category names :frowning: but now looks at full category url’s to distinguish parent categories too.

https://github.com/discourse/discourse/commit/8af6d8189186e9a504488ae219845c40c987c718

4 Likes