Skip to content

Roles: db migration to make role_name not nullable #7697

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 2 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions tests/unit/malware/checks/package_turnover/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from .....common.db.accounts import UserFactory
from .....common.db.malware import MalwareCheckFactory
from .....common.db.packaging import ProjectFactory, ReleaseFactory
from .....common.db.packaging import ProjectFactory, ReleaseFactory, RoleFactory


def test_initializes(db_session):
Expand Down Expand Up @@ -90,7 +90,8 @@ def test_user_posture_verdicts_has_2fa(db_session):

def test_user_turnover_verdicts(db_session):
user = UserFactory.create()
project = ProjectFactory.create(users=[user])
project = ProjectFactory.create()
RoleFactory.create(user=user, project=project, role_name="Owner")

project.record_event(
tag="project:role:add",
Expand All @@ -117,7 +118,8 @@ def test_user_turnover_verdicts(db_session):

def test_user_turnover_verdicts_no_turnover(db_session):
user = UserFactory.create()
project = ProjectFactory.create(users=[user])
project = ProjectFactory.create()
RoleFactory.create(user=user, project=project, role_name="Owner")

MalwareCheckFactory.create(
name="PackageTurnoverCheck", state=MalwareCheckState.Enabled,
Expand All @@ -130,7 +132,8 @@ def test_user_turnover_verdicts_no_turnover(db_session):

def test_scan(db_session, monkeypatch):
user = UserFactory.create()
project = ProjectFactory.create(users=[user])
project = ProjectFactory.create()
RoleFactory.create(user=user, project=project, role_name="Owner")

for _ in range(3):
ReleaseFactory.create(project=project)
Expand All @@ -157,7 +160,8 @@ def test_scan(db_session, monkeypatch):

def test_scan_too_few_releases(db_session, monkeypatch):
user = UserFactory.create()
project = ProjectFactory.create(users=[user])
project = ProjectFactory.create()
RoleFactory.create(user=user, project=project, role_name="Owner")
ReleaseFactory.create(project=project)

MalwareCheckFactory.create(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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.
"""
Role.role_name should not be nullable

Revision ID: 6af76ffb9612
Revises: aaa60e8ea12e
Create Date: 2020-03-28 01:20:30.453875
"""

import sqlalchemy as sa

from alembic import op

revision = "6af76ffb9612"
down_revision = "aaa60e8ea12e"


def upgrade():
op.alter_column("roles", "role_name", existing_type=sa.TEXT(), nullable=False)


def downgrade():
op.alter_column("roles", "role_name", existing_type=sa.TEXT(), nullable=True)
2 changes: 1 addition & 1 deletion warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Role(db.Model):

__repr__ = make_repr("role_name")

role_name = Column(Text)
role_name = Column(Text, nullable=False)
user_id = Column(
ForeignKey("users.id", onupdate="CASCADE", ondelete="CASCADE"), nullable=False
)
Expand Down