# Generated by Django 6.0 on 2026-02-11 13:38

import datetime
import django.db.models.deletion
import engine.models.snapshot_control
import uuid
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="Group",
            fields=[
                (
                    "group_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the group",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "group_name",
                    models.CharField(
                        help_text="Name of the group (e.g., 'sales', 'marketing', 'core')",
                        max_length=255,
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        help_text="Optional description of this group",
                        null=True,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the group was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the group was last updated",
                    ),
                ),
            ],
            options={
                "db_table": "group",
                "ordering": ["group_name"],
            },
        ),
        migrations.CreateModel(
            name="PrejoinDefinition",
            fields=[
                (
                    "prejoin_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the prejoin definition",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "prejoin_operator",
                    models.CharField(
                        choices=[("AND", "AND"), ("OR", "OR")],
                        default="AND",
                        help_text="Operator for combining multiple join conditions (AND/OR)",
                        max_length=3,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the prejoin was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the prejoin was last updated",
                    ),
                ),
            ],
            options={
                "verbose_name": "Prejoin Definition",
                "verbose_name_plural": "Prejoin Definitions",
                "db_table": "prejoin_definition",
                "ordering": ["source_table", "prejoin_target_table"],
            },
        ),
        migrations.CreateModel(
            name="Project",
            fields=[
                (
                    "project_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier for the project",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Human-readable name of the project", max_length=255
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        help_text="Optional longer description of the project",
                        null=True,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the project was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the project was last updated",
                    ),
                ),
            ],
            options={
                "db_table": "project",
                "ordering": ["-created_at"],
            },
        ),
        migrations.CreateModel(
            name="SourceColumn",
            fields=[
                (
                    "source_column_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the source column",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "source_column_physical_name",
                    models.CharField(
                        help_text="Physical column name in the source table",
                        max_length=255,
                    ),
                ),
                (
                    "source_column_datatype",
                    models.CharField(
                        help_text="Logical or physical data type of the column",
                        max_length=255,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the source column was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the source column was last updated",
                    ),
                ),
            ],
            options={
                "db_table": "source_column",
                "ordering": ["source_column_physical_name"],
            },
        ),
        migrations.CreateModel(
            name="TemplateCategory",
            fields=[
                (
                    "category_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the template category",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Category name (e.g., 'DataVault4dbt', 'Custom')",
                        max_length=100,
                        unique=True,
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True, help_text="Description of this template category"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name_plural": "Template categories",
                "db_table": "template_category",
                "ordering": ["name"],
            },
        ),
        migrations.CreateModel(
            name="Hub",
            fields=[
                (
                    "hub_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the hub",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "hub_physical_name",
                    models.CharField(
                        help_text="Physical name of the hub (e.g. hub_customer)",
                        max_length=255,
                    ),
                ),
                (
                    "hub_type",
                    models.CharField(
                        choices=[
                            ("standard", "Standard Hub"),
                            ("reference", "Reference Hub"),
                        ],
                        default="standard",
                        help_text="Type of hub: standard or reference",
                        max_length=20,
                    ),
                ),
                (
                    "hub_hashkey_name",
                    models.CharField(
                        blank=True,
                        help_text="Name of the hub hashkey column (used only if hub_type = standard)",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "create_record_tracking_satellite",
                    models.BooleanField(
                        default=False,
                        help_text="If true, a record-tracking satellite should be generated for this hub",
                    ),
                ),
                (
                    "create_effectivity_satellite",
                    models.BooleanField(
                        default=True,
                        help_text="If true, an effectivity satellite should be generated for this hub",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the hub was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the hub was last updated",
                    ),
                ),
                (
                    "group",
                    models.ForeignKey(
                        blank=True,
                        help_text="Optional group for organizing hubs into subfolders",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="hubs",
                        to="engine.group",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        help_text="Project this hub belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="hubs",
                        to="engine.project",
                    ),
                ),
            ],
            options={
                "db_table": "hub",
                "ordering": ["hub_physical_name"],
                "unique_together": {("project", "hub_physical_name")},
            },
        ),
        migrations.CreateModel(
            name="HubColumn",
            fields=[
                (
                    "hub_column_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the hub column",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "column_name",
                    models.CharField(
                        help_text="Logical/target column name in the hub",
                        max_length=255,
                    ),
                ),
                (
                    "column_type",
                    models.CharField(
                        choices=[
                            ("business_key", "Business Key"),
                            ("additional_column", "Additional Column"),
                            ("reference_key", "Reference Key"),
                        ],
                        default="business_key",
                        help_text="Type of column: business_key, additional_column, or reference_key",
                        max_length=30,
                    ),
                ),
                (
                    "sort_order",
                    models.IntegerField(
                        blank=True,
                        help_text="Sorting index to define ordering of hub columns (auto-incremented if not provided)",
                        null=True,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the hub column was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the hub column was last updated",
                    ),
                ),
                (
                    "hub",
                    models.ForeignKey(
                        help_text="Hub this column belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="columns",
                        to="engine.hub",
                    ),
                ),
            ],
            options={
                "db_table": "hub_column",
                "ordering": ["sort_order"],
                "unique_together": {("hub", "column_name")},
            },
        ),
        migrations.CreateModel(
            name="Link",
            fields=[
                (
                    "link_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the link",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "link_physical_name",
                    models.CharField(
                        help_text="Physical name of the link (e.g. customer_order_l)",
                        max_length=255,
                    ),
                ),
                (
                    "link_hashkey_name",
                    models.CharField(
                        default="",
                        help_text="Name of the link hashkey column (e.g. hk_customer_order_l)",
                        max_length=255,
                    ),
                ),
                (
                    "link_type",
                    models.CharField(
                        choices=[
                            ("standard", "Standard"),
                            ("non_historized", "Non-Historized"),
                        ],
                        default="standard",
                        help_text="Type of link: standard or non-historized",
                        max_length=20,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the link was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the link was last updated",
                    ),
                ),
                (
                    "group",
                    models.ForeignKey(
                        blank=True,
                        help_text="Optional group for organizing links into subfolders",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="links",
                        to="engine.group",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        help_text="Project this link belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="links",
                        to="engine.project",
                    ),
                ),
            ],
            options={
                "db_table": "link",
                "ordering": ["link_physical_name"],
                "unique_together": {("project", "link_physical_name")},
            },
        ),
        migrations.CreateModel(
            name="LinkColumn",
            fields=[
                (
                    "link_column_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the link column",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "column_name",
                    models.CharField(
                        help_text="Logical/target column name in the link",
                        max_length=255,
                    ),
                ),
                (
                    "column_type",
                    models.CharField(
                        choices=[
                            ("payload", "Payload"),
                            ("additional_column", "Additional Column"),
                            ("dependant_child_key", "Dependant Child Key"),
                        ],
                        help_text="Type of column: payload or additional_column",
                        max_length=20,
                    ),
                ),
                (
                    "sort_order",
                    models.IntegerField(
                        default=0,
                        help_text="Order of appearance in the link structure. Leave as 0 to auto-assign next available number.",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the link column was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the link column was last updated",
                    ),
                ),
                (
                    "link",
                    models.ForeignKey(
                        help_text="Link this column belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="columns",
                        to="engine.link",
                    ),
                ),
            ],
            options={
                "verbose_name": "Link Column",
                "verbose_name_plural": "Link Columns",
                "db_table": "link_column",
                "ordering": ["link", "sort_order", "column_name"],
                "unique_together": {("link", "column_name")},
            },
        ),
        migrations.CreateModel(
            name="LinkHubReference",
            fields=[
                (
                    "link_hub_reference_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier for the link-to-hub reference",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "hub_hashkey_alias_in_link",
                    models.CharField(
                        blank=True,
                        help_text="Alias for the hub hashkey in the link. Default should be the hub's hashkey name.",
                        max_length=255,
                    ),
                ),
                (
                    "sort_order",
                    models.IntegerField(
                        default=0,
                        help_text="Order of appearance in the link. Leave as 0 to auto-assign next available number.",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the record was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the record was last updated",
                    ),
                ),
                (
                    "hub",
                    models.ForeignKey(
                        help_text="Hub referenced by the link",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="link_references",
                        to="engine.hub",
                    ),
                ),
                (
                    "link",
                    models.ForeignKey(
                        help_text="Link this reference belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="hub_references",
                        to="engine.link",
                    ),
                ),
            ],
            options={
                "verbose_name": "Link Hub Reference",
                "verbose_name_plural": "Link Hub References",
                "db_table": "link_hub_references",
                "ordering": ["link", "sort_order", "hub"],
            },
        ),
        migrations.CreateModel(
            name="PrejoinExtractionColumn",
            fields=[
                (
                    "extraction_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the extraction column",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "prejoin_target_column_alias",
                    models.CharField(
                        blank=True,
                        help_text="Optional alias for the extracted column in the dbt stage. Will overwrite physical column name.",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the extraction column was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the extraction column was last updated",
                    ),
                ),
                (
                    "prejoin",
                    models.ForeignKey(
                        help_text="Prejoin definition this extraction belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="extraction_columns",
                        to="engine.prejoindefinition",
                    ),
                ),
                (
                    "source_column",
                    models.ForeignKey(
                        help_text="Column from the target table to extract",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="prejoin_extractions",
                        to="engine.sourcecolumn",
                    ),
                ),
            ],
            options={
                "verbose_name": "Prejoin Extraction Column",
                "verbose_name_plural": "Prejoin Extraction Columns",
                "db_table": "prejoin_extraction_column",
                "ordering": ["prejoin", "source_column"],
                "unique_together": {("prejoin", "source_column")},
            },
        ),
        migrations.AddField(
            model_name="prejoindefinition",
            name="project",
            field=models.ForeignKey(
                help_text="Project this prejoin belongs to",
                on_delete=django.db.models.deletion.CASCADE,
                related_name="prejoins",
                to="engine.project",
            ),
        ),
        migrations.AddField(
            model_name="group",
            name="project",
            field=models.ForeignKey(
                help_text="Project this group belongs to",
                on_delete=django.db.models.deletion.CASCADE,
                related_name="groups",
                to="engine.project",
            ),
        ),
        migrations.CreateModel(
            name="Satellite",
            fields=[
                (
                    "satellite_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the satellite",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "satellite_physical_name",
                    models.CharField(
                        help_text="Physical name of the satellite (e.g. sat_customer_details)",
                        max_length=255,
                    ),
                ),
                (
                    "satellite_type",
                    models.CharField(
                        choices=[
                            ("standard", "Standard"),
                            ("reference", "Reference"),
                            ("non_historized", "Non-Historized"),
                            ("multi_active", "Multi-Active"),
                        ],
                        default="standard",
                        help_text="Type of satellite",
                        max_length=20,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the satellite was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the satellite was last updated",
                    ),
                ),
                (
                    "group",
                    models.ForeignKey(
                        blank=True,
                        help_text="Optional group for organizing satellites into subfolders",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="satellites",
                        to="engine.group",
                    ),
                ),
                (
                    "parent_hub",
                    models.ForeignKey(
                        blank=True,
                        help_text="Parent hub (if satellite belongs to a hub)",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="satellites",
                        to="engine.hub",
                    ),
                ),
                (
                    "parent_link",
                    models.ForeignKey(
                        blank=True,
                        help_text="Parent link (if satellite belongs to a link)",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="satellites",
                        to="engine.link",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        help_text="Project this satellite belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="satellites",
                        to="engine.project",
                    ),
                ),
            ],
            options={
                "db_table": "satellite",
                "ordering": ["satellite_physical_name"],
            },
        ),
        migrations.CreateModel(
            name="SatelliteColumn",
            fields=[
                (
                    "satellite_column_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the satellite column",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "is_multi_active_key",
                    models.BooleanField(
                        default=False,
                        help_text="If true, this column is part of the multi-active key (for multi-active satellites)",
                    ),
                ),
                (
                    "include_in_delta_detection",
                    models.BooleanField(
                        default=True,
                        help_text="If false, this column is excluded from hashdiff calculation",
                    ),
                ),
                (
                    "target_column_name",
                    models.CharField(
                        blank=True,
                        help_text="Optional target column name (if different from source column name)",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "target_column_transformation",
                    models.TextField(
                        blank=True,
                        help_text="Optional transformation expression for derived columns (future use)",
                        null=True,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the satellite column was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the satellite column was last updated",
                    ),
                ),
                (
                    "satellite",
                    models.ForeignKey(
                        help_text="Satellite this column belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="columns",
                        to="engine.satellite",
                    ),
                ),
                (
                    "source_column",
                    models.ForeignKey(
                        help_text="Source column providing the data",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="satellite_columns",
                        to="engine.sourcecolumn",
                    ),
                ),
            ],
            options={
                "db_table": "satellite_column",
                "ordering": ["satellite", "source_column"],
                "unique_together": {("satellite", "source_column")},
            },
        ),
        migrations.CreateModel(
            name="SnapshotControlTable",
            fields=[
                (
                    "snapshot_control_table_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the snapshot control table",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        default="control_snap",
                        help_text="Base name of the snapshot control (e.g., 'control_snap')",
                        max_length=255,
                    ),
                ),
                (
                    "snapshot_start_date",
                    models.DateField(
                        default=engine.models.snapshot_control.default_snapshot_start_date,
                        help_text="Start date for snapshot range (default: beginning of current year - 5)",
                    ),
                ),
                (
                    "snapshot_end_date",
                    models.DateField(
                        default=engine.models.snapshot_control.default_snapshot_end_date,
                        help_text="End date for snapshot range (default: end of current year + 5)",
                    ),
                ),
                (
                    "daily_snapshot_time",
                    models.TimeField(
                        default=datetime.time(8, 0),
                        help_text="Daily snapshot time (default: 08:00:00)",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the snapshot control table was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the snapshot control table was last updated",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        help_text="Project this snapshot control belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="snapshot_controls",
                        to="engine.project",
                    ),
                ),
            ],
            options={
                "db_table": "snapshot_control_table",
                "ordering": ["project", "snapshot_start_date"],
            },
        ),
        migrations.CreateModel(
            name="SnapshotControlLogic",
            fields=[
                (
                    "snapshot_control_logic_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the snapshot logic entry",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "snapshot_control_logic_column_name",
                    models.CharField(
                        help_text="Column name for this snapshot logic in generated structures",
                        max_length=255,
                    ),
                ),
                (
                    "snapshot_component",
                    models.CharField(
                        choices=[
                            ("daily", "Daily"),
                            ("beginning_of_week", "Beginning of Week"),
                            ("end_of_week", "End of Week"),
                            ("beginning_of_month", "Beginning of Month"),
                            ("end_of_month", "End of Month"),
                            ("beginning_of_quarter", "Beginning of Quarter"),
                            ("end_of_quarter", "End of Quarter"),
                            ("beginning_of_year", "Beginning of Year"),
                            ("end_of_year", "End of Year"),
                        ],
                        help_text="When to take snapshots (daily, beginning/end of week/month/quarter/year)",
                        max_length=30,
                    ),
                ),
                (
                    "snapshot_duration",
                    models.IntegerField(
                        blank=True,
                        help_text="Duration value for snapshot retention (e.g., 3, 6, 12)",
                        null=True,
                    ),
                ),
                (
                    "snapshot_unit",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("DAY", "Day"),
                            ("WEEK", "Week"),
                            ("MONTH", "Month"),
                            ("QUARTER", "Quarter"),
                            ("YEAR", "Year"),
                        ],
                        help_text="Unit for duration: DAY, WEEK, MONTH, QUARTER, YEAR",
                        max_length=10,
                        null=True,
                    ),
                ),
                (
                    "snapshot_forever",
                    models.BooleanField(
                        default=False,
                        help_text="If true, snapshots are kept indefinitely (duration and unit must be NULL)",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the snapshot logic was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the snapshot logic was last updated",
                    ),
                ),
                (
                    "snapshot_control_table",
                    models.ForeignKey(
                        help_text="Snapshot control table this logic belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="logic_rules",
                        to="engine.snapshotcontroltable",
                    ),
                ),
            ],
            options={
                "db_table": "snapshot_control_logic",
                "ordering": ["snapshot_control_table", "snapshot_component"],
            },
        ),
        migrations.CreateModel(
            name="ReferenceTable",
            fields=[
                (
                    "reference_table_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the reference table",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "reference_table_physical_name",
                    models.CharField(
                        help_text="Physical name of the reference table", max_length=255
                    ),
                ),
                (
                    "historization_type",
                    models.CharField(
                        choices=[
                            ("latest", "Latest"),
                            ("full", "Full History"),
                            ("snapshot_based", "Snapshot-Based"),
                        ],
                        default="latest",
                        help_text="Historization strategy: latest, full, or snapshot_based",
                        max_length=20,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the reference table was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the reference table was last updated",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        help_text="Project this reference table belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="reference_tables",
                        to="engine.project",
                    ),
                ),
                (
                    "reference_hub",
                    models.ForeignKey(
                        help_text="Reference hub this table is based on (must be a reference hub)",
                        limit_choices_to={"hub_type": "reference"},
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="reference_tables",
                        to="engine.hub",
                    ),
                ),
                (
                    "snapshot_control_logic",
                    models.ForeignKey(
                        blank=True,
                        help_text="Snapshot control logic (required if historization_type is snapshot_based)",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="reference_tables",
                        to="engine.snapshotcontrollogic",
                    ),
                ),
                (
                    "snapshot_control_table",
                    models.ForeignKey(
                        blank=True,
                        help_text="Snapshot control table (required if historization_type is snapshot_based)",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="reference_tables",
                        to="engine.snapshotcontroltable",
                    ),
                ),
            ],
            options={
                "db_table": "reference_table",
                "ordering": ["project", "reference_table_physical_name"],
                "unique_together": {("project", "reference_table_physical_name")},
            },
        ),
        migrations.AddField(
            model_name="prejoindefinition",
            name="prejoin_condition_source_column",
            field=models.ManyToManyField(
                help_text="Join column(s) from the source table",
                related_name="prejoin_conditions_as_source",
                to="engine.sourcecolumn",
            ),
        ),
        migrations.AddField(
            model_name="prejoindefinition",
            name="prejoin_condition_target_column",
            field=models.ManyToManyField(
                help_text="Join column(s) from the target table",
                related_name="prejoin_conditions_as_target",
                to="engine.sourcecolumn",
            ),
        ),
        migrations.CreateModel(
            name="LinkSourceMapping",
            fields=[
                (
                    "link_source_mapping_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier for a link column mapping",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the mapping was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the mapping was last updated",
                    ),
                ),
                (
                    "link_column",
                    models.ForeignKey(
                        help_text="Link column being mapped",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="source_mappings",
                        to="engine.linkcolumn",
                    ),
                ),
                (
                    "source_column",
                    models.ForeignKey(
                        help_text="Source column mapped to this link column",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="link_column_mappings",
                        to="engine.sourcecolumn",
                    ),
                ),
            ],
            options={
                "verbose_name": "Link Source Mapping",
                "verbose_name_plural": "Link Source Mappings",
                "db_table": "link_source_mapping",
                "ordering": ["link_column"],
            },
        ),
        migrations.CreateModel(
            name="LinkHubSourceMapping",
            fields=[
                (
                    "link_hub_source_mapping_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier for a link hub mapping",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the mapping was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the mapping was last updated",
                    ),
                ),
                (
                    "link_hub_reference",
                    models.ForeignKey(
                        help_text="Link hub reference being mapped",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="source_mappings",
                        to="engine.linkhubreference",
                    ),
                ),
                (
                    "standard_hub_column",
                    models.ForeignKey(
                        help_text="Hub column of the referenced standard hub",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="link_hub_mappings",
                        to="engine.hubcolumn",
                    ),
                ),
                (
                    "prejoin_extraction_column",
                    models.ForeignKey(
                        blank=True,
                        help_text="Prejoin extraction column (XOR with source_column)",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="link_hub_mappings",
                        to="engine.prejoinextractioncolumn",
                    ),
                ),
                (
                    "source_column",
                    models.ForeignKey(
                        blank=True,
                        help_text="Direct source column (XOR with prejoin_extraction_column)",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="link_hub_mappings",
                        to="engine.sourcecolumn",
                    ),
                ),
            ],
            options={
                "verbose_name": "Link Hub Source Mapping",
                "verbose_name_plural": "Link Hub Source Mappings",
                "db_table": "link_hub_source_mapping",
                "ordering": ["link_hub_reference", "standard_hub_column"],
            },
        ),
        migrations.CreateModel(
            name="SourceSystem",
            fields=[
                (
                    "source_system_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the source system",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "schema_name",
                    models.CharField(
                        help_text="Schema name in the source system", max_length=255
                    ),
                ),
                (
                    "database_name",
                    models.CharField(
                        blank=True,
                        help_text="Optional database name (if applicable)",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Human-readable name for this source system",
                        max_length=255,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the source system was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the source system was last updated",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        help_text="Project this source system belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="source_systems",
                        to="engine.project",
                    ),
                ),
            ],
            options={
                "db_table": "source_system",
                "ordering": ["name"],
                "unique_together": {("project", "schema_name", "database_name")},
            },
        ),
        migrations.CreateModel(
            name="SourceTable",
            fields=[
                (
                    "source_table_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the source table",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "physical_table_name",
                    models.CharField(
                        help_text="Physical name of the table in the source system (e.g. CUSTOMER)",
                        max_length=255,
                    ),
                ),
                (
                    "alias",
                    models.CharField(
                        blank=True,
                        help_text="Optional alias used in generated code/dbt models",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "record_source_value",
                    models.CharField(
                        help_text="Value/expression used as record_source for this table",
                        max_length=500,
                    ),
                ),
                (
                    "static_part_of_record_source",
                    models.CharField(
                        blank=True,
                        help_text="Optional static part of record_source that is reused",
                        max_length=500,
                        null=True,
                    ),
                ),
                (
                    "load_date_value",
                    models.CharField(
                        help_text="Expression or column name used as load date value",
                        max_length=500,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the source table was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the source table was last updated",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        help_text="Project this source table belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="source_tables",
                        to="engine.project",
                    ),
                ),
                (
                    "source_system",
                    models.ForeignKey(
                        help_text="Source system this table belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="tables",
                        to="engine.sourcesystem",
                    ),
                ),
            ],
            options={
                "db_table": "source_table",
                "ordering": ["physical_table_name"],
                "unique_together": {("source_system", "physical_table_name")},
            },
        ),
        migrations.AddField(
            model_name="sourcecolumn",
            name="source_table",
            field=models.ForeignKey(
                help_text="Source table this column belongs to",
                on_delete=django.db.models.deletion.CASCADE,
                related_name="columns",
                to="engine.sourcetable",
            ),
        ),
        migrations.AddField(
            model_name="satellite",
            name="source_table",
            field=models.ForeignKey(
                blank=True,
                help_text="Source table that feeds this satellite (all columns must come from this table)",
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="satellites",
                to="engine.sourcetable",
            ),
        ),
        migrations.AddField(
            model_name="prejoindefinition",
            name="prejoin_target_table",
            field=models.ForeignKey(
                help_text="Target table to join (right side of join)",
                on_delete=django.db.models.deletion.CASCADE,
                related_name="prejoins_as_target",
                to="engine.sourcetable",
            ),
        ),
        migrations.AddField(
            model_name="prejoindefinition",
            name="source_table",
            field=models.ForeignKey(
                help_text="Main source table (left side of join)",
                on_delete=django.db.models.deletion.CASCADE,
                related_name="prejoins_as_source",
                to="engine.sourcetable",
            ),
        ),
        migrations.AlterUniqueTogether(
            name="group",
            unique_together={("project", "group_name")},
        ),
        migrations.CreateModel(
            name="ReferenceTableSatelliteAssignment",
            fields=[
                (
                    "assignment_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the satellite assignment",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the assignment was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the assignment was last updated",
                    ),
                ),
                (
                    "reference_table",
                    models.ForeignKey(
                        help_text="Reference table this assignment belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="satellite_assignments",
                        to="engine.referencetable",
                    ),
                ),
                (
                    "reference_satellite",
                    models.ForeignKey(
                        help_text="Reference satellite to include (must be a reference satellite)",
                        limit_choices_to={"satellite_type": "reference"},
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="reference_table_assignments",
                        to="engine.satellite",
                    ),
                ),
                (
                    "exclude_columns",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Specific columns to exclude (only used if include_columns is empty)",
                        related_name="excluded_from_reference_tables",
                        to="engine.satellitecolumn",
                    ),
                ),
                (
                    "include_columns",
                    models.ManyToManyField(
                        blank=True,
                        help_text="Specific columns to include (if empty, includes all except excluded)",
                        related_name="included_in_reference_tables",
                        to="engine.satellitecolumn",
                    ),
                ),
            ],
            options={
                "db_table": "reference_table_satellite_assignment",
                "ordering": ["reference_table", "reference_satellite"],
                "unique_together": {("reference_table", "reference_satellite")},
            },
        ),
        migrations.CreateModel(
            name="PIT",
            fields=[
                (
                    "pit_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the PIT structure",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "pit_physical_name",
                    models.CharField(
                        help_text="Physical name of the PIT structure", max_length=255
                    ),
                ),
                (
                    "tracked_entity_type",
                    models.CharField(
                        choices=[("hub", "Hub"), ("link", "Link")],
                        help_text="Type of entity being tracked (hub or link)",
                        max_length=10,
                    ),
                ),
                (
                    "dimension_key_column_name",
                    models.CharField(
                        blank=True,
                        help_text="Optional dimension key column name in the PIT",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "pit_type",
                    models.CharField(
                        blank=True,
                        help_text="Optional PIT type classification",
                        max_length=100,
                        null=True,
                    ),
                ),
                (
                    "custom_record_source",
                    models.CharField(
                        blank=True,
                        help_text="Optional custom record source value",
                        max_length=255,
                        null=True,
                    ),
                ),
                (
                    "use_snapshot_optimization",
                    models.BooleanField(
                        default=True,
                        help_text="Whether to apply snapshot optimization techniques",
                    ),
                ),
                (
                    "include_business_objects_before_appearance",
                    models.BooleanField(
                        default=False,
                        help_text="Whether to include business keys before their first appearance",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the PIT was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the PIT was last updated",
                    ),
                ),
                (
                    "tracked_hub",
                    models.ForeignKey(
                        blank=True,
                        help_text="Hub being tracked (if tracked_entity_type is 'hub')",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="pits",
                        to="engine.hub",
                    ),
                ),
                (
                    "tracked_link",
                    models.ForeignKey(
                        blank=True,
                        help_text="Link being tracked (if tracked_entity_type is 'link')",
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="pits",
                        to="engine.link",
                    ),
                ),
                (
                    "project",
                    models.ForeignKey(
                        help_text="Project this PIT belongs to",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="pits",
                        to="engine.project",
                    ),
                ),
                (
                    "satellites",
                    models.ManyToManyField(
                        help_text="Satellites included in this PIT structure",
                        related_name="pits",
                        to="engine.satellite",
                    ),
                ),
                (
                    "snapshot_control_logic",
                    models.ForeignKey(
                        help_text="Snapshot control logic for this PIT",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="pits",
                        to="engine.snapshotcontrollogic",
                    ),
                ),
                (
                    "snapshot_control_table",
                    models.ForeignKey(
                        help_text="Snapshot control table for this PIT",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="pits",
                        to="engine.snapshotcontroltable",
                    ),
                ),
            ],
            options={
                "verbose_name": "PIT",
                "verbose_name_plural": "PITs",
                "db_table": "pit",
                "ordering": ["project", "pit_physical_name"],
                "unique_together": {("project", "pit_physical_name")},
            },
        ),
        migrations.CreateModel(
            name="HubSourceMapping",
            fields=[
                (
                    "hub_source_mapping_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the hub-to-source mapping row",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "is_primary_source",
                    models.BooleanField(
                        default=False,
                        help_text="Indicates if this mapping is the primary source for the hub",
                    ),
                ),
                (
                    "created_at",
                    models.DateTimeField(
                        auto_now_add=True,
                        help_text="Timestamp when the mapping was created",
                    ),
                ),
                (
                    "updated_at",
                    models.DateTimeField(
                        auto_now=True,
                        help_text="Timestamp when the mapping was last updated",
                    ),
                ),
                (
                    "hub_column",
                    models.ForeignKey(
                        help_text="Hub column being mapped",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="source_mappings",
                        to="engine.hubcolumn",
                    ),
                ),
                (
                    "source_column",
                    models.ForeignKey(
                        help_text="Source column providing the data",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="hub_mappings",
                        to="engine.sourcecolumn",
                    ),
                ),
            ],
            options={
                "db_table": "hub_source_mapping",
                "unique_together": {("hub_column", "source_column")},
            },
        ),
        migrations.AlterUniqueTogether(
            name="sourcecolumn",
            unique_together={("source_table", "source_column_physical_name")},
        ),
        migrations.AlterUniqueTogether(
            name="satellite",
            unique_together={("project", "satellite_physical_name")},
        ),
        migrations.CreateModel(
            name="ModelTemplate",
            fields=[
                (
                    "template_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        help_text="Unique identifier of the template",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="Template name for identification", max_length=100
                    ),
                ),
                (
                    "entity_type",
                    models.CharField(
                        choices=[
                            ("stage", "Stage"),
                            ("hub_standard", "Hub (Standard)"),
                            ("hub_reference", "Hub (Reference)"),
                            ("link_standard", "Link (Standard)"),
                            ("link_non_historized", "Link (Non-Historized)"),
                            ("satellite_standard", "Satellite (Standard)"),
                            ("satellite_non_historized", "Satellite (Non-Historized)"),
                            ("satellite_reference", "Satellite (Reference)"),
                            ("satellite_multi_active", "Satellite (Multi-Active)"),
                            ("satellite_effectivity", "Effectivity Satellite"),
                            ("satellite_record_tracking", "Record Tracking Satellite"),
                            ("satellite_v1", "Satellite V1 (Load-End-Date View)"),
                            ("pit", "PIT"),
                            ("reference_table", "Reference Table"),
                            ("snapshot_control_v0", "Snapshot Control Table (V0)"),
                            ("snapshot_control_v1", "Snapshot Control Logic (V1)"),
                        ],
                        help_text="Entity type this template applies to",
                        max_length=50,
                    ),
                ),
                (
                    "description",
                    models.TextField(
                        blank=True, help_text="Description of this template variant"
                    ),
                ),
                (
                    "sql_template_content",
                    models.TextField(
                        blank=True,
                        help_text="Jinja2 template for SQL model file. Leave blank to use file-based default.",
                    ),
                ),
                (
                    "yaml_template_content",
                    models.TextField(
                        blank=True,
                        help_text="Jinja2 template for YAML schema file. Leave blank to use file-based default.",
                    ),
                ),
                (
                    "priority",
                    models.IntegerField(
                        default=0,
                        help_text="Priority for template selection. Higher values are preferred.",
                    ),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        default=True,
                        help_text="Whether this template is active and available for selection",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "category",
                    models.ForeignKey(
                        blank=True,
                        help_text="Category for organizing templates",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="templates",
                        to="engine.templatecategory",
                    ),
                ),
            ],
            options={
                "db_table": "model_template",
                "ordering": ["entity_type", "-priority", "name"],
                "unique_together": {("entity_type", "name")},
            },
        ),
    ]
