Skip to content

Commit

Permalink
feat: Slugs for tools and versions
Browse files Browse the repository at this point in the history
  • Loading branch information
amolenaar committed Nov 8, 2023
1 parent e8c9c1d commit 8b70b91
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors
# SPDX-License-Identifier: Apache-2.0

"""Slugs for tools and versions
Revision ID: 2827788b8d2d
Revises: 5ca7037ef183
Create Date: 2023-11-07 11:15:07.753055
"""
import sqlalchemy as sa
from alembic import op
from slugify import slugify

revision = "2827788b8d2d"
down_revision = "5ca7037ef183"
branch_labels = None
depends_on = None


def upgrade():
for table_name in ("tools", "versions"):
op.add_column(
table_name, sa.Column("slug", sa.String(), nullable=True)
)

connection = op.get_bind()
rows = connection.execute(sa.text(f"SELECT * from {table_name}"))

for row in rows:
connection.execute(
sa.text(
f"UPDATE {table_name} SET slug = '{slugify(row.name)}' WHERE id = {row.id};"
)
)

op.alter_column(table_name, "slug", nullable=False)
3 changes: 3 additions & 0 deletions backend/capellacollab/tools/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections import abc

import sqlalchemy as sa
from slugify import slugify
from sqlalchemy import exc, orm

from capellacollab.core import database
Expand Down Expand Up @@ -37,6 +38,7 @@ def get_tool_by_name(
def create_tool(
db: orm.Session, tool: models.DatabaseTool
) -> models.DatabaseTool:
tool.slug = slugify(tool.name)
tool.integrations = integrations_models.DatabaseToolIntegrations(
pure_variants=False, t4c=False, jupyter=False
)
Expand Down Expand Up @@ -161,6 +163,7 @@ def create_version(
is_recommended=is_recommended,
is_deprecated=is_deprecated,
tool_id=tool_id,
slug=slugify(name),
)
db.add(version)
db.commit()
Expand Down
2 changes: 2 additions & 0 deletions backend/capellacollab/tools/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DatabaseTool(database.Base):
id: orm.Mapped[int] = orm.mapped_column(primary_key=True)

name: orm.Mapped[str]
slug: orm.Mapped[str]
docker_image_template: orm.Mapped[str]
docker_image_backup_template: orm.Mapped[str | None]
readonly_docker_image_template: orm.Mapped[str | None]
Expand All @@ -46,6 +47,7 @@ class DatabaseVersion(database.Base):
id: orm.Mapped[int] = orm.mapped_column(primary_key=True)

name: orm.Mapped[str]
slug: orm.Mapped[str]
is_recommended: orm.Mapped[bool]
is_deprecated: orm.Mapped[bool]

Expand Down

0 comments on commit 8b70b91

Please sign in to comment.