This commit is contained in:
2026-04-02 23:25:39 +03:30
parent 881f8efa4d
commit bd0d04256c
84 changed files with 2725 additions and 856 deletions
+125
View File
@@ -0,0 +1,125 @@
# Generated by Django 5.2.12 on 2026-03-19 15:01
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="FarmType",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("uuid", models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, unique=True)),
("name", models.CharField(db_index=True, max_length=255, unique=True)),
("description", models.TextField(blank=True, default="")),
("metadata", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
],
options={
"db_table": "farm_types",
"ordering": ["name"],
},
),
migrations.CreateModel(
name="FarmHub",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("farm_uuid", models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, unique=True)),
("name", models.CharField(max_length=255)),
("is_active", models.BooleanField(default=True)),
("customization", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"farm_type",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="farms",
to="farm_hub.farmtype",
),
),
(
"owner",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="farm_hubs",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"db_table": "farm_hubs",
"ordering": ["-created_at"],
},
),
migrations.CreateModel(
name="Product",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("uuid", models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, unique=True)),
("name", models.CharField(db_index=True, max_length=255)),
("description", models.TextField(blank=True, default="")),
("metadata", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"farm_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="products",
to="farm_hub.farmtype",
),
),
],
options={
"db_table": "products",
"ordering": ["name"],
},
),
migrations.CreateModel(
name="FarmSensor",
fields=[
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
("uuid", models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, unique=True)),
("name", models.CharField(max_length=255)),
("sensor_type", models.CharField(blank=True, default="", max_length=255)),
("is_active", models.BooleanField(default=True)),
("specifications", models.JSONField(blank=True, default=dict)),
("power_source", models.JSONField(blank=True, default=dict)),
("customization", models.JSONField(blank=True, default=dict)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"farm",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="sensors",
to="farm_hub.farmhub",
),
),
],
options={
"db_table": "farm_sensors",
"ordering": ["-created_at"],
},
),
migrations.AddField(
model_name="farmhub",
name="products",
field=models.ManyToManyField(blank=True, related_name="farms", to="farm_hub.product"),
),
migrations.AddConstraint(
model_name="product",
constraint=models.UniqueConstraint(fields=("farm_type", "name"), name="unique_product_per_farm_type"),
),
]
@@ -0,0 +1,33 @@
from django.db import migrations
FARM_TYPES = {
"زراعی": ["گندم", "ذرت"],
"درختی": ["سیب", "پسته"],
"غرقابی": ["برنج"],
}
def seed_catalog(apps, schema_editor):
FarmType = apps.get_model("farm_hub", "FarmType")
Product = apps.get_model("farm_hub", "Product")
for farm_type_name, products in FARM_TYPES.items():
farm_type, _ = FarmType.objects.get_or_create(name=farm_type_name)
for product_name in products:
Product.objects.get_or_create(farm_type=farm_type, name=product_name)
def unseed_catalog(apps, schema_editor):
FarmType = apps.get_model("farm_hub", "FarmType")
FarmType.objects.filter(name__in=FARM_TYPES.keys()).delete()
class Migration(migrations.Migration):
dependencies = [
("farm_hub", "0001_initial"),
]
operations = [
migrations.RunPython(seed_catalog, unseed_catalog),
]
View File