Skip to content

Commit 93b89d9

Browse files
diewdurbin
andauthored
Cascade project_events deletion (#9063)
Co-authored-by: Ee W. Durbin III <[email protected]>
1 parent 8f4ec4b commit 93b89d9

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
Cascade project_events deletion
14+
15+
Revision ID: 69b928240b2f
16+
Revises: 99a201142761
17+
Create Date: 2021-02-08 21:45:22.759363
18+
"""
19+
20+
from alembic import op
21+
22+
revision = "69b928240b2f"
23+
down_revision = "99a201142761"
24+
25+
26+
def upgrade():
27+
op.drop_constraint(
28+
"project_events_project_id_fkey", "project_events", type_="foreignkey"
29+
)
30+
op.create_foreign_key(
31+
None,
32+
"project_events",
33+
"projects",
34+
["project_id"],
35+
["id"],
36+
ondelete="CASCADE",
37+
initially="DEFERRED",
38+
deferrable=True,
39+
)
40+
41+
42+
def downgrade():
43+
op.drop_constraint(None, "project_events", type_="foreignkey")
44+
op.create_foreign_key(
45+
"project_events_project_id_fkey",
46+
"project_events",
47+
"projects",
48+
["project_id"],
49+
["id"],
50+
initially="DEFERRED",
51+
deferrable=True,
52+
)

warehouse/packaging/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ class ProjectEvent(db.Model):
272272

273273
project_id = Column(
274274
UUID(as_uuid=True),
275-
ForeignKey("projects.id", deferrable=True, initially="DEFERRED"),
275+
ForeignKey(
276+
"projects.id", deferrable=True, initially="DEFERRED", ondelete="CASCADE"
277+
),
276278
nullable=False,
277279
)
278280
tag = Column(String, nullable=False)

0 commit comments

Comments
 (0)