mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
2 years ago
|
# Generated by Django 3.2.14 on 2022-08-17 09:16
|
||
2 years ago
|
import time
|
||
2 years ago
|
|
||
|
from django.db import migrations
|
||
|
|
||
|
|
||
2 years ago
|
def migrate_account_dirty_data(apps, schema_editor):
|
||
|
db_alias = schema_editor.connection.alias
|
||
|
account_model = apps.get_model('applications', 'Account')
|
||
|
|
||
|
count = 0
|
||
|
bulk_size = 1000
|
||
|
|
||
|
while True:
|
||
|
accounts = account_model.objects.using(db_alias) \
|
||
|
.filter(org_id='')[count:count + bulk_size]
|
||
|
|
||
|
if not accounts:
|
||
|
break
|
||
2 years ago
|
|
||
2 years ago
|
accounts = list(accounts)
|
||
|
start = time.time()
|
||
|
for i in accounts:
|
||
|
if i.app:
|
||
|
org_id = i.app.org_id
|
||
|
elif i.systemuser:
|
||
|
org_id = i.systemuser.org_id
|
||
|
else:
|
||
|
org_id = ''
|
||
|
if org_id:
|
||
|
i.org_id = org_id
|
||
|
|
||
|
account_model.objects.bulk_update(accounts, ['org_id', ])
|
||
|
print("Update account org is empty: {}-{} using: {:.2f}s".format(
|
||
|
count, count + len(accounts), time.time() - start
|
||
|
))
|
||
|
count += len(accounts)
|
||
|
|
||
|
|
||
|
class Migration(migrations.Migration):
|
||
2 years ago
|
dependencies = [
|
||
2 years ago
|
('applications', '0025_auto_20220817_1346'),
|
||
2 years ago
|
('perms', '0031_auto_20220816_1600'),
|
||
|
('ops', '0022_auto_20220817_1346'),
|
||
2 years ago
|
('assets', '0105_auto_20220817_1544'),
|
||
2 years ago
|
('tickets', '0020_auto_20220817_1346'),
|
||
|
]
|
||
|
|
||
|
operations = [
|
||
2 years ago
|
migrations.RunPython(migrate_account_dirty_data),
|
||
2 years ago
|
migrations.DeleteModel(
|
||
|
name='Account',
|
||
|
),
|
||
|
migrations.DeleteModel(
|
||
|
name='HistoricalAccount',
|
||
|
),
|
||
|
migrations.DeleteModel(
|
||
|
name='ApplicationUser',
|
||
|
),
|
||
|
]
|