Browse Source

perf: 添加迁移文件

pull/10181/head
ibuler 2 years ago committed by Jiangjie.Bai
parent
commit
59b27822be
  1. 31
      apps/assets/migrations/0113_auto_20230411_1917.py

31
apps/assets/migrations/0113_auto_20230411_1917.py

@ -0,0 +1,31 @@
# Generated by Django 3.2.17 on 2023-04-11 11:17
from django.db import migrations
def migrate_device_platform_su_method(apps, schema_editor):
platform_model = apps.get_model('assets', 'Platform')
device_map = {
'Huawei': 'super',
'Cisco': 'enable',
'H3C': 'super_level',
}
platforms = platform_model.objects.filter(name__in=device_map.keys())
print()
for platform in platforms:
print("Migrate platform su method: {}".format(platform.name))
if platform.name not in device_map:
continue
platform.su_method = device_map[platform.name]
platform.su_enabled = True
platform.save(update_fields=['su_method', 'su_enabled'])
class Migration(migrations.Migration):
dependencies = [
('assets', '0112_auto_20230404_1631'),
]
operations = [
migrations.RunPython(migrate_device_platform_su_method)
]
Loading…
Cancel
Save