From cf73768e4552af6e5f9a5fa1cb65eac45bb4c872 Mon Sep 17 00:00:00 2001 From: Donald Stufft Date: Mon, 27 Jun 2022 13:53:51 -0400 Subject: [PATCH] Migrate existing data and switch to using Release.is_prerelease --- ...f_migrate_existing_data_for_release_is_.py | 52 +++++++++++++++++++ warehouse/packaging/models.py | 2 +- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 warehouse/migrations/versions/4490777c984f_migrate_existing_data_for_release_is_.py diff --git a/warehouse/migrations/versions/4490777c984f_migrate_existing_data_for_release_is_.py b/warehouse/migrations/versions/4490777c984f_migrate_existing_data_for_release_is_.py new file mode 100644 index 000000000000..34e63bbc71d1 --- /dev/null +++ b/warehouse/migrations/versions/4490777c984f_migrate_existing_data_for_release_is_.py @@ -0,0 +1,52 @@ +# 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. +""" +Migrate Existing Data for Release.is_prerelease + +Revision ID: 4490777c984f +Revises: b0dbcd2f5c77 +Create Date: 2022-06-27 17:49:09.835384 +""" + +from alembic import op +import sqlalchemy as sa + + +revision = "4490777c984f" +down_revision = "b0dbcd2f5c77" + + +def upgrade(): + op.execute( + """ + UPDATE releases + SET is_prerelease = pep440_is_prerelease(version) + WHERE is_prerelease IS NULL + """ + ) + op.alter_column( + "releases", + "is_prerelease", + existing_type=sa.BOOLEAN(), + server_default=sa.text("false"), + nullable=False, + ) + + +def downgrade(): + op.alter_column( + "releases", + "is_prerelease", + existing_type=sa.BOOLEAN(), + server_default=None, + nullable=True, + ) diff --git a/warehouse/packaging/models.py b/warehouse/packaging/models.py index ed377e2001fa..8fcecd8c2e5e 100644 --- a/warehouse/packaging/models.py +++ b/warehouse/packaging/models.py @@ -418,7 +418,7 @@ def __table_args__(cls): # noqa ) version = Column(Text, nullable=False) canonical_version = Column(Text, nullable=False) - is_prerelease = orm.column_property(func.pep440_is_prerelease(version)) + is_prerelease = Column(Boolean, nullable=False, server_default=sql.false()) author = Column(Text) author_email = Column(Text) maintainer = Column(Text)