# Generated by Django 5.2.8 on 2025-11-25 14:39

import django.db.models.deletion
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="BackupRecord",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4, editable=False, primary_key=True, serialize=False
                    ),
                ),
                (
                    "database_alias",
                    models.CharField(
                        db_index=True, help_text="Django database alias", max_length=100
                    ),
                ),
                (
                    "database_name",
                    models.CharField(help_text="Actual database name", max_length=255),
                ),
                (
                    "database_engine",
                    models.CharField(
                        choices=[
                            ("postgresql", "PostgreSQL"),
                            ("mysql", "MySQL"),
                            ("sqlite", "SQLite"),
                            ("unknown", "Unknown"),
                        ],
                        default="unknown",
                        help_text="Database engine type",
                        max_length=20,
                    ),
                ),
                ("filename", models.CharField(help_text="Backup filename", max_length=500)),
                ("file_path", models.TextField(help_text="Full path or S3 key to backup file")),
                (
                    "file_size",
                    models.BigIntegerField(
                        blank=True, help_text="Backup file size in bytes", null=True
                    ),
                ),
                (
                    "compression",
                    models.CharField(
                        default="gzip", help_text="Compression algorithm used", max_length=10
                    ),
                ),
                (
                    "encrypted",
                    models.BooleanField(default=False, help_text="Whether backup is encrypted"),
                ),
                (
                    "storage_backend",
                    models.CharField(
                        choices=[("local", "Local"), ("s3", "S3")],
                        default="local",
                        help_text="Storage backend type",
                        max_length=10,
                    ),
                ),
                (
                    "storage_bucket",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="S3 bucket name (if S3 storage)",
                        max_length=255,
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "Pending"),
                            ("running", "Running"),
                            ("completed", "Completed"),
                            ("failed", "Failed"),
                            ("deleted", "Deleted"),
                        ],
                        db_index=True,
                        default="pending",
                        help_text="Backup status",
                        max_length=20,
                    ),
                ),
                (
                    "error_message",
                    models.TextField(blank=True, default="", help_text="Error message if failed"),
                ),
                (
                    "started_at",
                    models.DateTimeField(blank=True, help_text="When backup started", null=True),
                ),
                (
                    "completed_at",
                    models.DateTimeField(blank=True, help_text="When backup completed", null=True),
                ),
                (
                    "duration_seconds",
                    models.FloatField(
                        blank=True, help_text="Backup duration in seconds", null=True
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),
                (
                    "is_scheduled",
                    models.BooleanField(
                        default=False, help_text="Whether backup was created by scheduler"
                    ),
                ),
                (
                    "is_manual",
                    models.BooleanField(
                        default=False, help_text="Whether backup was created manually"
                    ),
                ),
                (
                    "tables_count",
                    models.IntegerField(
                        blank=True, help_text="Number of tables backed up", null=True
                    ),
                ),
                (
                    "rows_count",
                    models.BigIntegerField(
                        blank=True, help_text="Approximate number of rows backed up", null=True
                    ),
                ),
                (
                    "checksum",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="SHA256 checksum of backup file",
                        max_length=64,
                    ),
                ),
                (
                    "metadata",
                    models.JSONField(
                        blank=True, default=dict, help_text="Additional backup metadata"
                    ),
                ),
            ],
            options={
                "verbose_name": "Backup Record",
                "verbose_name_plural": "Backup Records",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["database_alias", "status"], name="db_backup_b_databas_e23118_idx"
                    ),
                    models.Index(
                        fields=["created_at", "status"], name="db_backup_b_created_a2c00f_idx"
                    ),
                    models.Index(
                        fields=["storage_backend", "status"], name="db_backup_b_storage_0c1f34_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="RestoreRecord",
            fields=[
                (
                    "id",
                    models.UUIDField(
                        default=uuid.uuid4, editable=False, primary_key=True, serialize=False
                    ),
                ),
                (
                    "target_database_alias",
                    models.CharField(help_text="Target Django database alias", max_length=100),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("pending", "Pending"),
                            ("running", "Running"),
                            ("completed", "Completed"),
                            ("failed", "Failed"),
                        ],
                        db_index=True,
                        default="pending",
                        max_length=20,
                    ),
                ),
                ("error_message", models.TextField(blank=True, default="")),
                ("started_at", models.DateTimeField(blank=True, null=True)),
                ("completed_at", models.DateTimeField(blank=True, null=True)),
                ("duration_seconds", models.FloatField(blank=True, null=True)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "created_by",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="User or system that initiated restore",
                        max_length=255,
                    ),
                ),
                (
                    "backup",
                    models.ForeignKey(
                        help_text="Source backup record",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="restores",
                        to="db_backup.backuprecord",
                    ),
                ),
            ],
            options={
                "verbose_name": "Restore Record",
                "verbose_name_plural": "Restore Records",
                "ordering": ["-created_at"],
            },
        ),
    ]
