Skip to content

Commit b66d929

Browse files
authored
Cleanup a lot of legacy cruft from the database schema (pypi#4581)
* Remove the unused stable_version column * Remove Release._pypi_hidden * Remove Project.autohide * Remove Project.comments * Remove Project.bugtrack_url * Remove project.hosting_mode * Remove Release.description_from_readme * Remove File.downloads * Remove User.is_staff * Allow setting User.is_staff to null
1 parent 37e57e7 commit b66d929

File tree

14 files changed

+44
-206
lines changed

14 files changed

+44
-206
lines changed

tests/common/db/accounts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Meta:
2828
name = factory.fuzzy.FuzzyText(length=12)
2929
password = "!"
3030
is_active = True
31-
is_staff = False
3231
is_superuser = False
3332
date_joined = factory.fuzzy.FuzzyNaiveDateTime(
3433
datetime.datetime(2005, 1, 1), datetime.datetime(2010, 1, 1)

tests/unit/forklift/test_legacy.py

Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,152 +2903,6 @@ def test_fails_without_user(self, pyramid_config, pyramid_request):
29032903
"403 Invalid or non-existent authentication information."
29042904
)
29052905

2906-
def test_autohides_old_releases(self, pyramid_config, db_request):
2907-
pyramid_config.testing_securitypolicy(userid=1)
2908-
2909-
user = UserFactory.create()
2910-
EmailFactory.create(user=user)
2911-
project = ProjectFactory.create(autohide=True)
2912-
ReleaseFactory.create(project=project, version="0.5", _pypi_hidden=False)
2913-
RoleFactory.create(user=user, project=project)
2914-
2915-
db_request.db.add(Classifier(classifier="Environment :: Other Environment"))
2916-
db_request.db.add(Classifier(classifier="Programming Language :: Python"))
2917-
2918-
filename = "{}-{}.tar.gz".format(project.name, "1.0")
2919-
2920-
db_request.user = user
2921-
db_request.remote_addr = "10.10.10.20"
2922-
db_request.user_agent = "warehouse-tests/6.6.6"
2923-
db_request.POST = MultiDict(
2924-
{
2925-
"metadata_version": "1.2",
2926-
"name": project.name,
2927-
"version": "1.0",
2928-
"summary": "This is my summary!",
2929-
"filetype": "sdist",
2930-
"md5_digest": "335c476dc930b959dda9ec82bd65ef19",
2931-
"content": pretend.stub(
2932-
filename=filename,
2933-
file=io.BytesIO(b"A fake file."),
2934-
type="application/tar",
2935-
),
2936-
}
2937-
)
2938-
db_request.POST.extend(
2939-
[
2940-
("classifiers", "Environment :: Other Environment"),
2941-
("classifiers", "Programming Language :: Python"),
2942-
("requires_dist", "foo"),
2943-
("requires_dist", "bar (>1.0)"),
2944-
("project_urls", "Test, https://example.com/"),
2945-
("requires_external", "Cheese (>1.0)"),
2946-
("provides", "testing"),
2947-
]
2948-
)
2949-
2950-
storage_service = pretend.stub(store=lambda path, filepath, meta: None)
2951-
db_request.find_service = lambda svc, name=None: storage_service
2952-
2953-
resp = legacy.file_upload(db_request)
2954-
2955-
assert resp.status_code == 200
2956-
2957-
# Ensure that a Release object has been created and is not hidden.
2958-
release = (
2959-
db_request.db.query(Release)
2960-
.filter((Release.project == project) & (Release.version == "1.0"))
2961-
.one()
2962-
)
2963-
assert not release._pypi_hidden
2964-
2965-
# Ensure that all the old release objects are hidden.
2966-
other_releases = (
2967-
db_request.db.query(Release)
2968-
.filter((Release.project == project) & (Release.version != "1.0"))
2969-
.all()
2970-
)
2971-
assert len(other_releases)
2972-
for r in other_releases:
2973-
assert r._pypi_hidden
2974-
2975-
def test_doesnt_autohides_old_releases(self, pyramid_config, db_request):
2976-
pyramid_config.testing_securitypolicy(userid=1)
2977-
2978-
user = UserFactory.create()
2979-
EmailFactory.create(user=user)
2980-
project = ProjectFactory.create(autohide=False)
2981-
previous_releases = {
2982-
"0.5": ReleaseFactory.create(
2983-
project=project, version="0.5", _pypi_hidden=False
2984-
),
2985-
"0.75": ReleaseFactory.create(
2986-
project=project, version="0.75", _pypi_hidden=False
2987-
),
2988-
}
2989-
RoleFactory.create(user=user, project=project)
2990-
2991-
db_request.db.add(Classifier(classifier="Environment :: Other Environment"))
2992-
db_request.db.add(Classifier(classifier="Programming Language :: Python"))
2993-
2994-
filename = "{}-{}.tar.gz".format(project.name, "1.0")
2995-
2996-
db_request.user = user
2997-
db_request.remote_addr = "10.10.10.20"
2998-
db_request.user_agent = "warehouse-tests/6.6.6"
2999-
db_request.POST = MultiDict(
3000-
{
3001-
"metadata_version": "1.2",
3002-
"name": project.name,
3003-
"version": "1.0",
3004-
"summary": "This is my summary!",
3005-
"filetype": "sdist",
3006-
"md5_digest": "335c476dc930b959dda9ec82bd65ef19",
3007-
"content": pretend.stub(
3008-
filename=filename,
3009-
file=io.BytesIO(b"A fake file."),
3010-
type="application/tar",
3011-
),
3012-
}
3013-
)
3014-
db_request.POST.extend(
3015-
[
3016-
("classifiers", "Environment :: Other Environment"),
3017-
("classifiers", "Programming Language :: Python"),
3018-
("requires_dist", "foo"),
3019-
("requires_dist", "bar (>1.0)"),
3020-
("project_urls", "Test, https://example.com/"),
3021-
("requires_external", "Cheese (>1.0)"),
3022-
("provides", "testing"),
3023-
]
3024-
)
3025-
3026-
storage_service = pretend.stub(store=lambda path, filepath, meta: None)
3027-
db_request.find_service = lambda svc, name=None: storage_service
3028-
3029-
resp = legacy.file_upload(db_request)
3030-
3031-
assert resp.status_code == 200
3032-
3033-
# Ensure that a Release object has been created and is not hidden.
3034-
release = (
3035-
db_request.db.query(Release)
3036-
.filter((Release.project == project) & (Release.version == "1.0"))
3037-
.one()
3038-
)
3039-
assert not release._pypi_hidden
3040-
3041-
# Ensure that all the old release objects still have the same hidden
3042-
# state.
3043-
other_releases = (
3044-
db_request.db.query(Release)
3045-
.filter((Release.project == project) & (Release.version != "1.0"))
3046-
.all()
3047-
)
3048-
assert len(other_releases)
3049-
for r in other_releases:
3050-
assert r._pypi_hidden == previous_releases[r.version]._pypi_hidden
3051-
30522906

30532907
@pytest.mark.parametrize("status", [True, False])
30542908
def test_legacy_purge(monkeypatch, status):

tests/unit/legacy/api/xmlrpc/test_xmlrpc.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,12 @@ def test_list_packages_with_serial(db_request):
460460

461461

462462
def test_package_hosting_mode_shows_none(db_request):
463-
assert xmlrpc.package_hosting_mode(db_request, "nope") is None
463+
assert xmlrpc.package_hosting_mode(db_request, "nope") == "pypi-only"
464464

465465

466466
def test_package_hosting_mode_results(db_request):
467-
project = ProjectFactory.create(hosting_mode="pypi-explicit")
468-
assert xmlrpc.package_hosting_mode(db_request, project.name) == "pypi-explicit"
467+
project = ProjectFactory.create()
468+
assert xmlrpc.package_hosting_mode(db_request, project.name) == "pypi-only"
469469

470470

471471
def test_user_packages(db_request):
@@ -592,8 +592,8 @@ def test_release_data(db_request):
592592
assert xmlrpc.release_data(db_request, project.name, release.version) == {
593593
"name": release.project.name,
594594
"version": release.version,
595-
"stable_version": release.project.stable_version,
596-
"bugtrack_url": release.project.bugtrack_url,
595+
"stable_version": None,
596+
"bugtrack_url": None,
597597
"package_url": urls[0],
598598
"release_url": urls[1],
599599
"docs_url": release.project.documentation_url,
@@ -619,7 +619,6 @@ def test_release_data(db_request):
619619
"requires_python": release.requires_python,
620620
"requires_external": list(release.requires_external),
621621
"_pypi_ordering": release._pypi_ordering,
622-
"_pypi_hidden": release._pypi_hidden,
623622
"downloads": {"last_day": -1, "last_week": -1, "last_month": -1},
624623
"cheesecake_code_kwalitee_id": None,
625624
"cheesecake_documentation_id": None,

warehouse/accounts/interfaces.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ def check_password(user_id, password, *, tags=None):
6666
checking the password.
6767
"""
6868

69-
def create_user(
70-
username, name, password, is_active=False, is_staff=False, is_superuser=False
71-
):
69+
def create_user(username, name, password, is_active=False, is_superuser=False):
7270
"""
7371
Accepts a user object, and attempts to create a user with those
7472
attributes.

warehouse/accounts/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class User(SitemapMixin, db.Model):
6969
password = Column(String(length=128), nullable=False)
7070
password_date = Column(DateTime, nullable=True, server_default=sql.func.now())
7171
is_active = Column(Boolean, nullable=False)
72-
is_staff = Column(Boolean, nullable=False)
7372
is_superuser = Column(Boolean, nullable=False)
7473
date_joined = Column(DateTime, server_default=sql.func.now())
7574
last_login = Column(DateTime, nullable=False, server_default=sql.func.now())

warehouse/accounts/services.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,14 @@ def check_password(self, userid, password, *, tags=None):
173173
return False
174174

175175
def create_user(
176-
self,
177-
username,
178-
name,
179-
password,
180-
is_active=False,
181-
is_staff=False,
182-
is_superuser=False,
176+
self, username, name, password, is_active=False, is_superuser=False
183177
):
184178

185179
user = User(
186180
username=username,
187181
name=name,
188182
password=self.hasher.hash(password),
189183
is_active=is_active,
190-
is_staff=is_staff,
191184
is_superuser=is_superuser,
192185
)
193186
self.db.add(user)

warehouse/admin/templates/admin/projects/detail.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,12 @@ <h3 class="project-name text-center">{{ project.name }}</h3>
8484
<table class="table table-hover">
8585
<th>Release version</th>
8686
<th>Created</th>
87-
<th>Hidden</th>
8887
<th>Uploader</th>
8988
<th>Author email</th>
9089
{% for release in releases %}
9190
<tr>
9291
<td><a href="{{ request.route_path('admin.project.release', project_name=release.project.normalized_name, version=release.version) }}">{{ release.name }}-{{ release.version }}</a></td>
9392
<td>{{ release.created }}</td>
94-
<td>{{ release._pypi_hidden }}</td>
9593
<td><a href="{{ request.route_path('admin.user.detail', user_id=release.uploader.id) }}">{{ release.uploader.username }}</a></td>
9694
<td>{{ release.author_email }}</td>
9795
</tr>

warehouse/admin/templates/admin/projects/release_detail.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ <h3>Details</h3>
3939
<td>Created</td>
4040
<td>{{ release.created }}</td>
4141
</tr>
42-
<tr>
43-
<td>Hidden</td>
44-
<td>{{ release._pypi_hidden }}</td>
45-
</tr>
4642
<tr>
4743
<td>Uploader</td>
4844
<td><a href="{{ request.route_path('admin.user.detail', user_id=release.uploader.id) }}">{{ release.uploader.username }}</a></td>

warehouse/admin/templates/admin/projects/releases_list.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
<tr>
4444
<th>Release version</th>
4545
<th>Created</th>
46-
<th>Hidden</th>
4746
<th>Uploader</th>
4847
<th>Author email</th>
4948
</tr>
@@ -52,7 +51,6 @@
5251
<tr>
5352
<td><a href="{{ request.route_path('admin.project.release', project_name=release.project.normalized_name, version=release.version) }}">{{ release.name }}-{{ release.version }}</a></td>
5453
<td>{{ release.created }}</td>
55-
<td>{{ release._pypi_hidden }}</td>
5654
<td><a href="{{ request.route_path('admin.user.detail', user_id=release.uploader.id) }}">{{ release.uploader.username }}</a></td>
5755
<td>{{ release.author_email }}</td>
5856
</tr>

warehouse/forklift/legacy.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,6 @@ def file_upload(request):
961961
_classifiers=[
962962
c for c in all_classifiers if c.classifier in form.classifiers.data
963963
],
964-
_pypi_hidden=False,
965964
dependencies=list(
966965
_construct_dependencies(
967966
form,
@@ -1021,20 +1020,14 @@ def file_upload(request):
10211020
releases = (
10221021
request.db.query(Release)
10231022
.filter(Release.project == project)
1024-
.options(orm.load_only(Release._pypi_ordering, Release._pypi_hidden))
1023+
.options(orm.load_only(Release._pypi_ordering))
10251024
.all()
10261025
)
10271026
for i, r in enumerate(
10281027
sorted(releases, key=lambda x: packaging.version.parse(x.version))
10291028
):
10301029
r._pypi_ordering = i
10311030

1032-
# TODO: Again, we should figure out a better solution to doing this than
1033-
# just inlining this inside this method.
1034-
if project.autohide:
1035-
for r in releases:
1036-
r._pypi_hidden = bool(not r == release)
1037-
10381031
# Pull the filename out of our POST data.
10391032
filename = request.POST["content"].filename
10401033

warehouse/legacy/api/json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def json_release(release, request):
172172
list(release.requires_dist) if release.requires_dist else None
173173
),
174174
"docs_url": project.documentation_url,
175-
"bugtrack_url": project.bugtrack_url,
175+
"bugtrack_url": None,
176176
"home_page": release.home_page,
177177
"download_url": release.download_url,
178178
},

warehouse/legacy/api/xmlrpc/views.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,7 @@ def list_packages_with_serial(request):
242242

243243
@xmlrpc_method(method="package_hosting_mode")
244244
def package_hosting_mode(request, package_name: str):
245-
try:
246-
project = (
247-
request.db.query(Project)
248-
.filter(Project.normalized_name == func.normalize_pep426_name(package_name))
249-
.one()
250-
)
251-
except NoResultFound:
252-
return None
253-
else:
254-
return project.hosting_mode
245+
return "pypi-only"
255246

256247

257248
@xmlrpc_method(method="user_packages")
@@ -332,8 +323,8 @@ def release_data(request, package_name: str, version: str):
332323
return {
333324
"name": release.project.name,
334325
"version": release.version,
335-
"stable_version": release.project.stable_version,
336-
"bugtrack_url": release.project.bugtrack_url,
326+
"stable_version": None,
327+
"bugtrack_url": None,
337328
"package_url": request.route_url(
338329
"packaging.project", name=release.project.name
339330
),
@@ -363,7 +354,6 @@ def release_data(request, package_name: str, version: str):
363354
"requires_python": release.requires_python,
364355
"requires_external": list(release.requires_external),
365356
"_pypi_ordering": release._pypi_ordering,
366-
"_pypi_hidden": release._pypi_hidden,
367357
"downloads": {"last_day": -1, "last_week": -1, "last_month": -1},
368358
"cheesecake_code_kwalitee_id": None,
369359
"cheesecake_documentation_id": None,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
Set User.is_staff to nullable
14+
15+
Revision ID: 62f6becc7653
16+
Revises: 522918187b73
17+
Create Date: 2018-08-17 16:16:20.397865
18+
"""
19+
20+
from alembic import op
21+
22+
23+
revision = "62f6becc7653"
24+
down_revision = "522918187b73"
25+
26+
27+
def upgrade():
28+
op.alter_column("accounts_user", "is_staff", nullable=True)
29+
30+
31+
def downgrade():
32+
op.alter_column("accounts_user", "is_staff", nullable=False)

0 commit comments

Comments
 (0)