Skip to content

Conversation

@avirajsingh7
Copy link
Collaborator

Summary

Target issue is #203

Currently, API keys are generated based on a combination of organization_id and user_id. This PR updates the logic to generate API keys using organization_id, project_id, and user_id—with the primary association being to the project.

Key Changes:

  • Modified the API key model to include project_id.
  • Updated API key creation logic to require both organization_id and project_id.
  • Adjusted related endpoints, seed data, and tests to reflect the new structure.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Please add here if any other information is required for the reviewer.

@codecov
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 98.16514% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/api/routes/api_keys.py 75.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@avirajsingh7 avirajsingh7 marked this pull request as draft June 11, 2025 04:55
@avirajsingh7 avirajsingh7 force-pushed the feat/api_key_per_project branch from abe51fd to 8eb8b87 Compare June 11, 2025 05:50
@avirajsingh7 avirajsingh7 marked this pull request as ready for review June 11, 2025 06:20
@avirajsingh7 avirajsingh7 added enhancement New feature or request ready-for-review labels Jun 13, 2025
Comment on lines +26 to +44

# 2. Bind engine to run raw SQL
conn = op.get_bind()

# 3. Populate project_id based on default logic (e.g., min project id per org)
conn.execute(
text(
"""
UPDATE apikey
SET project_id = (
SELECT id FROM project
WHERE project.organization_id = apikey.organization_id
ORDER BY id ASC
LIMIT 1
)
"""
)
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

as this will be one time thing we can run it manually in production server and remove from migration

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

need to set a NOT NULL constraint on the project_id column.
To do that, I first populated the column with appropriate values to avoid constraint violations.

@AkhileshNegi AkhileshNegi merged commit d6d5ead into main Jun 13, 2025
2 checks passed
@AkhileshNegi AkhileshNegi deleted the feat/api_key_per_project branch June 13, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants