-
Notifications
You must be signed in to change notification settings - Fork 986
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
warehouse: add initial pending OIDC provider models #12572
Merged
di
merged 5 commits into
pypi:main
from
trail-of-forks:tob-pending-oidc-provider-models
Nov 21, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6261b76
warehouse: add initial pending OIDC provider models
woodruffw 66b5631
oidc/models: unused imports
woodruffw d18dbbc
oidc/models: blacken
woodruffw 1756410
Merge branch 'main' into tob-pending-oidc-provider-models
woodruffw ef67edd
oidc/models: promote discriminator to base mixin
woodruffw 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
This file contains 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
80 changes: 80 additions & 0 deletions
80
warehouse/migrations/versions/aa3a4757f33a_add_pending_oidc_provider_hierarchy.py
This file contains 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,80 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
add pending OIDC provider hierarchy | ||
|
||
Revision ID: aa3a4757f33a | ||
Revises: 43bf0b6badcb | ||
Create Date: 2022-11-18 22:19:55.133681 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
revision = "aa3a4757f33a" | ||
down_revision = "43bf0b6badcb" | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
"pending_oidc_providers", | ||
sa.Column( | ||
"id", | ||
postgresql.UUID(as_uuid=True), | ||
server_default=sa.text("gen_random_uuid()"), | ||
nullable=False, | ||
), | ||
sa.Column("discriminator", sa.String(), nullable=True), | ||
sa.Column("project_name", sa.String(), nullable=False), | ||
sa.Column("added_by_id", postgresql.UUID(as_uuid=True), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["added_by_id"], | ||
["users.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_index( | ||
op.f("ix_pending_oidc_providers_added_by_id"), | ||
"pending_oidc_providers", | ||
["added_by_id"], | ||
unique=False, | ||
) | ||
op.create_table( | ||
"pending_github_oidc_providers", | ||
sa.Column("repository_name", sa.String(), nullable=True), | ||
sa.Column("repository_owner", sa.String(), nullable=True), | ||
sa.Column("repository_owner_id", sa.String(), nullable=True), | ||
sa.Column("workflow_filename", sa.String(), nullable=True), | ||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["id"], | ||
["pending_oidc_providers.id"], | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
sa.UniqueConstraint( | ||
"repository_name", | ||
"repository_owner", | ||
"workflow_filename", | ||
name="_pending_github_oidc_provider_uc", | ||
), | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table("pending_github_oidc_providers") | ||
op.drop_index( | ||
op.f("ix_pending_oidc_providers_added_by_id"), | ||
table_name="pending_oidc_providers", | ||
) | ||
op.drop_table("pending_oidc_providers") |
This file contains 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
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.
Flagging for review: I had to dupe this
UniqueConstraint
betweenGitHubProvider
andPendingGitHubProvider
, even though they're functionally equivalent, thanks to the uniquename
requirement. There might be a better way to do this, though.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.
I think this is due to not having set any naming_conventions for this project in the global metadata setup
warehouse/warehouse/db.py
Line 77 in d58e6b2
Alembic docs go into it here: https://alembic.sqlalchemy.org/en/latest/naming.html
I think we always named them manually, like here:
warehouse/warehouse/accounts/models.py
Line 197 in d58e6b2
So it might be a future refactoring to replace the manually-named constraints, but I’d approach that with some serious caution 😉