[PR #323] [MERGED] Migrate OAuth token storage to PostgreSQL #290

Closed
opened 2026-03-02 23:34:59 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/323
Author: @AJaySi
Created: 2/9/2026
Status: Merged
Merged: 2/9/2026
Merged by: @AJaySi

Base: mainHead: codex/migrate-oauth-token-storage-to-postgresql


📝 Commits (1)

  • 6dc7d2b Migrate OAuth tokens to PostgreSQL

📊 Changes

14 files changed (+1355 additions, -1035 deletions)

View changed files

📝 backend/api/wix_routes.py (+1 -2)
backend/models/oauth_token_models.py (+150 -0)
📝 backend/routers/bing_oauth.py (+31 -29)
📝 backend/routers/gsc_auth.py (+14 -12)
📝 backend/services/database.py (+6 -0)
📝 backend/services/gsc_service.py (+183 -158)
📝 backend/services/integrations/bing_oauth.py (+264 -222)
📝 backend/services/integrations/wix_oauth.py (+182 -157)
📝 backend/services/integrations/wordpress_oauth.py (+180 -163)
📝 backend/services/integrations/wordpress_publisher.py (+111 -88)
📝 backend/services/integrations/wordpress_service.py (+141 -131)
📝 backend/services/oauth_token_monitoring_service.py (+16 -14)
📝 backend/services/scheduler/executors/gsc_insights_executor.py (+23 -37)
📝 backend/services/scheduler/executors/oauth_token_monitoring_executor.py (+53 -22)

📄 Description

Motivation

  • Centralize OAuth tokens and related integration data in the platform PostgreSQL SSOT instead of local SQLite files to support the dual-database clean architecture and connection pooling.
  • Replace ad-hoc alwrity.db/sqlite3 reads and writes with SQLAlchemy models and sessions so monitoring and onboarding use the same platform DB.
  • Ensure monitoring executors and insight tasks read tokens from PostgreSQL so automated refresh/check logic uses the SSOT.

Description

  • Added a new SQLAlchemy model module backend/models/oauth_token_models.py containing GSC, Bing, WordPress, Wix token/state models plus WordPress wordpress_sites/wordpress_posts models and caching rows.
  • Wired the new models into database initialization by importing OAuthTokenBase in backend/services/database.py and creating platform tables via SQLAlchemy metadata.
  • Migrated services to use SQLAlchemy sessions: GSCService, BingOAuthService, WordPressOAuthService, WixOAuthService, WordPressService, and WordPressPublisher now accept an optional db_session and use get_platform_db_session() and the new models for reads/writes, with session cleanup when the service created its own session.
  • Updated monitoring and executor code to use the PostgreSQL-backed services and token checks: get_connected_platforms in backend/services/oauth_token_monitoring_service.py, oauth_token_monitoring_executor.py, and gsc_insights_executor.py now rely on SQLAlchemy-backed lookups and GscDataCache where applicable, and routers (backend/routers/gsc_auth.py, backend/routers/bing_oauth.py, backend/api/wix_routes.py) were adjusted to stop referencing alwrity.db.

Testing

  • No automated tests were executed as part of this change set; changes were applied and committed but integration/unit tests were not run in this rollout.

Codex Task


🔄 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/AJaySi/ALwrity/pull/323 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 2/9/2026 **Status:** ✅ Merged **Merged:** 2/9/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/migrate-oauth-token-storage-to-postgresql` --- ### 📝 Commits (1) - [`6dc7d2b`](https://github.com/AJaySi/ALwrity/commit/6dc7d2bb835f7be7bb354282ce2a336335694c81) Migrate OAuth tokens to PostgreSQL ### 📊 Changes **14 files changed** (+1355 additions, -1035 deletions) <details> <summary>View changed files</summary> 📝 `backend/api/wix_routes.py` (+1 -2) ➕ `backend/models/oauth_token_models.py` (+150 -0) 📝 `backend/routers/bing_oauth.py` (+31 -29) 📝 `backend/routers/gsc_auth.py` (+14 -12) 📝 `backend/services/database.py` (+6 -0) 📝 `backend/services/gsc_service.py` (+183 -158) 📝 `backend/services/integrations/bing_oauth.py` (+264 -222) 📝 `backend/services/integrations/wix_oauth.py` (+182 -157) 📝 `backend/services/integrations/wordpress_oauth.py` (+180 -163) 📝 `backend/services/integrations/wordpress_publisher.py` (+111 -88) 📝 `backend/services/integrations/wordpress_service.py` (+141 -131) 📝 `backend/services/oauth_token_monitoring_service.py` (+16 -14) 📝 `backend/services/scheduler/executors/gsc_insights_executor.py` (+23 -37) 📝 `backend/services/scheduler/executors/oauth_token_monitoring_executor.py` (+53 -22) </details> ### 📄 Description ### Motivation - Centralize OAuth tokens and related integration data in the platform PostgreSQL SSOT instead of local SQLite files to support the dual-database clean architecture and connection pooling. - Replace ad-hoc `alwrity.db`/`sqlite3` reads and writes with SQLAlchemy models and sessions so monitoring and onboarding use the same platform DB. - Ensure monitoring executors and insight tasks read tokens from PostgreSQL so automated refresh/check logic uses the SSOT. ### Description - Added a new SQLAlchemy model module `backend/models/oauth_token_models.py` containing GSC, Bing, WordPress, Wix token/state models plus WordPress `wordpress_sites`/`wordpress_posts` models and caching rows. - Wired the new models into database initialization by importing `OAuthTokenBase` in `backend/services/database.py` and creating platform tables via SQLAlchemy metadata. - Migrated services to use SQLAlchemy sessions: `GSCService`, `BingOAuthService`, `WordPressOAuthService`, `WixOAuthService`, `WordPressService`, and `WordPressPublisher` now accept an optional `db_session` and use `get_platform_db_session()` and the new models for reads/writes, with session cleanup when the service created its own session. - Updated monitoring and executor code to use the PostgreSQL-backed services and token checks: `get_connected_platforms` in `backend/services/oauth_token_monitoring_service.py`, `oauth_token_monitoring_executor.py`, and `gsc_insights_executor.py` now rely on SQLAlchemy-backed lookups and `GscDataCache` where applicable, and routers (`backend/routers/gsc_auth.py`, `backend/routers/bing_oauth.py`, `backend/api/wix_routes.py`) were adjusted to stop referencing `alwrity.db`. ### Testing - No automated tests were executed as part of this change set; changes were applied and committed but integration/unit tests were not run in this rollout. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_698975cd30588328a8d387cc81f92999) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:34:59 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#290
No description provided.