Skip to content

Commit 463ff5f

Browse files
committed
feat: add Project.lifecycle_status columns
Signed-off-by: Mike Fiedler <[email protected]>
1 parent c1f91c9 commit 463ff5f

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
Add Project Lifecycle Status
14+
15+
Revision ID: 14ad61e054cf
16+
Revises: b14df478c48f
17+
Create Date: 2024-06-26 20:30:52.083447
18+
"""
19+
20+
import sqlalchemy as sa
21+
22+
from alembic import op
23+
from sqlalchemy.dialects import postgresql
24+
25+
revision = "14ad61e054cf"
26+
down_revision = "b14df478c48f"
27+
28+
29+
def upgrade():
30+
op.execute("SET statement_timeout = 5000")
31+
op.execute("SET lock_timeout = 4000")
32+
33+
sa.Enum("quarantine-enter", "quarantine-exit", name="lifecyclestatus").create(
34+
op.get_bind()
35+
)
36+
op.add_column(
37+
"projects",
38+
sa.Column(
39+
"lifecycle_status",
40+
postgresql.ENUM(
41+
"quarantine-enter",
42+
"quarantine-exit",
43+
name="lifecyclestatus",
44+
create_type=False,
45+
),
46+
nullable=True,
47+
comment="Lifecycle status can change project visibility and access",
48+
),
49+
)
50+
op.add_column(
51+
"projects",
52+
sa.Column(
53+
"lifecycle_status_changed",
54+
sa.DateTime(),
55+
server_default=sa.text("now()"),
56+
nullable=True,
57+
comment="When the lifecycle status was last changed",
58+
),
59+
)
60+
op.add_column(
61+
"projects",
62+
sa.Column(
63+
"lifecycle_status_note",
64+
sa.String(),
65+
nullable=True,
66+
comment="Note about the lifecycle status",
67+
),
68+
)
69+
op.create_index(
70+
"projects_lifecycle_status_idx", "projects", ["lifecycle_status"], unique=False
71+
)
72+
73+
74+
def downgrade():
75+
op.drop_index("projects_lifecycle_status_idx", table_name="projects")
76+
op.drop_column("projects", "lifecycle_status_note")
77+
op.drop_column("projects", "lifecycle_status_changed")
78+
op.drop_column("projects", "lifecycle_status")
79+
sa.Enum("quarantine-enter", "quarantine-exit", name="lifecyclestatus").drop(
80+
op.get_bind()
81+
)

warehouse/packaging/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ def __contains__(self, project):
162162
return True
163163

164164

165+
class LifecycleStatus(enum.StrEnum):
166+
QuarantineEnter = "quarantine-enter"
167+
QuarantineExit = "quarantine-exit"
168+
169+
165170
class Project(SitemapMixin, HasEvents, HasObservations, db.Model):
166171
__tablename__ = "projects"
167172
__repr__ = make_repr("name")
@@ -183,6 +188,16 @@ class Project(SitemapMixin, HasEvents, HasObservations, db.Model):
183188
total_size: Mapped[int | None] = mapped_column(
184189
BigInteger, server_default=sql.text("0")
185190
)
191+
lifecycle_status: Mapped[LifecycleStatus | None] = mapped_column(
192+
comment="Lifecycle status can change project visibility and access"
193+
)
194+
lifecycle_status_changed: Mapped[datetime_now | None] = mapped_column(
195+
onupdate=func.now(),
196+
comment="When the lifecycle status was last changed",
197+
)
198+
lifecycle_status_note: Mapped[str | None] = mapped_column(
199+
comment="Note about the lifecycle status"
200+
)
186201

187202
oidc_publishers: Mapped[list[OIDCPublisher]] = orm.relationship(
188203
secondary="oidc_publisher_project_association",
@@ -231,6 +246,7 @@ class Project(SitemapMixin, HasEvents, HasObservations, db.Model):
231246
"project_name_ultranormalized",
232247
func.ultranormalize_name(name),
233248
),
249+
Index("projects_lifecycle_status_idx", "lifecycle_status"),
234250
)
235251

236252
def __getitem__(self, version):

0 commit comments

Comments
 (0)