jumpserver/apps/assets/migrations/0107_account_history.py

74 lines
2.2 KiB
Python

# Generated by Django 3.2.13 on 2022-10-09 08:50
from django.db import migrations
def migrate_create_history_account(apps, schema_editor):
db_alias = schema_editor.connection.alias
account_model = apps.get_model('assets', 'Account')
history_account_model = apps.get_model('assets', 'HistoricalAccount')
history_accounts = []
for account in account_model.objects.using(db_alias).all():
data = {
'id': account.id,
'secret': account.secret,
'secret_type': account.secret_type,
'history_date': account.date_created,
}
history_accounts.append(history_account_model(**data))
history_account_model.objects.using(db_alias).bulk_create(history_accounts)
class Migration(migrations.Migration):
dependencies = [
('assets', '0106_auto_20220916_1556'),
]
operations = [
migrations.RemoveField(
model_name='historicalaccount',
name='asset',
),
migrations.RemoveField(
model_name='historicalaccount',
name='comment',
),
migrations.RemoveField(
model_name='historicalaccount',
name='created_by',
),
migrations.RemoveField(
model_name='historicalaccount',
name='date_created',
),
migrations.RemoveField(
model_name='historicalaccount',
name='date_updated',
),
migrations.RemoveField(
model_name='historicalaccount',
name='name',
),
migrations.RemoveField(
model_name='historicalaccount',
name='org_id',
),
migrations.RemoveField(
model_name='historicalaccount',
name='privileged',
),
migrations.RemoveField(
model_name='historicalaccount',
name='su_from',
),
migrations.RemoveField(
model_name='historicalaccount',
name='username',
),
migrations.RemoveField(
model_name='historicalaccount',
name='version',
),
migrations.RunPython(migrate_create_history_account),
]