Skip to content

[Chore] Migrate shared/database/ to penguin-dal #67

@PenguinzTech

Description

@PenguinzTech

User Story

As a maintainer, I want to replace the dual PyDAL+SQLAlchemy database pattern with penguin-dal so that schema is defined once and the codebase follows penguin-libs standards.

Background

Elder currently uses a custom shared/database/ module (~4 files) implementing:

  • init_db(app) — PyDAL initialization with migrate=False
  • init_sqlalchemy_tables(app) — SQLAlchemy create_all()
  • get_database_url(app) — URL normalization (postgresql:// vs postgres://)
  • DatabaseManager — Read/write splitting with replica support
  • create_db_connection() — Factory with retry logic
  • ensure_database_ready() — Startup connectivity check

penguin-dal (pip install penguin-dal) replaces the entire dual-library pattern:

  • Single table definition (no separate SQLAlchemy models + PyDAL define_table calls)
  • Built-in connection pooling, multi-DB, async support
  • Flask integration via init_dal() / get_db()
  • PyDAL-identical query syntax

Per database.md: "Migrate at the next major version bump — not mid-release."

Acceptance Criteria

  • penguin-dal replaces PyDAL + SQLAlchemy dual pattern
  • All table definitions consolidated (single source of truth)
  • shared/database/ module removed or reduced to Elder-specific wrappers
  • Read/write splitting preserved (DatabaseManager equivalent)
  • All existing API endpoints work without query changes
  • migrate=False equivalent enforced (Alembic still manages migrations)
  • Tests pass (unit + integration)
  • Linting passes
  • Security scan passes

Notes

  • This is the highest-effort migration item — database layer changes carry significant risk
  • Requires penguin-dal to be stable (currently v0.1.0)
  • Must test all 4 supported databases: PostgreSQL, MySQL, MariaDB Galera, SQLite
  • shared/models/pydal_models.py table definitions will need rewriting

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions