[PR #79] [MERGED] feat: add support for Postgres database provider #956

Closed
opened 2025-10-08 00:20:26 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/pocket-id/pocket-id/pull/79
Author: @stonith404
Created: 12/12/2024
Status: Merged
Merged: 12/12/2024
Merged by: @stonith404

Base: mainHead: feat/postgres-support


📝 Commits (6)

  • 7132bf1 add Postgres support
  • a5f49d6 add db provider docs
  • 157e941 test both sqlite and postgres in e2e tests
  • 62e5266 add step to wait for database in e2e tests
  • b707fb8 fix caddy ambiguous config file format error
  • dcbd2ad remove postgres database name requirement

📊 Changes

38 files changed (+432 additions, -80 deletions)

View changed files

.env.test (+0 -2)
📝 .github/workflows/e2e-tests.yml (+108 -7)
📝 README.md (+15 -13)
📝 backend/.env.example (+3 -1)
📝 backend/go.mod (+7 -1)
📝 backend/go.sum (+54 -2)
📝 backend/internal/bootstrap/db_bootstrap.go (+33 -10)
📝 backend/internal/common/env_config.go (+41 -18)
📝 backend/internal/controller/webauthn_controller.go (+1 -3)
📝 backend/internal/model/types/date_time.go (+6 -1)
📝 backend/internal/model/user.go (+1 -1)
📝 backend/internal/model/webauthn.go (+3 -2)
📝 backend/internal/service/test_service.go (+23 -7)
📝 backend/internal/service/webauthn_service.go (+7 -10)
backend/migrations/postgres/20241211111554_init.up.sql (+126 -0)
📝 backend/migrations/sqlite/20240731203656_init.up.sql (+0 -0)
📝 backend/migrations/sqlite/20240813211251_passkey_backup_flags..up.sql (+0 -0)
📝 backend/migrations/sqlite/20240813211251_passkey_backup_flags.down.sql (+0 -0)
📝 backend/migrations/sqlite/20240817191051_rename_config_table.down.sql (+0 -0)
📝 backend/migrations/sqlite/20240817191051_rename_config_table.up.sql (+0 -0)

...and 18 more files

📄 Description

With this PR it is now possible to use Postgres instead of Sqlite as the database provider.

The following environment variables were added that allows the admin to configure the database provider:

Variable Default Value Description
DB_PROVIDER sqlite The database provider you want to use. Currently sqlite and postgres are supported.
SQLITE_DB_PATH data/pocket-id.db The path to the SQLite database. This gets ignored if you didn't set DB_PROVIDER to sqlite.
POSTGRES_CONNECTION_STRING - The connection string to your Postgres database. This gets ignored if you didn't set DB_PROVIDER to postgres. A connection string can look like this: postgresql://user:password@host:5432/pocket-id.

This PR can be tested with the stonith404/pocket-id:postgres-development Docker image.


🔄 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/pocket-id/pocket-id/pull/79 **Author:** [@stonith404](https://github.com/stonith404) **Created:** 12/12/2024 **Status:** ✅ Merged **Merged:** 12/12/2024 **Merged by:** [@stonith404](https://github.com/stonith404) **Base:** `main` ← **Head:** `feat/postgres-support` --- ### 📝 Commits (6) - [`7132bf1`](https://github.com/pocket-id/pocket-id/commit/7132bf11289320c6df8f745ead5cc9bfe8d3ae42) add Postgres support - [`a5f49d6`](https://github.com/pocket-id/pocket-id/commit/a5f49d65e93e1e37ae8b2cf29956589c7c7e98cd) add db provider docs - [`157e941`](https://github.com/pocket-id/pocket-id/commit/157e941c3b8b4267d24c5933761a6a087d5947e1) test both sqlite and postgres in e2e tests - [`62e5266`](https://github.com/pocket-id/pocket-id/commit/62e52668752d7cb8eab3fcc88d3d858820aab83e) add step to wait for database in e2e tests - [`b707fb8`](https://github.com/pocket-id/pocket-id/commit/b707fb8b0f8084076e110bda9ed9ff1d8f644f06) fix caddy ambiguous config file format error - [`dcbd2ad`](https://github.com/pocket-id/pocket-id/commit/dcbd2adcd6a6bad419f120f79bdd1ccd7a2f029b) remove postgres database name requirement ### 📊 Changes **38 files changed** (+432 additions, -80 deletions) <details> <summary>View changed files</summary> ➖ `.env.test` (+0 -2) 📝 `.github/workflows/e2e-tests.yml` (+108 -7) 📝 `README.md` (+15 -13) 📝 `backend/.env.example` (+3 -1) 📝 `backend/go.mod` (+7 -1) 📝 `backend/go.sum` (+54 -2) 📝 `backend/internal/bootstrap/db_bootstrap.go` (+33 -10) 📝 `backend/internal/common/env_config.go` (+41 -18) 📝 `backend/internal/controller/webauthn_controller.go` (+1 -3) 📝 `backend/internal/model/types/date_time.go` (+6 -1) 📝 `backend/internal/model/user.go` (+1 -1) 📝 `backend/internal/model/webauthn.go` (+3 -2) 📝 `backend/internal/service/test_service.go` (+23 -7) 📝 `backend/internal/service/webauthn_service.go` (+7 -10) ➕ `backend/migrations/postgres/20241211111554_init.up.sql` (+126 -0) 📝 `backend/migrations/sqlite/20240731203656_init.up.sql` (+0 -0) 📝 `backend/migrations/sqlite/20240813211251_passkey_backup_flags..up.sql` (+0 -0) 📝 `backend/migrations/sqlite/20240813211251_passkey_backup_flags.down.sql` (+0 -0) 📝 `backend/migrations/sqlite/20240817191051_rename_config_table.down.sql` (+0 -0) 📝 `backend/migrations/sqlite/20240817191051_rename_config_table.up.sql` (+0 -0) _...and 18 more files_ </details> ### 📄 Description With this PR it is now possible to use Postgres instead of Sqlite as the database provider. The following environment variables were added that allows the admin to configure the database provider: | Variable | Default Value | Description | | ---------------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `DB_PROVIDER` | `sqlite` | The database provider you want to use. Currently `sqlite` and `postgres` are supported. | | `SQLITE_DB_PATH` | `data/pocket-id.db` | The path to the SQLite database. This gets ignored if you didn't set `DB_PROVIDER` to `sqlite`. | | `POSTGRES_CONNECTION_STRING` | `-` | The connection string to your Postgres database. This gets ignored if you didn't set `DB_PROVIDER` to `postgres`. A connection string can look like this: `postgresql://user:password@host:5432/pocket-id`. | This PR can be tested with the `stonith404/pocket-id:postgres-development` Docker image. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2025-10-08 00:20:26 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pocket-id-pocket-id-1#956