Flarum zu Discourse Migrationsskript

Hallo zusammen,

ich habe mich kurzerhand entschlossen, einen Post zu schreiben, der kurz erläutert, wie wir unser Forum mit über 25.000 Mitgliedern und mehr als 250.000 Beiträgen von Flarum nach Discourse migriert haben.

Wie ihr wahrscheinlich wisst, wenn ihr das lest, gibt es kein offizielles Import-Skript für den Übergang von Flarum nach Discourse. Allerdings war @koen360 so freundlich, seine Arbeit an einem modifizierten FluxBB-Importer zum Importieren von Benutzern mit uns zu teilen. Da ein großer Teil des Erfolgs unseres Forums darauf beruht, dass Nutzer nach sehr spezifischen Begriffen in den Beiträgen suchen, mussten wir jedoch auch die Beiträge importieren. Das ist es also, was wir getan haben – nach mehreren Stunden gescheiterter Migrationen, Kopfschmerzen und einigen blutigen Zwischenfällen.

Ich bin keineswegs ein Experte für das Schreiben von Migrations-Skripten, aber dieses Skript funktioniert für die aktuelle Version von Flarum zum Zeitpunkt des Schreibens (V0.1.0-beta.16) ausreichend gut. Das Skript (siehe unten angehängt) benötigt Zugriff auf eure MySQL/MariaDB-Datenbank, vorzugsweise eine Kopie davon, damit ihr eure Produktionsseite nicht beschädigt, falls etwas schiefgeht. Ersetzt einfach die Platzhalterwerte in der MySQL-Verbindung, und ihr sollte startklar sein.

Stellt sicher, dass ihr vor Beginn dieses Prozesses ein vollständiges Backup eurer Flarum-Datenbank habt. Falls etwas schiefgeht, ist es wahrscheinlich nicht mehr rückgängig zu machen.

Falls ihr Unterstützung bei eurer Migration von Flarum nach Discourse benötigt, antwortet gerne auf diesen Thread. Ich bin zwar kein Experte, aber ich werde versuchen, so gut es geht zu helfen.

Hier könnt ihr den Importer herunterladen. Anscheinend kann ich keine Dateien hochladen, da dies mein erster Post ist

12 „Gefällt mir“

Danke, dass du das Skript erstellt hast, @Lecter! Kannst du es als PR bei discourse/discourse einreichen? Wir haben noch kein Flarum-Skript, daher wäre dies als Basis sehr hilfreich.

7 „Gefällt mir“

Auf jeden Fall! PR kommt…

7 „Gefällt mir“

Das ist großartig, danke, dass du diesen Importer noch einen Schritt weitergebracht hast! :sparkling_heart: Ich hoffe, dass er sich mit der Zeit auch um Tags erweitern lässt, falls nicht um Anhänge.

Wie viel Aufwand wäre es wohl, die Tag-Unterstützung hinzuzufügen? Ich sehe, dass vBulletin 5 und vielleicht ein paar andere Beispiele haben, wie das funktioniert, aber ich habe keine Ahnung, wie viel davon für Flarum angepasst werden müsste. Danke für jeden Hinweis, den jemand geben kann – und keine Sorge, falls das nicht wirklich beantwortet werden kann, ohne es einfach zu versuchen. :grinning_face_with_smiling_eyes:

1 „Gefällt mir“

Hallo @Lecter!

Ist dein Skript noch gültig? Kannst du es noch einmal teilen? Denn dein Link ist tot. :frowning:

Danke für die Berücksichtigung meiner Anfrage.

Das von @Lecter geschriebene Skript befindet sich jetzt unter

4 „Gefällt mir“

Kann mir jemand bitte bei der Migration helfen?

Ich habe Discourse mit leeren Beiträgen und 3 Standardkategorien.
Als ich versuchte, SQL von Flarum nach Discourse zu importieren, erhielt ich diese Fehlermeldung:

su discourse -c 'bundle exec ruby script/import_scripts/flarum_import.rb'
Loading existing groups...
Loading existing users...
Loading existing categories...
Loading existing posts...
Loading existing topics...

creating users
       13 / 13 (100.0%)  [281 items/min]  n]  
importing top level categories...
       39 / 39 (100.0%)  [420 items/min]  n]  
importing children categories...
       39 / 39 (100.0%)  [290 items/min]  
creating topics and posts
Traceback (most recent call last):
	19: from script/import_scripts/flarum_import.rb:162:in `<main>'
	18: from /var/www/discourse/script/import_scripts/base.rb:47:in `perform'
	17: from script/import_scripts/flarum_import.rb:32:in `execute'
	16: from script/import_scripts/flarum_import.rb:101:in `import_posts'
	15: from /var/www/discourse/script/import_scripts/base.rb:916:in `batches'
	14: from /var/www/discourse/script/import_scripts/base.rb:916:in `loop'
	13: from /var/www/discourse/script/import_scripts/base.rb:917:in `block in batches'
	12: from script/import_scripts/flarum_import.rb:122:in `block in import_posts'
	11: from /var/www/discourse/script/import_scripts/base.rb:224:in `all_records_exist?'
	10: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3/lib/active_record/transactions.rb:209:in `transaction'
	 9: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
	 8: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
	 7: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
	 6: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
	 5: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
	 4: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
	 3: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
	 2: from /var/www/discourse/script/import_scripts/base.rb:231:in `block in all_records_exist?'
	 1: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:56:in `exec'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:56:in `exec': ERROR:  duplicate key value violates unique constraint "import_ids_pkey" (PG::UniqueViolation)
DETAIL:  Key (val)=(7) already exists.
	20: from script/import_scripts/flarum_import.rb:162:in `<main>'
	19: from /var/www/discourse/script/import_scripts/base.rb:47:in `perform'
	18: from script/import_scripts/flarum_import.rb:32:in `execute'
	17: from script/import_scripts/flarum_import.rb:101:in `import_posts'
	16: from /var/www/discourse/script/import_scripts/base.rb:916:in `batches'
	15: from /var/www/discourse/script/import_scripts/base.rb:916:in `loop'
	14: from /var/www/discourse/script/import_scripts/base.rb:917:in `block in batches'
	13: from script/import_scripts/flarum_import.rb:122:in `block in import_posts'
	12: from /var/www/discourse/script/import_scripts/base.rb:224:in `all_records_exist?'
	11: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3/lib/active_record/transactions.rb:209:in `transaction'
	10: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3/lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
	 9: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
	 8: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
	 7: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
	 6: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
	 5: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activesupport-7.0.3/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
	 4: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.3/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
	 3: from /var/www/discourse/script/import_scripts/base.rb:243:in `block in all_records_exist?'
	 2: from /var/www/discourse/script/import_scripts/base.rb:243:in `ensure in block in all_records_exist?'
	 1: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:56:in `exec'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:56:in `exec': ERROR:  current transaction is aborted, commands ignored until end of transaction block (PG::InFailedSqlTransaction)

Das Problem liegt bei Key (val)=(7) already exists.

`exec': ERROR:  duplicate key value violates unique constraint "import_ids_pkey" (PG::UniqueViolation)
DETAIL:  Key (val)=(7) already exists.
root@raspberrypi-app:/var/www/discourse# rake db:validate_indexes
Starting postgres on port: 11000
Waiting for PG server to start...
PG server is ready and DB is loaded
Running migrations on blank database!

Testing indexes on the default database

No missing indexes

No extra indexes

Wie kann ich das beheben?

Dieser SQL-Code bricht das Skript

 SELECT p.id id,
               d.id topic_id,
               d.title title,
               d.first_post_id first_post_id,
               p.user_id user_id,
               p.content raw,
               p.created_at created_at,
               t.tag_id category_id
        FROM posts p,
             discussions d,
             discussion_tag t
        WHERE p.discussion_id = d.id
          AND t.discussion_id = d.id
        ORDER BY p.created_at

Ich habe das Problem gefunden. In meinem Fall hat ein Beitrag mehrere Tags. Nachdem ich solche Beiträge gelöscht hatte, wurde das Importskript ohne Fehler verarbeitet.

2 „Gefällt mir“

Ich habe diesen Fehler erhalten

ubuntu@ip-172-26-1-78:~/discourse$ bundle exec ruby script/import_scripts/flarum_import.rb
Loading existing groups...
Loading existing users...
Loading existing categories...
Loading existing posts...
Loading existing topics...

creating users
Skipping 1000 already imported users
Skipping 826 already imported users

importing top level categories...
       34 / 34 (100.0%)  [5728165 items/min]  
importing children categories...
       34 / 34 (100.0%)  [3194 items/min]  
creating topics and posts
Traceback (most recent call last):
	19: from script/import_scripts/flarum_import.rb:162:in `<main>'
	18: from /home/ubuntu/discourse/script/import_scripts/base.rb:47:in `perform'
	17: from script/import_scripts/flarum_import.rb:32:in `execute'
	16: from script/import_scripts/flarum_import.rb:101:in `import_posts'
	15: from /home/ubuntu/discourse/script/import_scripts/base.rb:916:in `batches'
	14: from /home/ubuntu/discourse/script/import_scripts/base.rb:916:in `loop'
	13: from /home/ubuntu/discourse/script/import_scripts/base.rb:917:in `block in batches'
	12: from script/import_scripts/flarum_import.rb:122:in `block in import_posts'
	11: from /home/ubuntu/discourse/script/import_scripts/base.rb:224:in `all_records_exist?'
	10: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/transactions.rb:209:in `transaction'
	 9: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
	 8: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
	 7: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
	 6: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
	 5: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
	 4: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
	 3: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
	 2: from /home/ubuntu/discourse/script/import_scripts/base.rb:243:in `block in all_records_exist?'
	 1: from /home/ubuntu/discourse/script/import_scripts/base.rb:243:in `ensure in block in all_records_exist?'
	 1: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:56:in `exec'
/home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:56:in `exec': ERROR:  duplicate key value violates unique constraint "import_ids_pkey" (PG::UniqueViolation)
DETAIL:  Key (val)=(53) already exists.
	20: from script/import_scripts/flarum_import.rb:162:in `<main>'
	19: from /home/ubuntu/discourse/script/import_scripts/base.rb:47:in `perform'
	18: from script/import_scripts/flarum_import.rb:32:in `execute'
	17: from script/import_scripts/flarum_import.rb:101:in `import_posts'
	16: from /home/ubuntu/discourse/script/import_scripts/base.rb:916:in `batches'
	15: from /home/ubuntu/discourse/script/import_scripts/base.rb:916:in `loop'
	14: from /home/ubuntu/discourse/script/import_scripts/base.rb:917:in `block in batches'
	13: from script/import_scripts/flarum_import.rb:122:in `block in import_posts'
	12: from /home/ubuntu/discourse/script/import_scripts/base.rb:224:in `all_records_exist?'
	11: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/transactions.rb:209:in `transaction'
	10: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
	 9: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
	 8: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
	 7: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
	 6: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
	 5: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activesupport-7.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
	 4: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
	 3: from /home/ubuntu/discourse/script/import_scripts/base.rb:243:in `block in all_records_exist?'
	 2: from /home/ubuntu/discourse/script/import_scripts/base.rb:243:in `ensure in block in all_records_exist?'
	 1: from /home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:56:in `exec'
/home/ubuntu/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:56:in `exec': ERROR:  current transaction is aborted, commands ignored until end of transaction block (PG::InFailedSqlTransaction)

Hallo,

Können Sie erklären, wie Sie das gemacht haben? Denn ich habe denselben Fehler wie Sie, aber anstelle von (val)=(7) erhalte ich:

`exec’: ERROR: duplicate key value violates unique constraint "import_ids_pkey" (PG::UniqueViolation)\nDETAIL: Key (val)=(1) already exists.