From 249120dc64c3d3de2985b7796f955abcf616125f Mon Sep 17 00:00:00 2001 From: Jan K <66259190+KBurgTech@users.noreply.github.com> Date: Tue, 22 Mar 2022 16:54:29 +0100 Subject: [PATCH] Added documentation on how to migrate from MySQL to PostgreSQL --- Using-the-PostgreSQL-Backend.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Using-the-PostgreSQL-Backend.md b/Using-the-PostgreSQL-Backend.md index cc3148a..7ff5387 100644 --- a/Using-the-PostgreSQL-Backend.md +++ b/Using-the-PostgreSQL-Backend.md @@ -51,3 +51,36 @@ load database ``` 8. run the command ```pgloader bitwarden.load``` and you might see some warnings, but the migration should complete successfully 9. Start vaultwarden again. + +## Migrating from MySQL to PostgreSQL +> Tested with MariaDB 10.3.32, PostgreSQL 14.2 and Vaultwarden 1.24.0 + + +Please, note that you **are using this at your own risk and you are strongly advised to backup your installation and data!**. This is **unsupported** and has not been robustly tested. + +1. Create a new (empty) database for vaultwarden: +```sql +CREATE DATABASE vaultwarden; +``` +2. Create a new database user and grant rights to database: +```sql +CREATE USER vaultwarden WITH ENCRYPTED PASSWORD 'yourpassword'; +GRANT all privileges ON database vaultwarden TO vaultwarden; +``` +3. Configure vaultwarden and start it, so diesel can run migrations and set up the schema properly. Do not do anything else. +4. Stop vaultwarden. +5. Install [pgloader](http://pgloader.io/). Make sure that you have the latest version of pgloader, the official Ubuntu repository has an outdated version which does not work well with newer versions of PostgreSQL. The newest version can be obtained from the [PostgreSQL Apt Repository](https://www.postgresql.org/download/linux/ubuntu/) +6. Create the file `vaultwarden.load ` with the following content: +``` +load database + from mysql://yourmysqluser:yourmysqlpassword@yourmysqlserver:yourmysqlport/yourmysqldatabase + into postgresql://yourpgsqluser:yourpgsqlpassword@yourpgsqlserver:yourpgsqlport/yourpgsqldatabase + WITH data only + EXCLUDING TABLE NAMES MATCHING '__diesel_schema_migrations' + ALTER SCHEMA 'vaultwarden' RENAME TO 'public' +; +``` +_Optionally add `?sslmode=require` to the PostgreSQL connection string if your connection requires SSL_ + +7. Run the command ```pgloader vaultwarden.load``` and you might see some warnings, but the migration should complete successfully. If there are errors, it is likely that you have an outdated version of pgloader! +8. Start vaultwarden again \ No newline at end of file