-
Notifications
You must be signed in to change notification settings - Fork 10
chore: improve DB structure #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: chore/add_native_client_to_tests
Are you sure you want to change the base?
chore: improve DB structure #164
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a major refactoring of the authentication and user management system, transitioning from a database-driven user model to a credential validation middleware pattern. Key changes include renaming userid to user_id throughout the codebase, integrating nilauth-credit-middleware for credential validation, restructuring the database schema to remove user-specific token tracking, and introducing a new QueryLogContext dependency pattern for improved request logging.
- Integrates
nilauth-credit-middlewarev0.1.2 for centralized credential validation - Refactors database schema: renames
useridtouser_id, removes user token counters, adds query log telemetry fields - Introduces
QueryLogContextas a FastAPI dependency for better request lifecycle tracking - Updates rate limiting to use
user_idinstead ofsubscription_holder - Removes subscription owner checks from prompt delegation endpoint
Reviewed Changes
Copilot reviewed 29 out of 32 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Updates dependencies: nilauth-credit-middleware 0.1.1→0.1.2, secretvaults source changed |
| nilai-api/src/nilai_api/db/users.py | Simplifies UserModel to only user_id and rate_limits; removes token tracking methods |
| nilai-api/src/nilai_api/db/logs.py | Adds QueryLogContext for request lifecycle logging; adds telemetry columns to QueryLog |
| nilai-api/src/nilai_api/auth/strategies.py | Integrates validate_credential function using nilauth-credit-middleware |
| nilai-api/src/nilai_api/routers/private.py | Adds QueryLogContext dependency; improves error handling and logging |
| nilai-api/src/nilai_api/rate_limiting.py | Renames subscription_holder to user_id; removes wait_for_bucket method |
| tests/* | Updates all tests to use user_id instead of userid |
| nilai-api/alembic/versions/*.py | Database migration scripts for schema changes |
| grafana/runtime-data/dashboards/*.json | Updates Grafana queries to use user_id column |
Comments suppressed due to low confidence (2)
tests/integration/nilai_api/test_users_db_integration.py:1
- The test attempts to access
user.nameanduser.apikeyattributes, but these fields were removed from the UserModel. This test will fail with AttributeError. The assertions should be updated to reflect the new UserModel schema that only contains user_id and rate_limits.
"""
nilai-api/src/nilai_api/config/init.py:67
- Print statement may execute during import.
print(CONFIG.prettify())
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ] | ||
|
|
||
| logging.info(CONFIG.prettify()) | ||
| print(CONFIG.prettify()) |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a print statement for configuration output is problematic in production code. This will clutter logs and should be removed or made conditional based on environment/debug settings.
| print(CONFIG.prettify()) |
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "0ba073468afc" |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variable 'revision' is not used.
| revision: str = "0ba073468afc" | ||
| down_revision: Union[str, None] = "9ddf28cf6b6f" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variable 'depends_on' is not used.
| depends_on: Union[str, Sequence[str], None] = None |
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "43b23c73035b" |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variable 'revision' is not used.
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "43b23c73035b" | ||
| down_revision: Union[str, None] = "0ba073468afc" |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variable 'down_revision' is not used.
| # revision identifiers, used by Alembic. | ||
| revision: str = "43b23c73035b" | ||
| down_revision: Union[str, None] = "0ba073468afc" | ||
| branch_labels: Union[str, Sequence[str], None] = None |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variable 'branch_labels' is not used.
| branch_labels: Union[str, Sequence[str], None] = None |
| revision: str = "43b23c73035b" | ||
| down_revision: Union[str, None] = "0ba073468afc" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None |
Copilot
AI
Nov 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variable 'depends_on' is not used.
| depends_on: Union[str, Sequence[str], None] = None |
8b6ce65 to
dd374dd
Compare
bfa83b9 to
fabf9fd
Compare
Pull Request Overview
This PR implements a major refactoring of the authentication and user management system, transitioning from a database-driven user model to a credential validation middleware pattern. Key changes include renaming
useridtouser_idthroughout the codebase, integratingnilauth-credit-middlewarefor credential validation, restructuring the database schema to remove user-specific token tracking, and introducing a newQueryLogContextdependency pattern for improved request logging.nilauth-credit-middlewarev0.1.2 for centralized credential validationuseridtouser_id, removes user token counters, adds query log telemetry fieldsQueryLogContextas a FastAPI dependency for better request lifecycle trackinguser_idinstead ofsubscription_holder