Skip to content

Commit ba97c14

Browse files
committed
Cascade delete additional information
1 parent 8bd7563 commit ba97c14

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"""cascade delete additional information
2+
3+
Revision ID: f90eb601dceb
4+
Revises: 74c313df967b
5+
Create Date: 2025-02-19 12:01:27.426582
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
import geoalchemy2
12+
import sqlalchemy as sa
13+
from alembic import op
14+
15+
# revision identifiers, used by Alembic.
16+
revision: str = "f90eb601dceb"
17+
down_revision: Union[str, None] = "74c313df967b"
18+
branch_labels: Union[str, Sequence[str], None] = None
19+
depends_on: Union[str, Sequence[str], None] = None
20+
21+
22+
def upgrade() -> None:
23+
# ### commands auto generated by Alembic - please adjust! ###
24+
op.drop_constraint(
25+
"plan_regulation_id_fkey",
26+
"additional_information",
27+
schema="hame",
28+
type_="foreignkey",
29+
)
30+
op.create_foreign_key(
31+
"plan_regulation_id_fkey",
32+
"additional_information",
33+
"plan_regulation",
34+
["plan_regulation_id"],
35+
["id"],
36+
source_schema="hame",
37+
referent_schema="hame",
38+
ondelete="CASCADE",
39+
)
40+
# ### end Alembic commands ###
41+
42+
43+
def downgrade() -> None:
44+
# ### commands auto generated by Alembic - please adjust! ###
45+
op.drop_constraint(
46+
"plan_regulation_id_fkey",
47+
"additional_information",
48+
schema="hame",
49+
type_="foreignkey",
50+
)
51+
op.create_foreign_key(
52+
"plan_regulation_id_fkey",
53+
"additional_information",
54+
"plan_regulation",
55+
["plan_regulation_id"],
56+
["id"],
57+
source_schema="hame",
58+
referent_schema="hame",
59+
)
60+
# ### end Alembic commands ###

database/models.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ class AdditionalInformation(VersionedBase, AttributeValueMixin):
327327
ForeignKey(
328328
"hame.plan_regulation.id",
329329
name="plan_regulation_id_fkey",
330+
ondelete="CASCADE",
330331
),
331332
index=True,
332333
)
@@ -400,7 +401,11 @@ class PlanRegulation(PlanBase, AttributeValueMixin):
400401
plan_theme = relationship("PlanTheme", backref="plan_regulations", lazy="joined")
401402

402403
additional_information: Mapped[list[AdditionalInformation]] = relationship(
403-
"AdditionalInformation", back_populates="plan_regulation", lazy="joined"
404+
"AdditionalInformation",
405+
back_populates="plan_regulation",
406+
lazy="joined",
407+
cascade="all, delete-orphan",
408+
passive_deletes=True,
404409
)
405410

406411
ordering: Mapped[Optional[int]]

0 commit comments

Comments
 (0)