Skip to content

Feature/eng 39 multi schema foundation#21

Merged
sreenandpk merged 4 commits into
developfrom
feature/ENG-39-Multi-Schema-Foundation
Jul 19, 2026
Merged

Feature/eng 39 multi schema foundation#21
sreenandpk merged 4 commits into
developfrom
feature/ENG-39-Multi-Schema-Foundation

Conversation

@sreenandpk

@sreenandpk sreenandpk commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Implemented the enterprise multi-schema database foundation.

Changes

  • Created enterprise PostgreSQL schemas
  • Enabled Alembic multi-schema support
  • Migrated authentication models to the auth schema
  • Updated foreign keys to use schema-qualified references
  • Migrated user_role enum to the auth schema
  • Updated test infrastructure for schema-aware models
  • Preserved existing authentication data during migration

Validation

  • All migrations executed successfully
  • Verified tables moved to the auth schema
  • Verified enum moved to the auth schema
  • 175 tests passing
  • Coverage: 81.28%

Breaking Changes

None.

Summary by CodeRabbit

  • New Features
    • Added support for organizing authentication data within a dedicated database schema.
    • Added database schemas for key enterprise platform areas, including market, risk, analytics, audit, and system operations.
  • Documentation
    • Added an architecture plan outlining the platform’s multi-schema structure.
  • Bug Fixes
    • Updated authentication relationships and token handling to work correctly with the new schema layout.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: af53b631-bfc7-4a38-9ea1-75db81200754

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ENG-39-Multi-Schema-Foundation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/ai_trading_discipline_copilot/models/user.py (1)

67-71: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer inherit_schema=True for schema-bound enums.

Instead of hardcoding schema="auth", you can use inherit_schema=True. This allows the Enum to automatically inherit the schema defined in __table_args__, reducing duplication and preventing mismatches if the table is ever moved to another schema.

♻️ Proposed refactor
         Enum(
             UserRole,
             name="user_role",
-            schema="auth",
+            inherit_schema=True,
         ),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ai_trading_discipline_copilot/models/user.py` around lines 67 - 71,
Update the Enum declaration in the User model to use inherit_schema=True instead
of hardcoding schema="auth", allowing it to inherit the schema from
__table_args__ while preserving the existing user_role name and UserRole type.
alembic/env.py (1)

42-42: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider filtering schemas to avoid noisy autogenerations.

Enabling include_schemas=True correctly allows Alembic to track your multi-schema setup. However, it also causes Alembic to reflect all schemas in the database. If your database eventually uses external extensions (like PostGIS) that create their own schemas or tables, Alembic may generate unintended migrations to drop them.

As the project grows, consider implementing an include_name function in context.configure() to restrict Alembic's scope strictly to your application schemas.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@alembic/env.py` at line 42, Add an include_name filter to the
context.configure() call near include_schemas=True so Alembic reflects only the
application’s intended schemas and objects, excluding external extension schemas
such as PostGIS. Preserve multi-schema tracking while preventing autogenerate
from proposing changes to unrelated database objects.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/fixtures/database.py`:
- Around line 47-50: Update the database setup around Base.metadata.create_all
to restore Base.metadata.drop_all for cleaning all managed tables, then create
every required enterprise schema (including auth, market, and risk) before
running create_all. Avoid hardcoding only the auth schema so public tables are
reset and all model schemas exist.

---

Nitpick comments:
In `@alembic/env.py`:
- Line 42: Add an include_name filter to the context.configure() call near
include_schemas=True so Alembic reflects only the application’s intended schemas
and objects, excluding external extension schemas such as PostGIS. Preserve
multi-schema tracking while preventing autogenerate from proposing changes to
unrelated database objects.

In `@src/ai_trading_discipline_copilot/models/user.py`:
- Around line 67-71: Update the Enum declaration in the User model to use
inherit_schema=True instead of hardcoding schema="auth", allowing it to inherit
the schema from __table_args__ while preserving the existing user_role name and
UserRole type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 442bdd8b-5fa9-4332-b2f3-5d08f16c3ed6

📥 Commits

Reviewing files that changed from the base of the PR and between 3c002e2 and da2206e.

📒 Files selected for processing (9)
  • alembic/env.py
  • alembic/versions/021805c35a4a_create_enterprise_schemas.py
  • alembic/versions/13a89530c1d2_move_auth_tables_to_auth_schema.py
  • docs/architecture/multi-schema-plan.md
  • src/ai_trading_discipline_copilot/models/email_verification_token.py
  • src/ai_trading_discipline_copilot/models/password_reset_token.py
  • src/ai_trading_discipline_copilot/models/refresh_token.py
  • src/ai_trading_discipline_copilot/models/user.py
  • tests/fixtures/database.py

Comment thread tests/fixtures/database.py Outdated
@sreenandpk
sreenandpk merged commit 44d94fb into develop Jul 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant