move to 2.5.5
[anni] / docs / configuration / howto_database_config.md
1 # How to activate Pleroma in-database configuration
2 ## Explanation
3
4 The configuration of 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.
5
6 ## Migration to database config
7
8 1. Run the mix task to migrate to the database.
9
10   **Source:**
11
12   ```
13   $ mix pleroma.config migrate_to_db
14   ```
15
16   or
17
18   **OTP:**
19
20   *Note: OTP users need Pleroma to be running for `pleroma_ctl` commands to work*
21
22   ```
23   $ ./bin/pleroma_ctl config migrate_to_db
24   ```
25
26   ```
27     Migrating settings from file: /home/pleroma/config/dev.secret.exs
28
29    Settings for key instance migrated.
30    Settings for group :pleroma migrated.
31   ```
32
33 2. It is recommended to backup your config file now.
34
35   ```
36   cp config/dev.secret.exs config/dev.secret.exs.orig
37   ```
38
39 3. Edit your Pleroma config to enable database configuration:
40
41   ```
42   config :pleroma, configurable_from_database: true
43   ```
44
45 4. ⚠️ **THIS IS NOT REQUIRED** ⚠️
46
47   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.
48
49   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.
50
51   A non-exhaustive list of settings that are only possible in the config file include the following:
52
53   * config :pleroma, Pleroma.Web.Endpoint
54   * config :pleroma, Pleroma.Repo
55   * config :pleroma, configurable\_from\_database
56   * config :pleroma, :database, rum_enabled
57   * config :pleroma, :connections_pool
58
59   Here is an example of a server config stripped down after migration:
60
61   ```
62   import Config
63
64   config :pleroma, Pleroma.Web.Endpoint,
65     url: [host: "cool.pleroma.site", scheme: "https", port: 443]
66
67   config :pleroma, Pleroma.Repo,
68     adapter: Ecto.Adapters.Postgres,
69     username: "pleroma",
70     password: "MySecretPassword",
71     database: "pleroma_prod",
72     hostname: "localhost"
73
74   config :pleroma, configurable_from_database: true
75   ```
76
77 5. Restart your instance and you can now access the Settings tab in AdminFE.
78
79
80 ## Reverting back from database config
81
82 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.
83
84   **Source:**
85
86   ```
87   $ mix pleroma.config migrate_from_db
88   ```
89
90   or
91
92   **OTP:**
93
94   ```
95   $ ./bin/pleroma_ctl config migrate_from_db
96   ```
97
98   ```
99   10:26:30.593 [debug] QUERY OK source="config" db=9.8ms decode=1.2ms queue=26.0ms idle=0.0ms
100   SELECT c0."id", c0."key", c0."group", c0."value", c0."inserted_at", c0."updated_at" FROM "config" AS c0 []
101
102   10:26:30.659 [debug] QUERY OK source="config" db=1.1ms idle=80.7ms
103   SELECT c0."id", c0."key", c0."group", c0."value", c0."inserted_at", c0."updated_at" FROM "config" AS c0 []
104   Database configuration settings have been saved to config/dev.exported_from_db.secret.exs
105   ```
106
107 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.
108
109 3. Restart your instance.
110
111 ## Debugging
112
113 ### Clearing database config
114 You can clear the database config with the following command:
115
116   **Source:**
117
118   ```
119   $ mix pleroma.config reset
120   ```
121
122   or
123
124   **OTP:**
125
126   ```
127   $ ./bin/pleroma_ctl config reset
128   ```
129
130 Additionally, every time you migrate the configuration to the database the config table is automatically truncated to ensure a clean migration.
131
132 ### Manually removing a setting
133 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.
134
135 e.g., here is an example showing a the removal of the `config :pleroma, :instance` settings:
136
137   **Source:**
138
139   ```
140   $ mix pleroma.config delete pleroma instance
141   Are you sure you want to continue? [n]  y
142   config :pleroma, :instance deleted from the ConfigDB.
143   ```
144
145   or
146
147   **OTP:**
148
149   ```
150   $ ./bin/pleroma_ctl config delete pleroma instance
151   Are you sure you want to continue? [n]  y
152   config :pleroma, :instance deleted from the ConfigDB.
153   ```
154
155 Now the `config :pleroma, :instance` settings have been removed from the database.