Skip to content

Commit

Permalink
Migrate existing data and switch to using Release.is_prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
dstufft committed Jun 27, 2022
1 parent c1c91dc commit 7435211
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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_prelease 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,
)
2 changes: 1 addition & 1 deletion warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7435211

Please sign in to comment.