mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-11-17 19:44:02 +01:00
Attempt to fix botched normalized URL migration from 1.43.0 (#1205)
This commit is contained in:
34
bookmarks/migrations/0051_fix_normalized_url.py
Normal file
34
bookmarks/migrations/0051_fix_normalized_url.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# Generated by Django 5.2.5 on 2025-10-11 08:46
|
||||
|
||||
from django.db import migrations
|
||||
from bookmarks.utils import normalize_url
|
||||
|
||||
|
||||
def fix_url_normalized(apps, schema_editor):
|
||||
Bookmark = apps.get_model("bookmarks", "Bookmark")
|
||||
|
||||
batch_size = 200
|
||||
qs = Bookmark.objects.filter(url_normalized="").all()
|
||||
for start in range(0, qs.count(), batch_size):
|
||||
batch = list(qs[start : start + batch_size])
|
||||
for bookmark in batch:
|
||||
bookmark.url_normalized = normalize_url(bookmark.url)
|
||||
Bookmark.objects.bulk_update(batch, ["url_normalized"])
|
||||
|
||||
|
||||
def reverse_fix_url_normalized(apps, schema_editor):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookmarks", "0050_new_search_toast"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
fix_url_normalized,
|
||||
reverse_fix_url_normalized,
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user