logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

howto_database_config.md (4702B)


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