dashboard/dash/migrations/0006_auto_20220619_0800.py

34 lines
1.0 KiB
Python
Raw Normal View History

# Generated by Django 4.0.3 on 2022-06-19 08:00
from django.db import migrations
from django.db.utils import IntegrityError
def create_default_configs(apps, schema_editor):
InstanceConfiguration = apps.get_model("dash", "InstanceConfiguration")
configs = [
InstanceConfiguration(name="s1-2", rent=10, ram=2, cpu=1, storage=10),
InstanceConfiguration(name="s1-4", rent=20, ram=4, cpu=1, storage=20),
InstanceConfiguration(name="s1-8", rent=40, ram=8, cpu=2, storage=40),
]
for config in configs:
print(f"[*] Saving configuration {config.name}")
try:
config.save()
except IntegrityError as db_error:
print(f"[!] Configuration {config.name} exists")
continue
except Exception as e:
print(f"[ERROR] {e}")
raise e
class Migration(migrations.Migration):
dependencies = [
("dash", "0005_alter_instance_owned_by"),
]
operations = [migrations.RunPython(create_default_configs)]