Skip to content

Simplify rx.session and reflex db CLI #6245

@masenf

Description

@masenf

Simplify the database session management and CLI tooling to delegate to standard SQLAlchemy/Alembic rather than wrapping them.

rx.session Changes

  • Becomes a thin context manager over sqlalchemy.orm.Session
  • Configured via REFLEX_DB_URL environment variable (or [tool.reflex] config)
  • No custom session subclass, no framework-specific session logic
  • Supports both sync and async sessions via standard SQLAlchemy APIs

reflex db CLI Changes

  • reflex db init → generates a standard alembic.ini and alembic/ directory, pre-configured with REFLEX_DB_URL
  • reflex db makemigrations → delegates to alembic revision --autogenerate
  • reflex db migrate → delegates to alembic upgrade head
  • No custom migration/autogenerate logic — standard Alembic handles everything
  • Users who outgrow the convenience wrapper can use alembic directly with zero friction

Motivation

The current implementation wraps Alembic with custom logic that occasionally diverges from standard behavior, creating confusion for users familiar with Alembic. By delegating to standard tooling, we reduce maintenance burden and make the Reflex database experience identical to the broader Python ecosystem.

Tracking

Parent: ENG-9181 (Database & ORM Standardization)
Roadmap: #2727 — Section 5

Metadata

Metadata

Assignees

No one assigned

    Labels

    roadmaphttps://github.com/reflex-dev/reflex/issues/2727

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions