2022-07-03 09:21:21 -06:00
# How to activate Akkoma in-database configuration
2020-07-12 09:38:07 -06:00
## Explanation
2022-07-03 09:21:21 -06:00
The configuration of Akkoma (and Pleroma) has traditionally been managed with a config file, e.g. `config/prod.secret.exs` . This method requires a restart of the application for any configuration changes to take effect. We have made it possible to control most settings in the AdminFE interface after running a migration script.
2020-07-12 09:38:07 -06:00
## Migration to database config
2020-11-28 11:09:17 -07:00
1. Run the mix task to migrate to the database.
2020-07-12 09:38:07 -06:00
2020-07-13 08:56:05 -06:00
**Source:**
2020-11-28 10:53:45 -07:00
2020-07-12 09:38:07 -06:00
```
$ mix pleroma.config migrate_to_db
2020-07-13 08:56:05 -06:00
```
2020-11-28 10:53:45 -07:00
2020-07-13 08:56:05 -06:00
or
2020-11-28 10:53:45 -07:00
2020-07-13 08:56:05 -06:00
**OTP:**
2020-11-28 10:53:45 -07:00
2022-07-03 09:21:21 -06:00
*Note: OTP users need Akkoma to be running for `pleroma_ctl` commands to work*
2020-11-28 10:53:45 -07:00
2020-07-13 08:56:05 -06:00
```
$ ./bin/pleroma_ctl config migrate_to_db
```
2020-07-30 11:01:46 -06:00
```
Migrating settings from file: /home/pleroma/config/dev.secret.exs
2020-11-28 10:53:45 -07:00
2020-07-30 11:01:46 -06:00
Settings for key instance migrated.
Settings for group :pleroma migrated.
2020-07-12 09:38:07 -06:00
```
2020-11-28 10:53:45 -07:00
2020-07-30 11:37:56 -06:00
2. It is recommended to backup your config file now.
2020-07-30 12:04:49 -06:00
2020-07-12 09:38:07 -06:00
```
cp config/dev.secret.exs config/dev.secret.exs.orig
```
2020-11-28 10:53:45 -07:00
2022-07-03 09:21:21 -06:00
3. Edit your Akkoma config to enable database configuration:
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
```
config :pleroma, configurable_from_database: true
```
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
4. ⚠️ **THIS IS NOT REQUIRED** ⚠️
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
Now you can edit your config file and strip it down to the only settings which are not possible to control in the database. e.g., the Postgres (Repo) and webserver (Endpoint) settings cannot be controlled in the database because the application needs the settings to start up and access the database.
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
Any settings in the database will override those in the config file, but you may find it less confusing if the setting is only declared in one place.
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
A non-exhaustive list of settings that are only possible in the config file include the following:
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
* config :pleroma, Pleroma.Web.Endpoint
* config :pleroma, Pleroma.Repo
* config :pleroma, configurable\_from\_database
* config :pleroma, :database, rum_enabled
* config :pleroma, :connections_pool
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
Here is an example of a server config stripped down after migration:
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
```
use Mix.Config
2020-07-12 09:38:07 -06:00
2020-07-30 11:37:56 -06:00
config :pleroma, Pleroma.Web.Endpoint,
url: [host: "cool.pleroma.site", scheme: "https", port: 443]
2020-11-28 10:53:45 -07:00
2020-07-30 11:37:56 -06:00
config :pleroma, Pleroma.Repo,
adapter: Ecto.Adapters.Postgres,
2022-07-03 09:21:21 -06:00
username: "akkoma",
2020-07-30 11:37:56 -06:00
password: "MySecretPassword",
2022-07-03 09:21:21 -06:00
database: "akkoma_prod",
2020-07-30 11:37:56 -06:00
hostname: "localhost"
2020-11-28 10:53:45 -07:00
2020-07-30 11:37:56 -06:00
config :pleroma, configurable_from_database: true
```
2020-11-28 10:53:45 -07:00
2020-07-30 12:04:49 -06:00
5. Restart your instance and you can now access the Settings tab in AdminFE.
2020-07-12 09:38:07 -06:00
## Reverting back from database config
2020-07-30 12:04:49 -06:00
1. Run the mix task to migrate back from the database. You'll receive some debugging output and a few messages informing you of what happened.
2020-07-12 09:38:07 -06:00
2020-07-13 08:56:05 -06:00
**Source:**
2020-11-28 10:53:45 -07:00
2020-07-12 09:38:07 -06:00
```
$ mix pleroma.config migrate_from_db
2020-07-13 08:56:05 -06:00
```
2020-11-28 10:53:45 -07:00
2020-07-13 08:56:05 -06:00
or
2020-11-28 10:53:45 -07:00
2020-07-13 08:56:05 -06:00
**OTP:**
2020-11-28 10:53:45 -07:00
2020-07-13 08:56:05 -06:00
```
$ ./bin/pleroma_ctl config migrate_from_db
```
2020-07-12 09:38:07 -06:00
2020-07-13 08:56:05 -06:00
```
2020-07-12 09:38:07 -06:00
10:26:30.593 [debug] QUERY OK source="config" db=9.8ms decode=1.2ms queue=26.0ms idle=0.0ms
2020-07-30 11:01:46 -06:00
SELECT c0."id", c0."key", c0."group", c0."value", c0."inserted_at", c0."updated_at" FROM "config" AS c0 []
2020-11-28 10:53:45 -07:00
2020-07-12 09:38:07 -06:00
10:26:30.659 [debug] QUERY OK source="config" db=1.1ms idle=80.7ms
2020-07-30 11:01:46 -06:00
SELECT c0."id", c0."key", c0."group", c0."value", c0."inserted_at", c0."updated_at" FROM "config" AS c0 []
Database configuration settings have been saved to config/dev.exported_from_db.secret.exs
```
2020-07-12 09:38:07 -06:00
2020-07-30 12:04:49 -06:00
2. Remove `config :pleroma, configurable_from_database: true` from your config. The in-database configuration still exists, but it will not be used. Future migrations will erase the database config before importing your config file again.
2020-07-12 09:38:07 -06:00
2020-07-30 12:04:49 -06:00
3. Restart your instance.
2020-07-12 09:38:07 -06:00
## Debugging
### Clearing database config
2020-11-28 10:53:45 -07:00
You can clear the database config with the following command:
2020-07-12 09:38:07 -06:00
2020-11-28 10:53:45 -07:00
**Source:**
```
$ mix pleroma.config reset
```
or
**OTP:**
```
$ ./bin/pleroma_ctl config reset
```
2020-07-12 09:38:07 -06:00
Additionally, every time you migrate the configuration to the database the config table is automatically truncated to ensure a clean migration.
### Manually removing a setting
If you encounter a situation where the server cannot run properly because of an invalid setting in the database and this is preventing you from accessing AdminFE, you can manually remove the offending setting if you know which one it is.
2020-11-28 10:53:45 -07:00
e.g., here is an example showing a the removal of the `config :pleroma, :instance` settings:
2020-07-12 09:38:07 -06:00
2020-11-28 10:53:45 -07:00
**Source:**
2020-11-25 16:31:44 -07:00
2020-11-28 10:53:45 -07:00
```
$ mix pleroma.config delete pleroma instance
Are you sure you want to continue? [n] y
config :pleroma, :instance deleted from the ConfigDB.
```
2020-11-25 16:31:44 -07:00
2020-11-28 10:53:45 -07:00
or
2020-11-25 16:31:44 -07:00
2020-11-28 10:53:45 -07:00
**OTP:**
2020-11-25 16:31:44 -07:00
2020-11-28 10:53:45 -07:00
```
$ ./bin/pleroma_ctl config delete pleroma instance
Are you sure you want to continue? [n] y
config :pleroma, :instance deleted from the ConfigDB.
```
2020-07-12 09:38:07 -06:00
2020-07-12 09:43:24 -06:00
Now the `config :pleroma, :instance` settings have been removed from the database.