-
Notifications
You must be signed in to change notification settings - Fork 10
Generate API Key per Project Instead of per organisation #215
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8eb8b87
modified api key to function as per project
avirajsingh7 f2863bf
fix seed script
avirajsingh7 2d6338c
fix pre-commit formatting
avirajsingh7 82d53f1
add unit tests for validate project function
avirajsingh7 215c92c
api key per (project and user)
avirajsingh7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
backend/app/alembic/versions/60b6c511a485_add_project_id_in_api_key_table.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Add project_id in api_key table | ||
|
|
||
| Revision ID: 60b6c511a485 | ||
| Revises: 904ed70e7dab | ||
| Create Date: 2025-06-10 13:22:59.947971 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| from sqlmodel import text | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "60b6c511a485" | ||
| down_revision = "904ed70e7dab" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column("apikey", sa.Column("project_id", sa.Integer(), nullable=True)) | ||
| op.create_foreign_key( | ||
| None, "apikey", "project", ["project_id"], ["id"], ondelete="CASCADE" | ||
| ) | ||
|
|
||
| # 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 | ||
| ) | ||
| """ | ||
| ) | ||
| ) | ||
|
|
||
| # 4. Alter column to be NOT NULL now that it’s populated | ||
| op.alter_column("apikey", "project_id", nullable=False) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_constraint(None, "apikey", type_="foreignkey") | ||
| op.drop_column("apikey", "project_id") | ||
| # ### end Alembic commands ### | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
as this will be one time thing we can run it manually in production server and remove from migration
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.
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.