Skip to content

Commit 345661f

Browse files
authored
Roles: db migration to make role_name not nullable (#7697)
* Roles: db migration to make role_name not nullable Depends on #7689, fixes #7688 * lint
1 parent a511197 commit 345661f

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

tests/unit/malware/checks/package_turnover/test_check.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from .....common.db.accounts import UserFactory
2323
from .....common.db.malware import MalwareCheckFactory
24-
from .....common.db.packaging import ProjectFactory, ReleaseFactory
24+
from .....common.db.packaging import ProjectFactory, ReleaseFactory, RoleFactory
2525

2626

2727
def test_initializes(db_session):
@@ -90,7 +90,8 @@ def test_user_posture_verdicts_has_2fa(db_session):
9090

9191
def test_user_turnover_verdicts(db_session):
9292
user = UserFactory.create()
93-
project = ProjectFactory.create(users=[user])
93+
project = ProjectFactory.create()
94+
RoleFactory.create(user=user, project=project, role_name="Owner")
9495

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

118119
def test_user_turnover_verdicts_no_turnover(db_session):
119120
user = UserFactory.create()
120-
project = ProjectFactory.create(users=[user])
121+
project = ProjectFactory.create()
122+
RoleFactory.create(user=user, project=project, role_name="Owner")
121123

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

131133
def test_scan(db_session, monkeypatch):
132134
user = UserFactory.create()
133-
project = ProjectFactory.create(users=[user])
135+
project = ProjectFactory.create()
136+
RoleFactory.create(user=user, project=project, role_name="Owner")
134137

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

158161
def test_scan_too_few_releases(db_session, monkeypatch):
159162
user = UserFactory.create()
160-
project = ProjectFactory.create(users=[user])
163+
project = ProjectFactory.create()
164+
RoleFactory.create(user=user, project=project, role_name="Owner")
161165
ReleaseFactory.create(project=project)
162166

163167
MalwareCheckFactory.create(
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
"""
13+
Role.role_name should not be nullable
14+
15+
Revision ID: 6af76ffb9612
16+
Revises: aaa60e8ea12e
17+
Create Date: 2020-03-28 01:20:30.453875
18+
"""
19+
20+
import sqlalchemy as sa
21+
22+
from alembic import op
23+
24+
revision = "6af76ffb9612"
25+
down_revision = "aaa60e8ea12e"
26+
27+
28+
def upgrade():
29+
op.alter_column("roles", "role_name", existing_type=sa.TEXT(), nullable=False)
30+
31+
32+
def downgrade():
33+
op.alter_column("roles", "role_name", existing_type=sa.TEXT(), nullable=True)

warehouse/packaging/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Role(db.Model):
6464

6565
__repr__ = make_repr("role_name")
6666

67-
role_name = Column(Text)
67+
role_name = Column(Text, nullable=False)
6868
user_id = Column(
6969
ForeignKey("users.id", onupdate="CASCADE", ondelete="CASCADE"), nullable=False
7070
)

0 commit comments

Comments
 (0)