1
0
mirror of https://gitlab.crans.org/bde/nk20-scripts synced 2025-06-29 17:51:08 +02:00

Anonymize data, fix remittancei import

This commit is contained in:
Yohann D'ANELLO
2020-07-26 12:05:26 +02:00
parent 748ad7eb48
commit 126e5fa1e4
5 changed files with 33 additions and 8 deletions

View File

@ -11,7 +11,7 @@ from polymorphic.models import PolymorphicModel
NO_SEQ = [
"Session",
"Token",
"WEIRole", # dirty fix
"WEIRole", # dirty fix
]
class Command(BaseCommand):
@ -33,10 +33,14 @@ class Command(BaseCommand):
# no app specified, sync everything
model_classes = apps.get_models(include_auto_created=True)
db_names = [ m._meta.db_table for m in model_classes if m.__base__.__base__ is not PolymorphicModel and m.__name__ not in NO_SEQ and m.objects.count()>1]
db_names = [
m._meta.db_table for m in model_classes
if m.__base__.__base__ is not PolymorphicModel and m.__name__ not in NO_SEQ and m.objects.count() > 1
]
com = "BEGIN;\n"
for db_name in db_names:
com += f'SELECT setval(pg_get_serial_sequence(\'"{db_name}"\',\'id\'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "{db_name}";\n'
com += f'SELECT setval(pg_get_serial_sequence(\'"{db_name}"\',\'id\'), coalesce(max("id"), 1),' \
f' max("id") IS NOT null) FROM "{db_name}";\n'
com += "COMMIT;"
print(com)
cur = connection.cursor()