186 lines
12 KiB
Python
186 lines
12 KiB
Python
# Generated by Django 5.0.14 on 2026-01-08 06:56
|
|
|
|
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 = [
|
|
('contenttypes', '0002_remove_content_type_name'),
|
|
('organizations', '0001_initial'),
|
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name='AppreciationBadge',
|
|
fields=[
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('code', models.CharField(help_text='Unique badge code', max_length=50, unique=True)),
|
|
('name_en', models.CharField(max_length=200)),
|
|
('name_ar', models.CharField(blank=True, max_length=200)),
|
|
('description_en', models.TextField(blank=True)),
|
|
('description_ar', models.TextField(blank=True)),
|
|
('icon', models.CharField(blank=True, help_text='Icon class', max_length=50)),
|
|
('color', models.CharField(blank=True, help_text='Hex color code', max_length=7)),
|
|
('criteria_type', models.CharField(choices=[('received_count', 'Total Appreciations Received'), ('received_month', 'Appreciations Received in a Month'), ('streak_weeks', 'Consecutive Weeks with Appreciation'), ('diverse_senders', 'Appreciations from Different Senders')], db_index=True, max_length=50)),
|
|
('criteria_value', models.IntegerField(help_text='Value to achieve (e.g., 10 for 10 appreciations)')),
|
|
('order', models.IntegerField(default=0)),
|
|
('is_active', models.BooleanField(default=True)),
|
|
('hospital', models.ForeignKey(blank=True, help_text='Leave blank for system-wide badges', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='appreciation_badges', to='organizations.hospital')),
|
|
],
|
|
options={
|
|
'ordering': ['hospital', 'order', 'name_en'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='AppreciationCategory',
|
|
fields=[
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('code', models.CharField(help_text='Unique code for this category', max_length=50)),
|
|
('name_en', models.CharField(max_length=200)),
|
|
('name_ar', models.CharField(blank=True, max_length=200)),
|
|
('description_en', models.TextField(blank=True)),
|
|
('description_ar', models.TextField(blank=True)),
|
|
('icon', models.CharField(blank=True, help_text="Icon class (e.g., 'fa-heart', 'fa-star')", max_length=50)),
|
|
('color', models.CharField(blank=True, help_text="Hex color code (e.g., '#FF5733')", max_length=7)),
|
|
('order', models.IntegerField(default=0, help_text='Display order')),
|
|
('is_active', models.BooleanField(default=True)),
|
|
('hospital', models.ForeignKey(blank=True, help_text='Leave blank for system-wide categories', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='appreciation_categories', to='organizations.hospital')),
|
|
],
|
|
options={
|
|
'verbose_name_plural': 'Appreciation Categories',
|
|
'ordering': ['hospital', 'order', 'name_en'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='Appreciation',
|
|
fields=[
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('recipient_object_id', models.UUIDField(blank=True, null=True)),
|
|
('message_en', models.TextField()),
|
|
('message_ar', models.TextField(blank=True)),
|
|
('visibility', models.CharField(choices=[('private', 'Private'), ('department', 'Department'), ('hospital', 'Hospital'), ('public', 'Public')], db_index=True, default='private', max_length=20)),
|
|
('status', models.CharField(choices=[('draft', 'Draft'), ('sent', 'Sent'), ('acknowledged', 'Acknowledged')], db_index=True, default='draft', max_length=20)),
|
|
('is_anonymous', models.BooleanField(default=False, help_text='Hide sender identity from recipient')),
|
|
('sent_at', models.DateTimeField(blank=True, null=True)),
|
|
('acknowledged_at', models.DateTimeField(blank=True, null=True)),
|
|
('notification_sent', models.BooleanField(default=False)),
|
|
('notification_sent_at', models.DateTimeField(blank=True, null=True)),
|
|
('metadata', models.JSONField(blank=True, default=dict)),
|
|
('department', models.ForeignKey(blank=True, help_text='Department context (if applicable)', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='appreciations', to='organizations.department')),
|
|
('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='appreciations', to='organizations.hospital')),
|
|
('recipient_content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='appreciation_recipients', to='contenttypes.contenttype')),
|
|
('sender', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='sent_appreciations', to=settings.AUTH_USER_MODEL)),
|
|
('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='appreciations', to='appreciation.appreciationcategory')),
|
|
],
|
|
options={
|
|
'ordering': ['-created_at'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='AppreciationStats',
|
|
fields=[
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('recipient_object_id', models.UUIDField(blank=True, null=True)),
|
|
('year', models.IntegerField(db_index=True)),
|
|
('month', models.IntegerField(db_index=True, help_text='1-12')),
|
|
('received_count', models.IntegerField(default=0)),
|
|
('sent_count', models.IntegerField(default=0)),
|
|
('acknowledged_count', models.IntegerField(default=0)),
|
|
('hospital_rank', models.IntegerField(blank=True, help_text='Rank within hospital', null=True)),
|
|
('department_rank', models.IntegerField(blank=True, help_text='Rank within department', null=True)),
|
|
('category_breakdown', models.JSONField(blank=True, default=dict, help_text='Breakdown by category ID and count')),
|
|
('metadata', models.JSONField(blank=True, default=dict)),
|
|
('department', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='appreciation_stats', to='organizations.department')),
|
|
('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='appreciation_stats', to='organizations.hospital')),
|
|
('recipient_content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='appreciation_stats_recipients', to='contenttypes.contenttype')),
|
|
],
|
|
options={
|
|
'ordering': ['-year', '-month', '-received_count'],
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='UserBadge',
|
|
fields=[
|
|
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('recipient_object_id', models.UUIDField(blank=True, null=True)),
|
|
('earned_at', models.DateTimeField(auto_now_add=True)),
|
|
('appreciation_count', models.IntegerField(help_text='Count when badge was earned')),
|
|
('metadata', models.JSONField(blank=True, default=dict)),
|
|
('badge', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='earned_by', to='appreciation.appreciationbadge')),
|
|
('recipient_content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='earned_badges_recipients', to='contenttypes.contenttype')),
|
|
],
|
|
options={
|
|
'ordering': ['-earned_at'],
|
|
},
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciationbadge',
|
|
index=models.Index(fields=['hospital', 'is_active'], name='appreciatio_hospita_3847f7_idx'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciationbadge',
|
|
index=models.Index(fields=['code'], name='appreciatio_code_416153_idx'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciationcategory',
|
|
index=models.Index(fields=['hospital', 'is_active'], name='appreciatio_hospita_b8e413_idx'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciationcategory',
|
|
index=models.Index(fields=['code'], name='appreciatio_code_50215a_idx'),
|
|
),
|
|
migrations.AlterUniqueTogether(
|
|
name='appreciationcategory',
|
|
unique_together={('hospital', 'code')},
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciation',
|
|
index=models.Index(fields=['status', '-created_at'], name='appreciatio_status_24158d_idx'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciation',
|
|
index=models.Index(fields=['hospital', 'status'], name='appreciatio_hospita_db3f34_idx'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciation',
|
|
index=models.Index(fields=['recipient_content_type', 'recipient_object_id', '-created_at'], name='appreciatio_recipie_71ef0e_idx'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciation',
|
|
index=models.Index(fields=['visibility', '-created_at'], name='appreciatio_visibil_ed96d9_idx'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciationstats',
|
|
index=models.Index(fields=['hospital', 'year', 'month', '-received_count'], name='appreciatio_hospita_a0d454_idx'),
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='appreciationstats',
|
|
index=models.Index(fields=['department', 'year', 'month', '-received_count'], name='appreciatio_departm_f68345_idx'),
|
|
),
|
|
migrations.AlterUniqueTogether(
|
|
name='appreciationstats',
|
|
unique_together={('recipient_content_type', 'recipient_object_id', 'year', 'month')},
|
|
),
|
|
migrations.AddIndex(
|
|
model_name='userbadge',
|
|
index=models.Index(fields=['recipient_content_type', 'recipient_object_id', '-earned_at'], name='appreciatio_recipie_fc90c8_idx'),
|
|
),
|
|
]
|