-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
backend/capellacollab/alembic/versions/2827788b8d2d_add_slugs_for_tools_and_versions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters