CLI command to migrate a single category

AI-generated summary

The discussion outlines a proposal for a CLI-only tool to migrate single categories between Discourse instances, addressing needs like reducing downtime during large migrations, splitting sites due to weak partitioning, or consolidating multiple small sites. sam specifies that the tool should export a single topic as a standalone unit containing all involved users, user actions, and posts in a tar, CSV, XML, or JSON format. The initial scope focuses on the export/import workflow for use case #1, with example commands like discourse export some_category > my_export.tar.

blake expresses interest in building a general discourse_cli application using the discourse_api gem and asks if this should be a separate project or part of the core codebase to allow direct SQL queries. blake subsequently shares a basic repository structure for such a tool at https://github.com/blake/discourse_cli, though it currently lacks specific migration features.

neil raises a critical concern regarding the proposed export formats, noting that the approach resembles the original backup/restore spec which failed when database schemas changed. He argues that the scope of what constitutes a “user” or “post” export must be strictly limited to ensure the tool remains maintainable. neil points to an existing related discussion on topic and category export/import at https://meta.discourse.org/t/topic-and-category-export-import/38930 for further context.

We need to build a general purpose tool for moving a category from one Discourse instance to another.

This has come up on one of our customers and is also useful for a variety of use cases:

Use cases for category import / export

  1. (current need) During huge migrations we may need to avoid long term downtime, so we need to run a temporary site on one domain and then ship the content (eventually) to the new imported site

  2. In some cases category partitioning is not strong enough, we have seen this issue at the site @BCHK hosts. In cases like this it may be desirable to partition a site into 2 seperate sites.

  3. In some cases many tiny Discourse sites are created unnecessarily and an amalgamation is desirable

A CLI tool only

The scope of this spec is for a command line tool only. There will be no GUI at all for the first version.

Topic export with layered category export

At the heart of it we need a mechanism to export a single topic as a stand alone unit that can be imported into another instance. Format wise we need to export all users , user actions and posts as single tar-csv, xml or json blob.

We are only interested in exporting “involved” users, that is, users that have tracking state, user actions or direct involvement with the topic.

Once applied to a category the export will avoid double exporting users, the format should specify users first and then content in each of the exported entities.

For v1 we need to cover user case (1) and have an importer.

Example usage

discourse export some_category > my_export.tar
discourse import < my_export.tar
18개의 좋아요

I’ve been wanting to build a discourse_cli app for sometime now so that it’s possible to do admin tasks like this and have it use the discourse_api gem.

Is this something you would like to have as a separate discourse_cli project or do you think it needs to live in discourse so that it can make actual sql queries?

I just created a CLI Tool that we can use for admin tasks like migrating categories.

https://github.com/blake/discourse_cli

This is just the basic structure for the CLI tool, it doesn’t haven any features yet other than displaying a list of categories.

4개의 좋아요

This is very deja vu. It’s basically the original spec for our backup/restore, which didn’t work because it broke whenever the db schema changed. We need to limit the scope of what it means to export a user, user action, topic, post, etc. otherwise this tool will become impossible to maintain.

2개의 좋아요

The tool is described here:

4개의 좋아요