Merge branch 'feature/account_migrate' into develop
This commit is contained in:
commit
3d83c2a3aa
43
apps/account/management/commands/add_account.py
Normal file
43
apps/account/management/commands/add_account.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db import connections
|
||||
from django.db.models import Q
|
||||
from establishment.management.commands.add_position import namedtuplefetchall
|
||||
from account.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Add account from old db to new db'
|
||||
|
||||
def account_sql(self):
|
||||
with connections['legacy'].cursor() as cursor:
|
||||
cursor.execute('''
|
||||
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',
|
||||
'cyril2@tomatic.net',
|
||||
'd.sadykova@id-east.ru',
|
||||
'd.sadykova@octopod.ru',
|
||||
'n.yurchenko@id-east.ru'
|
||||
)
|
||||
and a.confirmed_at is not null
|
||||
''')
|
||||
return namedtuplefetchall(cursor)
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
objects = []
|
||||
for a in self.account_sql():
|
||||
count = User.objects.filter(Q(email=a.email) | Q(old_id=a.account_id)).count()
|
||||
if count == 0:
|
||||
objects.append(User(email=a.email,
|
||||
unconfirmed_email=False,
|
||||
email_confirmed=True,
|
||||
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.'))
|
||||
31
apps/account/management/commands/add_image.py
Normal file
31
apps/account/management/commands/add_image.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db import connections
|
||||
from django.db.models import Q
|
||||
from establishment.management.commands.add_position import namedtuplefetchall
|
||||
from account.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Update accounts image from old db to new db'
|
||||
|
||||
def account_sql(self):
|
||||
with connections['legacy'].cursor() as cursor:
|
||||
cursor.execute('''
|
||||
select
|
||||
url as image_url,
|
||||
t.account_id
|
||||
from
|
||||
(
|
||||
select a.account_id, a.attachment_file_name,
|
||||
trim(CONCAT(u.url, a.attachment_suffix_url)) as url
|
||||
from account_pictures a,
|
||||
(select 'https://s3.eu-central-1.amazonaws.com/gm-test.com/media/' as url) u
|
||||
) t
|
||||
''')
|
||||
return namedtuplefetchall(cursor)
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
for a in self.account_sql():
|
||||
users = User.objects.filter(old_id=a.account_id)
|
||||
users.update(image_url= a.image_url)
|
||||
self.stdout.write(self.style.WARNING(f'Update accounts image url.'))
|
||||
51
apps/account/management/commands/add_social.py
Normal file
51
apps/account/management/commands/add_social.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
from django.core.management.base import BaseCommand
|
||||
from django.db import connections
|
||||
from django.db.models import Q
|
||||
from social_django.models import UserSocialAuth
|
||||
from establishment.management.commands.add_position import namedtuplefetchall
|
||||
from account.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = '''Add account social networks from old db to new db.
|
||||
Run after add_account!!!'''
|
||||
|
||||
def social_sql(self):
|
||||
with connections['legacy'].cursor() as cursor:
|
||||
cursor.execute('''
|
||||
select
|
||||
DISTINCT
|
||||
i.account_id, i.provider, i.uid
|
||||
from
|
||||
(
|
||||
select a.email, a.id as account_id
|
||||
from accounts as a
|
||||
where a.email is not null
|
||||
and a.email not in ('cyril@tomatic.net',
|
||||
'cyril2@tomatic.net',
|
||||
'd.sadykova@id-east.ru',
|
||||
'd.sadykova@octopod.ru',
|
||||
'n.yurchenko@id-east.ru'
|
||||
)
|
||||
and a.confirmed_at is not null
|
||||
) t
|
||||
join identities i on i.account_id = t.account_id
|
||||
''')
|
||||
return namedtuplefetchall(cursor)
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
objects = []
|
||||
for s in self.social_sql():
|
||||
user = User.objects.filter(old_id=s.account_id)
|
||||
if user.count() > 0:
|
||||
social = UserSocialAuth.objects.filter(user=user.first(),
|
||||
provider=s.provider,
|
||||
uid=s.uid)
|
||||
if social.count() == 0:
|
||||
objects.append(UserSocialAuth(user=user.first(), provider=s.provider,
|
||||
uid=s.uid)
|
||||
)
|
||||
print('INSERT')
|
||||
|
||||
UserSocialAuth.objects.bulk_create(objects)
|
||||
self.stdout.write(self.style.WARNING(f'Created social objects.'))
|
||||
18
apps/account/migrations/0019_auto_20191108_0827.py
Normal file
18
apps/account/migrations/0019_auto_20191108_0827.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.4 on 2019-11-08 08:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('account', '0018_user_old_id'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='image_url',
|
||||
field=models.URLField(blank=True, default=None, max_length=500, null=True, verbose_name='Image URL path'),
|
||||
),
|
||||
]
|
||||
|
|
@ -89,7 +89,8 @@ class UserQuerySet(models.QuerySet):
|
|||
class User(AbstractUser):
|
||||
"""Base user model."""
|
||||
image_url = models.URLField(verbose_name=_('Image URL path'),
|
||||
blank=True, null=True, default=None)
|
||||
blank=True, null=True, default=None,
|
||||
max_length=500)
|
||||
cropped_image_url = models.URLField(verbose_name=_('Cropped image URL path'),
|
||||
blank=True, null=True, default=None)
|
||||
email = models.EmailField(_('email address'), unique=True,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ class Command(BaseCommand):
|
|||
return namedtuplefetchall(cursor)
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
|
||||
objects = []
|
||||
for p in self.position_sql():
|
||||
count = Position.objects.filter(name={"en-GB": p.position_name}).count()
|
||||
|
|
|
|||
|
|
@ -73,6 +73,28 @@ LOGGING = {
|
|||
}
|
||||
|
||||
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.contrib.gis.db.backends.postgis',
|
||||
'NAME': os.environ.get('DB_NAME'),
|
||||
'USER': os.environ.get('DB_USERNAME'),
|
||||
'PASSWORD': os.environ.get('DB_PASSWORD'),
|
||||
'HOST': os.environ.get('DB_HOSTNAME'),
|
||||
'PORT': os.environ.get('DB_PORT'),
|
||||
},
|
||||
'legacy': {
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
# 'HOST': '172.17.0.1',
|
||||
# 'HOST': '172.23.0.1',
|
||||
'HOST': 'mysql_db',
|
||||
'PORT': 3306,
|
||||
'NAME': 'dev',
|
||||
'USER': 'dev',
|
||||
'PASSWORD': 'octosecret123'
|
||||
}
|
||||
}
|
||||
|
||||
# ELASTICSEARCH SETTINGS
|
||||
ELASTICSEARCH_DSL = {
|
||||
'default': {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
-r base.txt
|
||||
ipdb
|
||||
ipython
|
||||
ipython
|
||||
mysqlclient==1.4.4
|
||||
Loading…
Reference in New Issue
Block a user