How to use the database without destroying Discourse?

AI-generated summary

In the Dev category, Silvanus proposes creating a “bookquote” plugin to replace citation tags (e.g., [us-constitution 1.1]) with full text from the U.S. Constitution. As a scholar with limited coding experience, Silvanus asks whether to use the existing Discourse database or an external storage method like a file, specifically seeking advice on how to avoid disrupting Discourse’s operations. zogstrip initially suggests that since the plugin replaces post content, no new storage area is strictly necessary. However, Falco clarifies that the user is asking where to store the constitution data itself. Falco advises against creating new tables in the Discourse database schema, warning that it would compromise backups. Instead, Falco recommends using the built-in PluginStore to save the data on the first run. When Silvanus asks for documentation on the PluginStore, Falco provides links to the source code of the discourse-staff-notes and discourse-canned-replies plugins as practical examples of implementation.

I’m thinking of starting to make a plugin (working title: bookquote) that would replace citations from database and replace the citation in the message, for example [us-constitution 1.1] would give out All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives. (U.S. Constitution, I.1).

I’m not really a coder, I’m a humanist scholar myself, but I have some rudimentary knowledge of coding, postgresql, git, and I’m a really good in copy&paste. Nerd youth…

My first question is: can I use the same database that Discourse uses to store the data, or should I use some other kind of storage i.e. a file? If I can use the database, how do I do that so that I don’t destroy anything that Discourse is trying to do?

Since you’ll be replacing the content of the posts, you don’t need a new storage area :wink:

I think he’s talking about where to put the constitution. You can either:

  • Put it in another database, and handle creating the connection, etc.

  • Use the built-in PluginStore, save everything on first run, and then use it.

Please don’t create a table inside Discourse database/schema. Your backups will be screwed.

Where can I find more info on this?

See examples on the source code of some plugins: