[PR #863] [MERGED] fix: enable foreign key check for sqlite #574

Closed
opened 2025-10-07 00:18:46 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/pocket-id/pocket-id/pull/863
Author: @stonith404
Created: 8/22/2025
Status: Merged
Merged: 8/23/2025
Merged by: @stonith404

Base: mainHead: fix/foreign-keys


📝 Commits (7)

📊 Changes

10 files changed (+545 additions, -48 deletions)

View changed files

📝 backend/internal/bootstrap/db_bootstrap.go (+138 -9)
📝 backend/internal/bootstrap/db_bootstrap_test.go (+216 -31)
📝 backend/internal/common/env_config.go (+1 -1)
📝 backend/internal/model/oidc.go (+2 -2)
📝 backend/internal/service/e2etest_service.go (+4 -4)
📝 backend/internal/service/oidc_service.go (+1 -1)
backend/resources/migrations/postgres/20250822000000_foreign_keys_improvements.down.sql (+1 -0)
backend/resources/migrations/postgres/20250822000000_foreign_keys_improvements.up.sql (+8 -0)
backend/resources/migrations/sqlite/20250822000000_foreign_keys_improvements.down.sql (+1 -0)
backend/resources/migrations/sqlite/20250822000000_foreign_keys_improvements.up.sql (+173 -0)

📄 Description

By default Sqlite doesn't enforce foreign key checks which can lead to orphan rows in the database and confusing behavior. This changes the default connection string of Sqlite so that the connections enforce foreign key checks.

For this change I have added a migration, that cleans all potential orphan rows, adds missing foreign keys and brings the ON DELETE behavior of Postgres and Sqlite in sync.


🔄 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/863 **Author:** [@stonith404](https://github.com/stonith404) **Created:** 8/22/2025 **Status:** ✅ Merged **Merged:** 8/23/2025 **Merged by:** [@stonith404](https://github.com/stonith404) **Base:** `main` ← **Head:** `fix/foreign-keys` --- ### 📝 Commits (7) - [`86dc5a5`](https://github.com/pocket-id/pocket-id/commit/86dc5a5ed2f474a529b7db412614c524332c2efe) enable foreign key checks in sqlite - [`de4b6b6`](https://github.com/pocket-id/pocket-id/commit/de4b6b644567948366a23b9fc9d119cc623f5c49) add missing foreign keys and adapt sync postgres foreign key constraints - [`e58c5ae`](https://github.com/pocket-id/pocket-id/commit/e58c5ae3234b2857f29ad4f1dd82142295e6c9da) use pointers for user id - [`7404c0f`](https://github.com/pocket-id/pocket-id/commit/7404c0f23b5c93d3e4743486acc4c3e504d9c06b) Merge branch 'main' into fix/foreign-keys - [`cae81d8`](https://github.com/pocket-id/pocket-id/commit/cae81d87a7e7b508bec43f3468d36c4b9d0fac53) Parse the SQLite connection string to set default options - [`aac2573`](https://github.com/pocket-id/pocket-id/commit/aac2573ded809f96516b85d1c5d707e6e801f621) Apply suggestion from @ItalyPaleAle - [`f355a7f`](https://github.com/pocket-id/pocket-id/commit/f355a7fb89668d75193103d3e464d7568a963355) Merge branch 'main' of https://github.com/pocket-id/pocket-id into fix/foreign-keys ### 📊 Changes **10 files changed** (+545 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `backend/internal/bootstrap/db_bootstrap.go` (+138 -9) 📝 `backend/internal/bootstrap/db_bootstrap_test.go` (+216 -31) 📝 `backend/internal/common/env_config.go` (+1 -1) 📝 `backend/internal/model/oidc.go` (+2 -2) 📝 `backend/internal/service/e2etest_service.go` (+4 -4) 📝 `backend/internal/service/oidc_service.go` (+1 -1) ➕ `backend/resources/migrations/postgres/20250822000000_foreign_keys_improvements.down.sql` (+1 -0) ➕ `backend/resources/migrations/postgres/20250822000000_foreign_keys_improvements.up.sql` (+8 -0) ➕ `backend/resources/migrations/sqlite/20250822000000_foreign_keys_improvements.down.sql` (+1 -0) ➕ `backend/resources/migrations/sqlite/20250822000000_foreign_keys_improvements.up.sql` (+173 -0) </details> ### 📄 Description By default Sqlite doesn't enforce foreign key checks which can lead to orphan rows in the database and confusing behavior. This changes the default connection string of Sqlite so that the connections enforce foreign key checks. For this change I have added a migration, that cleans all potential orphan rows, adds missing foreign keys and brings the `ON DELETE` behavior of Postgres and Sqlite in sync. --- <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-07 00:18:46 +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#574