mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
239 lines
7.6 KiB
Python
239 lines
7.6 KiB
Python
# Generated by Django 4.2.10 on 2024-03-21 09:13
|
|
|
|
import django.db.models
|
|
from django.conf import settings
|
|
from django.db import migrations, models
|
|
|
|
import plane.db.models.asset
|
|
|
|
|
|
def update_user_urls(apps, schema_editor):
|
|
# Check if the app is using minio or s3
|
|
if settings.USE_MINIO:
|
|
prefix1 = (
|
|
f"{settings.AWS_S3_URL_PROTOCOL}//{settings.AWS_S3_CUSTOM_DOMAIN}/"
|
|
)
|
|
prefix2 = prefix1
|
|
else:
|
|
prefix1 = f"https://{settings.AWS_STORAGE_BUCKET_NAME}.s3.{settings.AWS_REGION}.amazonaws.com/"
|
|
prefix2 = (
|
|
f"https://{settings.AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/"
|
|
)
|
|
|
|
User = apps.get_model("db", "User")
|
|
bulk_users = []
|
|
|
|
# Loop through all the users and update the cover image
|
|
for user in User.objects.all():
|
|
# prefix 1
|
|
if user.avatar and (user.avatar.startswith(prefix1)):
|
|
avatar_key = user.avatar
|
|
user.avatar = avatar_key[len(prefix1) :]
|
|
bulk_users.append(user)
|
|
|
|
# prefix 2
|
|
if (
|
|
not settings.USE_MINIO
|
|
and user.avatar
|
|
and user.avatar.startswith(prefix2)
|
|
):
|
|
avatar_key = user.avatar
|
|
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 = cover_image_key[len(prefix1) :]
|
|
bulk_users.append(user)
|
|
|
|
# prefix 2
|
|
if (
|
|
not settings.USE_MINIO
|
|
and user.cover_image
|
|
and user.cover_image.startswith(prefix2)
|
|
):
|
|
cover_image_key = user.cover_image
|
|
user.cover_image = cover_image_key[len(prefix2) :]
|
|
bulk_users.append(user)
|
|
|
|
User.objects.bulk_update(
|
|
bulk_users, ["avatar", "cover_image"], batch_size=100
|
|
)
|
|
|
|
|
|
def update_workspace_urls(apps, schema_editor):
|
|
# Check if the app is using minio or s3
|
|
if settings.USE_MINIO:
|
|
prefix1 = (
|
|
f"{settings.AWS_S3_URL_PROTOCOL}//{settings.AWS_S3_CUSTOM_DOMAIN}/"
|
|
)
|
|
prefix2 = prefix1
|
|
else:
|
|
prefix1 = f"https://{settings.AWS_STORAGE_BUCKET_NAME}.s3.{settings.AWS_REGION}.amazonaws.com/"
|
|
prefix2 = (
|
|
f"https://{settings.AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/"
|
|
)
|
|
|
|
Workspace = apps.get_model("db", "Workspace")
|
|
bulk_workspaces = []
|
|
|
|
# Loop through all the users and update the cover image
|
|
for workspace in Workspace.objects.all():
|
|
# prefix 1
|
|
if workspace.logo and (workspace.logo.startswith(prefix1)):
|
|
logo_key = workspace.logo
|
|
workspace.logo = logo_key[len(prefix1) :]
|
|
bulk_workspaces.append(workspace)
|
|
|
|
# prefix 2
|
|
if (
|
|
not settings.USE_MINIO
|
|
and workspace.logo
|
|
and (workspace.logo.startswith(prefix2))
|
|
):
|
|
logo_key = workspace.logo
|
|
workspace.logo = logo_key[len(prefix2) :]
|
|
bulk_workspaces.append(workspace)
|
|
|
|
Workspace.objects.bulk_update(bulk_workspaces, ["logo"], batch_size=100)
|
|
|
|
|
|
def update_project_urls(apps, schema_editor):
|
|
file_assets = {}
|
|
|
|
# Check if the app is using minio or s3
|
|
if settings.USE_MINIO:
|
|
prefix1 = (
|
|
f"{settings.AWS_S3_URL_PROTOCOL}//{settings.AWS_S3_CUSTOM_DOMAIN}/"
|
|
)
|
|
prefix2 = prefix1
|
|
else:
|
|
prefix1 = f"https://{settings.AWS_STORAGE_BUCKET_NAME}.s3.{settings.AWS_REGION}.amazonaws.com/"
|
|
prefix2 = (
|
|
f"https://{settings.AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/"
|
|
)
|
|
|
|
Project = apps.get_model("db", "Project")
|
|
bulk_projects = []
|
|
|
|
# Loop through all the users and update the cover image
|
|
for project in Project.objects.all():
|
|
# prefix 1
|
|
if project.cover_image and (project.cover_image.startswith(prefix1)):
|
|
cover_image_key = project.cover_image
|
|
project.cover_image = cover_image_key[len(prefix1) :]
|
|
file_assets[cover_image_key[len(prefix1) :]] = str(project.id)
|
|
bulk_projects.append(project)
|
|
|
|
# prefix 2
|
|
if (
|
|
not settings.USE_MINIO
|
|
and project.cover_image
|
|
and (project.cover_image.startswith(prefix2))
|
|
):
|
|
cover_image_key = project.cover_image
|
|
project.cover_image = cover_image_key[len(prefix2) :]
|
|
file_assets[cover_image_key[len(prefix2) :]] = str(project.id)
|
|
bulk_projects.append(project)
|
|
|
|
Project.objects.bulk_update(bulk_projects, ["cover_image"], batch_size=100)
|
|
|
|
FileAsset = apps.get_model("db", "FileAsset")
|
|
bulk_assets = []
|
|
for asset in FileAsset.objects.filter(asset__in=file_assets.keys()):
|
|
asset.project_id = file_assets[str(asset.asset)]
|
|
bulk_assets.append(asset)
|
|
|
|
FileAsset.objects.bulk_update(
|
|
bulk_assets,
|
|
[
|
|
"project_id",
|
|
],
|
|
batch_size=100,
|
|
)
|
|
return
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("db", "0062_cycle_archived_at_module_archived_at_and_more"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AlterField(
|
|
model_name="fileasset",
|
|
name="asset",
|
|
field=models.FileField(
|
|
storage=plane.settings.storage.S3PrivateBucketStorage(),
|
|
upload_to=plane.db.models.asset.get_upload_path,
|
|
validators=[plane.db.models.asset.file_size],
|
|
),
|
|
),
|
|
migrations.RemoveField(
|
|
model_name="issueactivity",
|
|
name="attachments",
|
|
),
|
|
migrations.RemoveField(
|
|
model_name="issuecomment",
|
|
name="attachments",
|
|
),
|
|
migrations.AlterField(
|
|
model_name="integration",
|
|
name="avatar_url",
|
|
field=models.CharField(blank=True, null=True),
|
|
),
|
|
migrations.AlterField(
|
|
model_name="project",
|
|
name="cover_image",
|
|
field=models.CharField(blank=True, max_length=800, null=True),
|
|
),
|
|
migrations.AlterField(
|
|
model_name="user",
|
|
name="cover_image",
|
|
field=models.CharField(blank=True, max_length=800, null=True),
|
|
),
|
|
migrations.AlterField(
|
|
model_name="workspace",
|
|
name="logo",
|
|
field=models.CharField(blank=True, null=True, verbose_name="Logo"),
|
|
),
|
|
migrations.AddField(
|
|
model_name="fileasset",
|
|
name="size",
|
|
field=models.PositiveBigIntegerField(null=True),
|
|
),
|
|
migrations.AddField(
|
|
model_name="fileasset",
|
|
name="entity_identifier",
|
|
field=models.UUIDField(null=True),
|
|
),
|
|
migrations.AddField(
|
|
model_name="fileasset",
|
|
name="entity_type",
|
|
field=models.CharField(
|
|
choices=[
|
|
("issue_attachment", "Issue Attachment"),
|
|
("issue_description", "Issue Description"),
|
|
("comment", "Comment"),
|
|
("page", "Page"),
|
|
],
|
|
null=True,
|
|
),
|
|
),
|
|
migrations.AddField(
|
|
model_name="fileasset",
|
|
name="project",
|
|
field=models.ForeignKey(
|
|
null=True,
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
related_name="assets",
|
|
to="db.project",
|
|
),
|
|
),
|
|
migrations.RunPython(update_user_urls),
|
|
migrations.RunPython(update_workspace_urls),
|
|
migrations.RunPython(update_project_urls),
|
|
]
|