Merge pull request #11186 from jumpserver/pr@dev@perf_merge_migrations

perf: 合并 migrations
pull/11190/head
老广 1 year ago committed by GitHub
commit 4dc6bd3660
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,7 @@
# Generated by Django 4.1.10 on 2023-07-25 06:58
from django.db import migrations
import json
def migrate_platforms_sftp_protocol(apps, schema_editor):
@ -68,6 +69,24 @@ def migrate_assets_sftp_protocol(apps, schema_editor):
print(" - Add {}".format(len(new_protocols)))
def migrate_telnet_regex(apps, schema_editor):
setting_cls = apps.get_model('settings', 'Setting')
setting = setting_cls.objects.filter(name='TERMINAL_TELNET_REGEX').first()
if not setting:
print("Not found telnet regex setting, skip")
return
try:
value = json.loads(setting.value)
except Exception:
print("Invalid telnet regex setting, skip")
return
platform_protocol_cls = apps.get_model('assets', 'PlatformProtocol')
telnets = platform_protocol_cls.objects.filter(name='telnet')
if telnets.count() > 0:
telnets.update(setting={'success_prompt': value})
print("Migrate telnet regex setting success: ", telnets.count())
class Migration(migrations.Migration):
dependencies = [
@ -77,4 +96,5 @@ class Migration(migrations.Migration):
operations = [
migrations.RunPython(migrate_platforms_sftp_protocol),
migrations.RunPython(migrate_assets_sftp_protocol),
migrations.RunPython(migrate_telnet_regex),
]

@ -1,24 +0,0 @@
# Generated by Django 4.1.10 on 2023-08-01 11:40
from django.db import migrations
def windows_platform_protocols_ssh_default(apps, schema_editor):
platform_cls = apps.get_model('assets', 'Platform')
windows_platform = platform_cls.objects.filter(
name='Windows', internal=True, type='windows'
).first()
if not windows_platform:
return
windows_platform.protocols.filter(name='ssh').update(default=True)
class Migration(migrations.Migration):
dependencies = [
('assets', '0121_auto_20230725_1458'),
]
operations = [
migrations.RunPython(windows_platform_protocols_ssh_default)
]

@ -1,33 +0,0 @@
# Generated by Django 4.1.10 on 2023-08-02 09:40
from django.db import migrations
import json
def migrate_telnet_regex(apps, schema_editor):
setting_cls = apps.get_model('settings', 'Setting')
setting = setting_cls.objects.filter(name='TERMINAL_TELNET_REGEX').first()
if not setting:
print("Not found telnet regex setting, skip")
return
try:
value = json.loads(setting.value)
except Exception:
print("Invalid telnet regex setting, skip")
return
platform_protocol_cls = apps.get_model('assets', 'PlatformProtocol')
telnets = platform_protocol_cls.objects.filter(name='telnet')
if telnets.count() > 0:
telnets.update(setting={'success_prompt': value})
print("Migrate telnet regex setting success: ", telnets.count())
class Migration(migrations.Migration):
dependencies = [
('assets', '0122_auto_20230801_1940'),
]
operations = [
migrations.RunPython(migrate_telnet_regex)
]
Loading…
Cancel
Save