Skip to content

Commit

Permalink
Merge 1bb7963 into b844c3f
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzWeber0 authored Apr 25, 2024
2 parents b844c3f + 1bb7963 commit e63ee25
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-FileCopyrightText: Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

"""Remove versions without tool
Revision ID: aa88e6d1333b
Revises: e06d616469ec
Create Date: 2024-04-25 10:48:56.205850
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "aa88e6d1333b"
down_revision = "e06d616469ec"
branch_labels = None
depends_on = None

t_versions = sa.Table(
"versions",
sa.MetaData(),
sa.Column("id", sa.Integer()),
sa.Column("tool_id", sa.Integer()),
)

t_natures = sa.Table(
"types",
sa.MetaData(),
sa.Column("id", sa.Integer()),
sa.Column("tool_id", sa.Integer()),
)


def upgrade():
connection = op.get_bind()
connection.execute(
sa.delete(t_versions).where(t_versions.c.tool_id.is_(None))
)
connection.execute(
sa.delete(t_natures).where(t_natures.c.tool_id.is_(None))
)
op.alter_column(
"types", "tool_id", existing_type=sa.INTEGER(), nullable=False
)
op.alter_column(
"versions", "tool_id", existing_type=sa.INTEGER(), nullable=False
)
12 changes: 8 additions & 4 deletions backend/capellacollab/tools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ class DatabaseTool(database.Base):
)

versions: orm.Mapped[list[DatabaseVersion]] = orm.relationship(
default_factory=list, back_populates="tool"
default_factory=list,
back_populates="tool",
cascade="all, delete-orphan",
)
natures: orm.Mapped[list[DatabaseNature]] = orm.relationship(
default_factory=list, back_populates="tool"
default_factory=list,
back_populates="tool",
cascade="all, delete-orphan",
)


Expand Down Expand Up @@ -335,7 +339,7 @@ class DatabaseVersion(database.Base):

name: orm.Mapped[str]

tool_id: orm.Mapped[int | None] = orm.mapped_column(
tool_id: orm.Mapped[int] = orm.mapped_column(
sa.ForeignKey("tools.id"),
init=False,
)
Expand All @@ -356,7 +360,7 @@ class DatabaseNature(database.Base):
id: orm.Mapped[int] = orm.mapped_column(init=False, primary_key=True)
name: orm.Mapped[str]

tool_id: orm.Mapped[int | None] = orm.mapped_column(
tool_id: orm.Mapped[int] = orm.mapped_column(
sa.ForeignKey("tools.id"), init=False
)
tool: orm.Mapped[DatabaseTool] = orm.relationship(back_populates="natures")
Expand Down

0 comments on commit e63ee25

Please sign in to comment.