Skip to content

Commit

Permalink
feat: add Project.lifecycle_status columns
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
  • Loading branch information
miketheman committed Jun 27, 2024
1 parent 4c667b1 commit 1601b40
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 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.
"""
Add Project Lifecycle Status
Revision ID: 14ad61e054cf
Revises: b14df478c48f
Create Date: 2024-06-26 20:30:52.083447
"""

import sqlalchemy as sa

from alembic import op
from sqlalchemy.dialects import postgresql

revision = "14ad61e054cf"
down_revision = "b14df478c48f"


def upgrade():
op.execute("SET statement_timeout = 5000")
op.execute("SET lock_timeout = 4000")

sa.Enum("quarantine-enter", "quarantine-exit", name="lifecyclestatus").create(
op.get_bind()
)
op.add_column(
"projects",
sa.Column(
"lifecycle_status",
postgresql.ENUM(
"quarantine-enter",
"quarantine-exit",
name="lifecyclestatus",
create_type=False,
),
nullable=True,
comment="Lifecycle status can change project visibility and access",
),
)
op.add_column(
"projects",
sa.Column(
"lifecycle_status_changed",
sa.DateTime(),
server_default=sa.text("now()"),
nullable=True,
comment="When the lifecycle status was last changed",
),
)
op.add_column(
"projects",
sa.Column(
"lifecycle_status_note",
sa.String(),
nullable=True,
comment="Note about the lifecycle status",
),
)
op.create_index(
"projects_lifecycle_status_idx", "projects", ["lifecycle_status"], unique=False
)


def downgrade():
op.drop_index("projects_lifecycle_status_idx", table_name="projects")
op.drop_column("projects", "lifecycle_status_note")
op.drop_column("projects", "lifecycle_status_changed")
op.drop_column("projects", "lifecycle_status")
sa.Enum("quarantine-enter", "quarantine-exit", name="lifecyclestatus").drop(
op.get_bind()
)
16 changes: 16 additions & 0 deletions warehouse/packaging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ def __contains__(self, project):
return True


class LifecycleStatus(enum.StrEnum):
QuarantineEnter = "quarantine-enter"
QuarantineExit = "quarantine-exit"


class Project(SitemapMixin, HasEvents, HasObservations, db.Model):
__tablename__ = "projects"
__repr__ = make_repr("name")
Expand All @@ -183,6 +188,16 @@ class Project(SitemapMixin, HasEvents, HasObservations, db.Model):
total_size: Mapped[int | None] = mapped_column(
BigInteger, server_default=sql.text("0")
)
lifecycle_status: Mapped[LifecycleStatus | None] = mapped_column(
comment="Lifecycle status can change project visibility and access"
)
lifecycle_status_changed: Mapped[datetime_now | None] = mapped_column(
onupdate=func.now(),
comment="When the lifecycle status was last changed",
)
lifecycle_status_note: Mapped[str | None] = mapped_column(
comment="Note about the lifecycle status"
)

oidc_publishers: Mapped[list[OIDCPublisher]] = orm.relationship(
secondary="oidc_publisher_project_association",
Expand Down Expand Up @@ -231,6 +246,7 @@ class Project(SitemapMixin, HasEvents, HasObservations, db.Model):
"project_name_ultranormalized",
func.ultranormalize_name(name),
),
Index("projects_lifecycle_status_idx", "lifecycle_status"),
)

def __getitem__(self, version):
Expand Down

0 comments on commit 1601b40

Please sign in to comment.