# Adding default sets of topics, categories and users to a new Discourse

**URL:** https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733
**Category:** Development
**Created:** [18 april 2016 om 16:47 UTC](https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733 "2016-04-18T16:47:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [18 april 2016 om 16:47 UTC](https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733/1 "2016-04-18T16:47:39Z")

</div>

I have another university professor interested in using Discourse as a tool to run online classes. I would like to have a means to create an initial Discourse database with a set of sample categories and topics. For example,

- each course will have a set of categories/subcategories with appropriate permissions;
- there need to be additional topics in the Staff category about how to organize things
- Badges for submitting assignments and getting instructor approval
- I want to tweak the language in some of the default staff posts for people who don’t know what system administration is

I think that perhaps the easiest/best way to do this is to set up a fresh install, set stuff up like I want it, and back that up. Those who want to use my system would do a fresh install and restore my database. Does that sound right? Is there some other way? Might I want to do this as a template instead and use `db/fixtures/999_topics.rb` as a model?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [18 april 2016 om 18:53 UTC](https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733/2 "2016-04-18T18:53:00Z")

</div>

I just noticed that there is a [topic and category import/export](https://meta.discourse.org/t/topic-and-category-export-import/38930) command line tool. This solves half my problem, as I can now put all of my customizations in a LMS category and export:

> [@Move topics from one Discourse instance to another](https://meta.discourse.org/t/move-topics-from-one-discourse-instance-to-another/38930/1):
>
> the category  
> all its subcategories  
> its security settings  
> custom groups mentioned in the security settings  
> all topics and posts in the category and subcategories  
> all users who posted, and assigns them to the groups

This will make it easy/possible to include the exported JSON file with my set of scripts that support creating badges for assignments and so on.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [18 april 2016 om 19:00 UTC](https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733/3 "2016-04-18T19:00:17Z")

</div>

A similar badge export/import tool would probably be very handy too.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [18 april 2016 om 19:03 UTC](https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733/4 "2016-04-18T19:03:25Z")

</div>

Indeed it might. For now I have created a Python script that creates sets of badges (bronze, silver, gold for people who post in a certain category with a given tag). My target audience probably won’t be likely to be popping into a shell and running rails commands, though.

---

<div class="post-metadata">

### Author: ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)
#### Post date: [18 april 2016 om 19:34 UTC](https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733/5 "2016-04-18T19:34:52Z")

</div>

> [@pfaffman](#):
>
> I think that perhaps the easiest/best way to do this is to set up a fresh install, set stuff up like I want it, and back that up. Those who want to use my system would do a fresh install and restore my database.

In this way, you lose the time axis. Your default topic may looks out of date.

> [@pfaffman](#):
>
> each course will have a set of categories/subcategories with appropriate permissions;  
> there need to be additional topics in the Staff category about how to organize things  
> Badges for submitting assignments and getting instructor approval  
> I want to tweak the language in some of the default staff posts for people who don’t know what system administration is

I guess your case is highly **customized** given different time. But the previous data doesn’t need to change since they will be archived just like Moodle.

I would suggest two ways:

- If your data doesn’t evolved rapidly and it can be deduced from default site settings, you can go with a plugin. In this plugin, several `seed_data` can be registered (it’s the way to override admin start guide for plugin authors) as well as a lib task. Later on, you invoked this lib task.
- While the previous may not be that customizable, you can however make use of a rake task. Visiting a HTTP url (securely), downloading and commit all changes. Basically everything you can do in the console can be done by rake task.

It’s been quite easy to invoke the rake task for Discourse Docker. Running `rake` in custom commands and you are good to go. In both case, you have to protect the rake task running twice which might fit your case. This can be achieved by a timestamp parameter. (Well, I don’t have an good idea now)

Besides, you have every rights to generate an admin API by `rake apikey:get` and use it whatever you want. Though you still need to use custom commands to trigger the rake task and collect it (securely).

Basically, depends on what you need to do 🙂

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [18 april 2016 om 19:39 UTC](https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733/6 "2016-04-18T19:39:02Z")

</div>

> [@fantasticfears](#):
>
> In this plugin, several seed\_data can be registered (it’s the way to override admin start guide for plugin authors) as well as a lib task. Later on, you invoked this lib task.

That sounds like what I need to do. I’ll poke through some plugins and look for an example of `seed_data`. I don’t remember seeing that in the plugin guides, but that may be because I wasn’t looking. 🙂

Thanks!

---

<div class="post-metadata">

### Author: ![fantasticfears](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fantasticfears/32/119608_2.png) [@fantasticfears](https://meta.discourse.org/u/fantasticfears)
#### Post date: [18 april 2016 om 19:48 UTC](https://meta.discourse.org/t/adding-default-sets-of-topics-categories-and-users-to-a-new-discourse/42733/7 "2016-04-18T19:48:32Z")

</div>

Sorry, I checked the `seed_data` which is a plain hash and only used for overriding the admin starter guide. It’s not really useful in your case.

But a rake task is still worthing considered but you have to prevent it from running twice (maybe define a site setting for checking this). In this way, you would end up with a configurable ruby script as your need/create.

Task `db.rake` may be a good start.
