[PR #486] [CLOSED] [WIP/RFC] MySQL / MariaDB database backend support #2610

Closed
opened 2025-11-07 07:48:24 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/dani-garcia/vaultwarden/pull/486
Author: @Skeen
Created: 5/20/2019
Status: Closed

Base: masterHead: master


📝 Commits (9)

  • 42af7c6 MySQL database
  • 85c8a01 Merge branch 'master' of github.com:Skeen/bitwarden_rs
  • ab95a69 Rework migrations for MySQL
  • e22e290 Fix key and type variable names for mysql
  • 233b48b Fix missing joinable in schema
  • eb9d5e1 Reintroduce .env.template
  • 5fb6531 Attempt to fix azure pipeline
  • 6f78395 Passwordless sudo on azure?
  • badd22a Make docker image build

📊 Changes

29 files changed (+199 additions, -210 deletions)

View changed files

📝 Cargo.lock (+12 -13)
📝 Cargo.toml (+2 -5)
📝 Dockerfile (+6 -0)
📝 azure-pipelines.yml (+5 -0)
📝 migrations/2018-01-14-171611_create_tables/up.sql (+16 -16)
📝 migrations/2018-02-17-205753_create_collections_and_orgs/up.sql (+10 -11)
📝 migrations/2018-04-27-155151_create_users_ciphers/up.sql (+8 -8)
📝 migrations/2018-05-08-161616_create_collection_cipher_map/up.sql (+3 -3)
📝 migrations/2018-05-25-232323_update_attachments_reference/up.sql (+3 -3)
📝 migrations/2018-07-11-181453_create_u2f_twofactor/up.sql (+7 -7)
📝 migrations/2018-09-10-111213_add_invites/up.sql (+2 -2)
📝 migrations/2018-11-27-152651_add_att_key_columns/up.sql (+1 -1)
📝 src/api/core/accounts.rs (+5 -5)
📝 src/api/core/ciphers.rs (+3 -3)
📝 src/api/core/mod.rs (+1 -1)
📝 src/api/core/organizations.rs (+14 -14)
📝 src/api/identity.rs (+4 -4)
📝 src/auth.rs (+1 -1)
📝 src/config.rs (+2 -1)
📝 src/db/mod.rs (+6 -4)

...and 9 more files

📄 Description

Hello,

This PR introduces support for MySQL as database backend (and in the current state, completely breaks support for SQLite in the process), thus resolving #208. MySQL was chosen due to diesel::replace_into support, as noted as a requirement here: #87.

The changes are mainly:

  • Replacing SQLite* with mysql*
  • Reworking migrations to name key to akey and type to atype (key and type are reserved keywords in MySQL).
  • Reworking migrations to use VARCHAR(40) instead of TEXT for UUIDs (MySQL cannot use TEXT as keys, as it only (as far as I know) indexes up to 255 characters).

The PR can be tested out, by starting a mysql docker container:

docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=bitwarden -p 3306:3306 -d mysql:5.7

or a mariadb docker container:

docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=bitwarden -p 3306:3306 -d mariadb:10.3

And building the project via cargo run, althrough we now need the libmysql++-dev debian package.

Now for the questions:

  1. Are these changes welcome?
  • I imagine changes to migration files could be a big issue for current installations.
  • The naming akey and atype is up for discussion, I just wanted to avoid the conflicts.
  1. How do we peserve sqlite support while supporting mysql?
  • The connection import + type alias in db/mod.rs will have to be dynamic and configuration dependent.
  • If we combine support for both in one image, it will be larger than the pure sqlite3 one.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/dani-garcia/vaultwarden/pull/486 **Author:** [@Skeen](https://github.com/Skeen) **Created:** 5/20/2019 **Status:** ❌ Closed **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (9) - [`42af7c6`](https://github.com/dani-garcia/vaultwarden/commit/42af7c6dab113388a0db4fae0c196bae14761bc1) MySQL database - [`85c8a01`](https://github.com/dani-garcia/vaultwarden/commit/85c8a01f4a0f51efb2432396743878477529b72f) Merge branch 'master' of github.com:Skeen/bitwarden_rs - [`ab95a69`](https://github.com/dani-garcia/vaultwarden/commit/ab95a69dc8be20401bcc3167c51fb5f8b99ed2a2) Rework migrations for MySQL - [`e22e290`](https://github.com/dani-garcia/vaultwarden/commit/e22e290f677c01354446bf784287114696f2eeaa) Fix key and type variable names for mysql - [`233b48b`](https://github.com/dani-garcia/vaultwarden/commit/233b48bdad8d5c9571831a40dd8b7d6cb0e6f280) Fix missing joinable in schema - [`eb9d5e1`](https://github.com/dani-garcia/vaultwarden/commit/eb9d5e1196840a45a11329e46911c1db7ce7a496) Reintroduce .env.template - [`5fb6531`](https://github.com/dani-garcia/vaultwarden/commit/5fb6531db869ae395f1ac08695023d0dd27879d0) Attempt to fix azure pipeline - [`6f78395`](https://github.com/dani-garcia/vaultwarden/commit/6f78395ef71bd037fff24aeb60318c109294971a) Passwordless sudo on azure? - [`badd22a`](https://github.com/dani-garcia/vaultwarden/commit/badd22ac3d1b6c364c7be59e64ec0c48f2b960dd) Make docker image build ### 📊 Changes **29 files changed** (+199 additions, -210 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+12 -13) 📝 `Cargo.toml` (+2 -5) 📝 `Dockerfile` (+6 -0) 📝 `azure-pipelines.yml` (+5 -0) 📝 `migrations/2018-01-14-171611_create_tables/up.sql` (+16 -16) 📝 `migrations/2018-02-17-205753_create_collections_and_orgs/up.sql` (+10 -11) 📝 `migrations/2018-04-27-155151_create_users_ciphers/up.sql` (+8 -8) 📝 `migrations/2018-05-08-161616_create_collection_cipher_map/up.sql` (+3 -3) 📝 `migrations/2018-05-25-232323_update_attachments_reference/up.sql` (+3 -3) 📝 `migrations/2018-07-11-181453_create_u2f_twofactor/up.sql` (+7 -7) 📝 `migrations/2018-09-10-111213_add_invites/up.sql` (+2 -2) 📝 `migrations/2018-11-27-152651_add_att_key_columns/up.sql` (+1 -1) 📝 `src/api/core/accounts.rs` (+5 -5) 📝 `src/api/core/ciphers.rs` (+3 -3) 📝 `src/api/core/mod.rs` (+1 -1) 📝 `src/api/core/organizations.rs` (+14 -14) 📝 `src/api/identity.rs` (+4 -4) 📝 `src/auth.rs` (+1 -1) 📝 `src/config.rs` (+2 -1) 📝 `src/db/mod.rs` (+6 -4) _...and 9 more files_ </details> ### 📄 Description Hello, This PR introduces support for MySQL as database backend (and in the current state, completely breaks support for SQLite in the process), thus resolving #208. MySQL was chosen due to [diesel::replace_into ](https://docs.rs/diesel/1.2.2/diesel/fn.replace_into.html) support, as noted as a requirement here: #87. The changes are mainly: * Replacing SQLite* with mysql* * Reworking migrations to name `key` to `akey` and `type` to `atype` (`key` and `type` are reserved keywords in MySQL). * Reworking migrations to use `VARCHAR(40)` instead of `TEXT` for UUIDs (MySQL cannot use `TEXT` as keys, as it only (as far as I know) indexes up to 255 characters). The PR can be tested out, by starting a mysql docker container: ``` docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=bitwarden -p 3306:3306 -d mysql:5.7 ``` or a mariadb docker container: ``` docker run --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=bitwarden -p 3306:3306 -d mariadb:10.3 ``` And building the project via `cargo run`, althrough we now need the `libmysql++-dev` debian package. Now for the questions: 1. Are these changes welcome? - I imagine changes to migration files could be a big issue for current installations. - The naming `akey` and `atype` is up for discussion, I just wanted to avoid the conflicts. 2. How do we peserve sqlite support while supporting mysql? - The connection import + type alias in `db/mod.rs` will have to be dynamic and configuration dependent. - If we combine support for both in one image, it will be larger than the pure sqlite3 one. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-07 07:48:24 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vaultwarden#2610