# Generated by Django 3.2.20 on 2023-08-23 10:21

import django.contrib.postgres.fields
import django.db.models.deletion
from django.db import migrations, models

import baserow.core.encoders


class Migration(migrations.Migration):
    dependencies = [
        ("database", "0124_add_encode_uri_component_formula"),
    ]

    operations = [
        migrations.CreateModel(
            name="RowHistory",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "user_id",
                    models.PositiveIntegerField(
                        help_text="The id of the user that performed the action.",
                        null=True,
                    ),
                ),
                (
                    "user_name",
                    models.CharField(
                        blank=True,
                        help_text="The name of the user that performed the action.",
                        max_length=150,
                    ),
                ),
                (
                    "row_id",
                    models.PositiveIntegerField(
                        help_text="The id of the row that was changed."
                    ),
                ),
                (
                    "field_names",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.CharField(max_length=255),
                        help_text="The names of the fields that were changed. All these names must be provided in fields_metadata, before_values and after_values.",
                        size=None,
                    ),
                ),
                (
                    "fields_metadata",
                    models.JSONField(
                        encoder=baserow.core.encoders.JSONEncoderSupportingDataClasses,
                        help_text="The metadata of the fields that were changed.",
                    ),
                ),
                (
                    "action_uuid",
                    models.CharField(
                        help_text="The UUID of the action that was performed resulting in this history entry. ",
                        max_length=36,
                    ),
                ),
                (
                    "action_command_type",
                    models.CharField(
                        choices=[("DO", "DO"), ("UNDO", "UNDO"), ("REDO", "REDO")],
                        default="DO",
                        help_text="The type of command that was performed.",
                        max_length=4,
                    ),
                ),
                (
                    "action_type",
                    models.TextField(
                        help_text="The type of the action that was performed."
                    ),
                ),
                (
                    "action_timestamp",
                    models.DateTimeField(
                        help_text="The timestamp of the action that was performed."
                    ),
                ),
                (
                    "before_values",
                    models.JSONField(
                        encoder=baserow.core.encoders.JSONEncoderSupportingDataClasses,
                        help_text="The values of the row before the action was performed.",
                    ),
                ),
                (
                    "after_values",
                    models.JSONField(
                        encoder=baserow.core.encoders.JSONEncoderSupportingDataClasses,
                        help_text="The values of the row after the action was performed.",
                    ),
                ),
                (
                    "table",
                    models.ForeignKey(
                        help_text="The table that the row belongs to.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="database.table",
                    ),
                ),
            ],
            options={
                "ordering": ("-action_timestamp",),
            },
        ),
        migrations.AddIndex(
            model_name="rowhistory",
            index=models.Index(
                fields=["table", "row_id", "-action_timestamp"],
                name="database_ro_table_i_7d9a59_idx",
            ),
        ),
    ]
