Added food api endpoints prep for mcp
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
# Generated by Django 6.1.1 on 2026-10-07 12:36
|
||||
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def backfill_api_ids(apps, schema_editor):
|
||||
for model_name in ('FoodLogEntry', 'FoodProduct', 'KitchenInventoryItem'):
|
||||
model = apps.get_model('food', model_name)
|
||||
for pk in model.objects.filter(api_id__isnull=True).values_list('pk', flat=True).iterator():
|
||||
model.objects.filter(pk=pk).update(api_id=uuid.uuid4())
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0003_inventorycategory_inventorylocation_and_more'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='foodlogentry',
|
||||
name='api_id',
|
||||
field=models.UUIDField(null=True, editable=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='foodlogentry',
|
||||
name='created_via',
|
||||
field=models.CharField(default='web', max_length=16),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='foodproduct',
|
||||
name='api_id',
|
||||
field=models.UUIDField(null=True, editable=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='kitcheninventoryitem',
|
||||
name='api_id',
|
||||
field=models.UUIDField(null=True, editable=False),
|
||||
),
|
||||
migrations.RunPython(backfill_api_ids, migrations.RunPython.noop),
|
||||
migrations.AlterField(model_name='foodlogentry', name='api_id', field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
|
||||
migrations.AlterField(model_name='foodproduct', name='api_id', field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
|
||||
migrations.AlterField(model_name='kitcheninventoryitem', name='api_id', field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
|
||||
migrations.CreateModel(
|
||||
name='FoodLogAttachment',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('api_id', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
|
||||
('image', models.ImageField(upload_to='food-attachments/%Y/%m/')),
|
||||
('original_filename', models.CharField(max_length=255)),
|
||||
('content_type', models.CharField(max_length=50)),
|
||||
('file_size', models.PositiveIntegerField()),
|
||||
('caption', models.CharField(blank=True, max_length=255)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('log_entry', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='food.foodlogentry')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='PersonalAccessToken',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('prefix', models.CharField(max_length=20, unique=True)),
|
||||
('token_hash', models.CharField(max_length=64)),
|
||||
('scopes', models.JSONField(default=list)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('last_used_at', models.DateTimeField(blank=True, null=True)),
|
||||
('expires_at', models.DateTimeField(blank=True, null=True)),
|
||||
('revoked_at', models.DateTimeField(blank=True, null=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='personal_access_tokens', to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ApiIdempotencyRecord',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('key', models.CharField(max_length=128)),
|
||||
('request_hash', models.CharField(max_length=64)),
|
||||
('response', models.JSONField()),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('token', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='food.personalaccesstoken')),
|
||||
],
|
||||
options={
|
||||
'constraints': [models.UniqueConstraint(fields=('token', 'key'), name='food_unique_api_idempotency_key')],
|
||||
},
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user