split migrations, CI denendencies

This commit is contained in:
vabene1111
2025-03-16 13:08:06 +01:00
parent 3075ec066f
commit 7bde1bf44f
4 changed files with 44 additions and 31 deletions

View File

@@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@v1.4.3
with:
packages: libsasl2-dev python3-dev libldap2-dev libssl-dev
packages: libsasl2-dev python3-dev libxml2-dev libxslt-dev libldap2-dev libssl-dev gcc musl-dev postgresql-dev zlib-dev jpeg-dev libwebp-dev openssl-dev libffi-dev cargo openldap-dev python3-dev xmlsec-dev xmlsec build-base g++ curl
version: 1.0
# Setup python & dependencies

View File

@@ -3,34 +3,6 @@
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
from django.db.models import F, Count
from django_scopes import scopes_disabled
def add_space_and_owner_to_shopping_list_recipe(apps, schema_editor):
print('migrating shopping list recipe space attribute, this might take a while ...')
with scopes_disabled():
ShoppingListRecipe = apps.get_model('cookbook', 'ShoppingListRecipe')
# delete all shopping list recipes that do not have entries as those are of no use anyway
ShoppingListRecipe.objects.annotate(entry_count=Count('entries')).filter(entry_count__lte=0).delete()
shopping_list_recipes = ShoppingListRecipe.objects.all().prefetch_related('entries')
update_list = []
for slr in shopping_list_recipes:
if entry := slr.entries.first():
if entry.space and entry.created_by:
slr.space = entry.space
slr.created_by = entry.created_by
update_list.append(slr)
else:
print(slr, 'missing data on entry')
else:
print(slr, 'missing entry')
ShoppingListRecipe.objects.bulk_update(update_list, ['space', 'created_by'], batch_size=500)
class Migration(migrations.Migration):
dependencies = [
@@ -49,5 +21,4 @@ class Migration(migrations.Migration):
name='space',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.space'),
),
migrations.RunPython(add_space_and_owner_to_shopping_list_recipe),
]

View File

@@ -0,0 +1,42 @@
# Generated by Django 4.2.18 on 2025-03-14 10:50
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
from django.db.models import F, Count
from django_scopes import scopes_disabled
def add_space_and_owner_to_shopping_list_recipe(apps, schema_editor):
print('migrating shopping list recipe space attribute, this might take a while ...')
with scopes_disabled():
ShoppingListRecipe = apps.get_model('cookbook', 'ShoppingListRecipe')
# delete all shopping list recipes that do not have entries as those are of no use anyway
ShoppingListRecipe.objects.annotate(entry_count=Count('entries')).filter(entry_count__lte=0).delete()
shopping_list_recipes = ShoppingListRecipe.objects.all().prefetch_related('entries')
update_list = []
for slr in shopping_list_recipes:
if entry := slr.entries.first():
if entry.space and entry.created_by:
slr.space = entry.space
slr.created_by = entry.created_by
update_list.append(slr)
else:
print(slr, 'missing data on entry')
else:
print(slr, 'missing entry')
ShoppingListRecipe.objects.bulk_update(update_list, ['space', 'created_by'], batch_size=500)
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0220_shoppinglistrecipe_created_by_and_more'),
]
operations = [
migrations.RunPython(add_space_and_owner_to_shopping_list_recipe),
]

View File

@@ -9,7 +9,7 @@ class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('cookbook', '0220_shoppinglistrecipe_created_by_and_more'),
('cookbook', '0221_migrate_shoppinglistrecipe_space_created_by'),
]
operations = [