dev: update migration to only use file asset name

This commit is contained in:
pablohashescobar 2024-04-30 20:44:21 +05:30
parent d560d1f7df
commit 08ec379e9c
2 changed files with 14 additions and 38 deletions

View File

@ -28,9 +28,7 @@ def update_user_urls(apps, schema_editor):
# prefix 1
if user.avatar and (user.avatar.startswith(prefix1)):
avatar_key = user.avatar
user.avatar = (
"/api/users/avatar/" + avatar_key[len(prefix1) :] + "/"
)
user.avatar = avatar_key[len(prefix1) :]
bulk_users.append(user)
# prefix 2
@ -40,19 +38,13 @@ def update_user_urls(apps, schema_editor):
and user.avatar.startswith(prefix2)
):
avatar_key = user.avatar
user.avatar = (
"/api/users/avatar/" + avatar_key[len(prefix2) :] + "/"
)
user.avatar = avatar_key[len(prefix2) :]
bulk_users.append(user)
# prefix 1
if user.cover_image and (user.cover_image.startswith(prefix1)):
cover_image_key = user.cover_image
user.cover_image = (
"/api/users/cover-image/"
+ cover_image_key[len(prefix1) :]
+ "/"
)
user.cover_image = cover_image_key[len(prefix1) :]
bulk_users.append(user)
# prefix 2
@ -62,11 +54,7 @@ def update_user_urls(apps, schema_editor):
and user.cover_image.startswith(prefix2)
):
cover_image_key = user.cover_image
user.cover_image = (
"/api/users/cover-image/"
+ cover_image_key[len(prefix2) :]
+ "/"
)
user.cover_image = cover_image_key[len(prefix2) :]
bulk_users.append(user)
User.objects.bulk_update(
@ -95,7 +83,7 @@ def update_workspace_urls(apps, schema_editor):
# prefix 1
if workspace.logo and (workspace.logo.startswith(prefix1)):
logo_key = workspace.logo
workspace.logo = f"/api/workspaces/{workspace.slug}/logo/{logo_key[len(prefix1) :]}/"
workspace.logo = logo_key[len(prefix1) :]
bulk_workspaces.append(workspace)
# prefix 2
@ -105,7 +93,7 @@ def update_workspace_urls(apps, schema_editor):
and (workspace.logo.startswith(prefix2))
):
logo_key = workspace.logo
workspace.logo = f"/api/workspaces/{workspace.slug}/logo/{logo_key[len(prefix2) :]}/"
workspace.logo = logo_key[len(prefix2) :]
bulk_workspaces.append(workspace)
Workspace.objects.bulk_update(bulk_workspaces, ["logo"], batch_size=100)
@ -134,7 +122,7 @@ def update_project_urls(apps, schema_editor):
# prefix 1
if project.cover_image and (project.cover_image.startswith(prefix1)):
cover_image_key = project.cover_image
project.cover_image = f"/api/workspaces/{project.workspace.slug}/projects/{project.id}/cover-image/{cover_image_key[len(prefix1) :]}/"
project.cover_image = cover_image_key[len(prefix1) :]
file_assets[cover_image_key[len(prefix1) :]] = str(project.id)
bulk_projects.append(project)
@ -145,7 +133,7 @@ def update_project_urls(apps, schema_editor):
and (project.cover_image.startswith(prefix2))
):
cover_image_key = project.cover_image
project.cover_image = f"/api/workspaces/{project.workspace.slug}/projects/{project.id}/cover-image/{cover_image_key[len(prefix2) :]}/"
project.cover_image = cover_image_key[len(prefix2) :]
file_assets[cover_image_key[len(prefix2) :]] = str(project.id)
bulk_projects.append(project)

View File

@ -32,9 +32,7 @@ def convert_issue_description_image_sources(apps, schema_editor):
for img in img_tags:
src = img.get("src", "")
if src and (src.startswith(prefix1)):
img["src"] = (
f"{src[len(prefix1): ]}"
)
img["src"] = src[len(prefix1) :]
file_assets[src[len(prefix1) :]] = {
"project_id": str(issue.project_id),
"issue_id": str(issue.id),
@ -44,9 +42,7 @@ def convert_issue_description_image_sources(apps, schema_editor):
# prefix 2
if not settings.USE_MINIO and src and src.startswith(prefix2):
img["src"] = (
f"{src[len(prefix2): ]}"
)
img["src"] = src[len(prefix2) :]
file_assets[src[len(prefix2) :]] = {
"project_id": str(issue.project_id),
"issue_id": str(issue.id),
@ -108,9 +104,7 @@ def convert_page_image_sources(apps, schema_editor):
for img in img_tags:
src = img.get("src", "")
if src and (src.startswith(prefix1)):
img["src"] = (
f"{src[len(prefix1): ]}/"
)
img["src"] = src[len(prefix1) :]
file_assets[src[len(prefix1) :]] = {
"project_id": str(page.project_id),
"page_id": str(page.id),
@ -120,9 +114,7 @@ def convert_page_image_sources(apps, schema_editor):
# prefix 2
if not settings.USE_MINIO and src and src.startswith(prefix2):
img["src"] = (
f"{src[len(prefix2): ]}/"
)
img["src"] = src[len(prefix2) :]
file_assets[src[len(prefix2) :]] = {
"project_id": str(page.project_id),
"page_id": str(page.id),
@ -180,9 +172,7 @@ def convert_comment_image_sources(apps, schema_editor):
for img in img_tags:
src = img.get("src", "")
if src and (src.startswith(prefix1)):
img["src"] = (
f"{src[len(prefix1): ]}/"
)
img["src"] = src[len(prefix1) :]
file_assets[src[len(prefix1) :]] = {
"project_id": str(comment.project_id),
"comment_id": str(comment.id),
@ -192,9 +182,7 @@ def convert_comment_image_sources(apps, schema_editor):
# prefix 2
if not settings.USE_MINIO and src and src.startswith(prefix2):
img["src"] = (
f"{src[len(prefix2): ]}/"
)
img["src"] = src[len(prefix2) :]
file_assets[src[len(prefix2) :]] = {
"project_id": str(comment.project_id),
"comment_id": str(comment.id),