diff --git a/apps/account/management/commands/add_account.py b/apps/account/management/commands/add_account.py index 808f661e..2b72767c 100644 --- a/apps/account/management/commands/add_account.py +++ b/apps/account/management/commands/add_account.py @@ -11,7 +11,7 @@ class Command(BaseCommand): def account_sql(self): with connections['legacy'].cursor() as cursor: cursor.execute(''' - select a.email, a.id as account_id + select a.email, a.id as account_id, a.encrypted_password from accounts as a where a.email is not null and a.email not in ('cyril@tomatic.net', @@ -20,7 +20,7 @@ class Command(BaseCommand): 'd.sadykova@octopod.ru', 'n.yurchenko@id-east.ru' ) - and a.confirmed_at is not null + and a.confirmed_at is not null ''') return namedtuplefetchall(cursor) @@ -32,7 +32,12 @@ class Command(BaseCommand): objects.append(User(email=a.email, unconfirmed_email=False, email_confirmed=True, - old_id=a.account_id + old_id=a.account_id, + password='bcrypt$'+a.encrypted_password )) + else: + user = User.objects.filter(Q(email=a.email) | Q(old_id=a.account_id)) + user.update(password='bcrypt$'+a.encrypted_password) + User.objects.bulk_create(objects) self.stdout.write(self.style.WARNING(f'Created accounts objects.')) \ No newline at end of file