add community scripts to migration
@@ -4,9 +4,11 @@ from django.db import migrations
from django.conf import settings
import os
import base64
+from pathlib import Path
def move_scripts_to_db(apps, schema_editor):
+ print("")
Script = apps.get_model("scripts", "Script")
for script in Script.objects.all():
if not script.script_type == "builtin":
@@ -26,6 +28,25 @@ def move_scripts_to_db(apps, schema_editor):
f"Script file {script.name} was not found on the disk. You will need to edit the script in the UI"
)
+ elif not settings.DOCKER_BUILD and script.code_base64 is None:
+ scripts_dir = os.path.join(Path(settings.BASE_DIR).parents[1], "scripts")
+ community_script = os.path.join(scripts_dir, script.filename)
+ if os.path.exists(community_script):
+ print(f"Found community script {script.name}. Importing code.")
+ with open(community_script, "rb") as f:
+ script_bytes = f.read().decode("utf-8").encode("ascii", "ignore")
+ script.code_base64 = base64.b64encode(script_bytes).decode("ascii")
+ script.save(update_fields=["code_base64"])
+
+ elif settings.DOCKER_BUILD and script.code_base64 is None:
+ community_script = os.path.join(settings.SCRIPTS_DIR, script.filename)
+ if os.path.exists(community_script):
+ print(f"Found community script {script.name}. Importing code.")
+ with open(community_script, "rb") as f:
+ script_bytes = f.read().decode("utf-8").encode("ascii", "ignore")
+ script.code_base64 = base64.b64encode(script_bytes).decode("ascii")
+ script.save(update_fields=["code_base64"])
+
class Migration(migrations.Migration):
