fix: More Backup Restore Fixes (#2859)

* refactor normalized search migration to use dummy default

* changed group slug migration to use raw SQL

* updated comment

* added tests with anonymized backups (currently failing)

* typo

* fixed LDAP enum in test data

* fix for adding label settings across groups

* add migration data fixes

* fix shopping list label settings test

* re-run db init instead of just running alembic migration, to include fixes

* intentionally broke SQLAlchemy GUID handling

* safely convert between GUID types in different databases

* restore original test data after testing backup restores

* added missing group name update to migration
This commit is contained in:
Michael Genson
2024-01-02 22:19:04 -06:00
committed by GitHub
parent b3f7f2d89f
commit 7602c67449
14 changed files with 422 additions and 45 deletions

View File

@@ -24,17 +24,22 @@ def populate_group_slugs(session: Session):
seen_slugs: set[str] = set()
for group in groups:
original_name = group.name
new_name = original_name
attempts = 0
while True:
slug = slugify(group.name)
slug = slugify(new_name)
if slug not in seen_slugs:
break
attempts += 1
group.name = f"{original_name} ({attempts})"
new_name = f"{original_name} ({attempts})"
seen_slugs.add(slug)
group.slug = slug
session.execute(
sa.text(f"UPDATE {Group.__tablename__} SET name=:name, slug=:slug WHERE id=:id").bindparams(
name=new_name, slug=slug, id=group.id
)
)
session.commit()