|
| 1 | +# Generated by Django 4.2.3 on 2023-12-11 01:52 |
| 2 | + |
| 3 | +import base.utils.upload |
| 4 | +from django.conf import settings |
| 5 | +from django.db import migrations, models |
| 6 | +import django.db.models.deletion |
| 7 | +import django.utils.timezone |
| 8 | +import model_utils.fields |
| 9 | +import pgtrigger.compiler |
| 10 | +import pgtrigger.migrations |
| 11 | + |
| 12 | + |
| 13 | +class Migration(migrations.Migration): |
| 14 | + initial = True |
| 15 | + |
| 16 | + dependencies = [ |
| 17 | + migrations.swappable_dependency(settings.AUTH_USER_MODEL), |
| 18 | + ("contenttypes", "0002_remove_content_type_name"), |
| 19 | + ("pghistory", "0005_events_middlewareevents"), |
| 20 | + ] |
| 21 | + |
| 22 | + operations = [ |
| 23 | + migrations.CreateModel( |
| 24 | + name="File", |
| 25 | + fields=[ |
| 26 | + ( |
| 27 | + "id", |
| 28 | + models.BigAutoField( |
| 29 | + auto_created=True, |
| 30 | + primary_key=True, |
| 31 | + serialize=False, |
| 32 | + verbose_name="ID", |
| 33 | + ), |
| 34 | + ), |
| 35 | + ( |
| 36 | + "modified", |
| 37 | + model_utils.fields.AutoLastModifiedField( |
| 38 | + default=django.utils.timezone.now, |
| 39 | + editable=False, |
| 40 | + verbose_name="modified", |
| 41 | + ), |
| 42 | + ), |
| 43 | + ("parent_object_id", models.PositiveIntegerField(null=True)), |
| 44 | + ( |
| 45 | + "content_type", |
| 46 | + models.CharField(blank=True, max_length=150, null=True), |
| 47 | + ), |
| 48 | + ("file_name", models.CharField(blank=True, max_length=512, null=True)), |
| 49 | + ( |
| 50 | + "file_size", |
| 51 | + models.PositiveIntegerField( |
| 52 | + help_text="File size in bytes", null=True |
| 53 | + ), |
| 54 | + ), |
| 55 | + ( |
| 56 | + "file", |
| 57 | + models.FileField( |
| 58 | + max_length=512, |
| 59 | + upload_to=base.utils.upload.set_upload_to_random_filename( |
| 60 | + "files" |
| 61 | + ), |
| 62 | + ), |
| 63 | + ), |
| 64 | + ("name", models.CharField(blank=True, max_length=512, null=True)), |
| 65 | + ("description", models.TextField(blank=True, null=True)), |
| 66 | + ("created", models.DateTimeField(auto_now_add=True)), |
| 67 | + ("updated", models.DateTimeField(auto_now=True)), |
| 68 | + ( |
| 69 | + "created_by", |
| 70 | + models.ForeignKey( |
| 71 | + null=True, |
| 72 | + on_delete=django.db.models.deletion.DO_NOTHING, |
| 73 | + related_name="files_created", |
| 74 | + to=settings.AUTH_USER_MODEL, |
| 75 | + ), |
| 76 | + ), |
| 77 | + ( |
| 78 | + "parent_content_type", |
| 79 | + models.ForeignKey( |
| 80 | + null=True, |
| 81 | + on_delete=django.db.models.deletion.CASCADE, |
| 82 | + to="contenttypes.contenttype", |
| 83 | + ), |
| 84 | + ), |
| 85 | + ], |
| 86 | + options={ |
| 87 | + "abstract": False, |
| 88 | + }, |
| 89 | + ), |
| 90 | + migrations.CreateModel( |
| 91 | + name="FileEvent", |
| 92 | + fields=[ |
| 93 | + ("pgh_id", models.AutoField(primary_key=True, serialize=False)), |
| 94 | + ("pgh_created_at", models.DateTimeField(auto_now_add=True)), |
| 95 | + ("pgh_label", models.TextField(help_text="The event label.")), |
| 96 | + ("id", models.IntegerField()), |
| 97 | + ( |
| 98 | + "modified", |
| 99 | + model_utils.fields.AutoLastModifiedField( |
| 100 | + default=django.utils.timezone.now, |
| 101 | + editable=False, |
| 102 | + verbose_name="modified", |
| 103 | + ), |
| 104 | + ), |
| 105 | + ("parent_object_id", models.PositiveIntegerField(null=True)), |
| 106 | + ( |
| 107 | + "content_type", |
| 108 | + models.CharField(blank=True, max_length=150, null=True), |
| 109 | + ), |
| 110 | + ("file_name", models.CharField(blank=True, max_length=512, null=True)), |
| 111 | + ( |
| 112 | + "file_size", |
| 113 | + models.PositiveIntegerField( |
| 114 | + help_text="File size in bytes", null=True |
| 115 | + ), |
| 116 | + ), |
| 117 | + ( |
| 118 | + "file", |
| 119 | + models.FileField( |
| 120 | + max_length=512, |
| 121 | + upload_to=base.utils.upload.set_upload_to_random_filename( |
| 122 | + "files" |
| 123 | + ), |
| 124 | + ), |
| 125 | + ), |
| 126 | + ("name", models.CharField(blank=True, max_length=512, null=True)), |
| 127 | + ("description", models.TextField(blank=True, null=True)), |
| 128 | + ("created", models.DateTimeField(auto_now_add=True)), |
| 129 | + ("updated", models.DateTimeField(auto_now=True)), |
| 130 | + ( |
| 131 | + "created_by", |
| 132 | + models.ForeignKey( |
| 133 | + db_constraint=False, |
| 134 | + null=True, |
| 135 | + on_delete=django.db.models.deletion.DO_NOTHING, |
| 136 | + related_name="+", |
| 137 | + related_query_name="+", |
| 138 | + to=settings.AUTH_USER_MODEL, |
| 139 | + ), |
| 140 | + ), |
| 141 | + ( |
| 142 | + "parent_content_type", |
| 143 | + models.ForeignKey( |
| 144 | + db_constraint=False, |
| 145 | + null=True, |
| 146 | + on_delete=django.db.models.deletion.DO_NOTHING, |
| 147 | + related_name="+", |
| 148 | + related_query_name="+", |
| 149 | + to="contenttypes.contenttype", |
| 150 | + ), |
| 151 | + ), |
| 152 | + ( |
| 153 | + "pgh_context", |
| 154 | + models.ForeignKey( |
| 155 | + db_constraint=False, |
| 156 | + null=True, |
| 157 | + on_delete=django.db.models.deletion.DO_NOTHING, |
| 158 | + related_name="+", |
| 159 | + to="pghistory.context", |
| 160 | + ), |
| 161 | + ), |
| 162 | + ( |
| 163 | + "pgh_obj", |
| 164 | + models.ForeignKey( |
| 165 | + db_constraint=False, |
| 166 | + on_delete=django.db.models.deletion.DO_NOTHING, |
| 167 | + related_name="event", |
| 168 | + to="baseapp_files.file", |
| 169 | + ), |
| 170 | + ), |
| 171 | + ], |
| 172 | + options={ |
| 173 | + "abstract": False, |
| 174 | + }, |
| 175 | + ), |
| 176 | + pgtrigger.migrations.AddTrigger( |
| 177 | + model_name="file", |
| 178 | + trigger=pgtrigger.compiler.Trigger( |
| 179 | + name="snapshot_insert", |
| 180 | + sql=pgtrigger.compiler.UpsertTriggerSql( |
| 181 | + func='INSERT INTO "baseapp_files_fileevent" ("content_type", "created", "created_by_id", "description", "file", "file_name", "file_size", "id", "modified", "name", "parent_content_type_id", "parent_object_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "updated") VALUES (NEW."content_type", NEW."created", NEW."created_by_id", NEW."description", NEW."file", NEW."file_name", NEW."file_size", NEW."id", NEW."modified", NEW."name", NEW."parent_content_type_id", NEW."parent_object_id", _pgh_attach_context(), NOW(), \'snapshot\', NEW."id", NEW."updated"); RETURN NULL;', |
| 182 | + hash="fdaabf389378057e7d8d7b2eeb304517c32c87f6", |
| 183 | + operation="INSERT", |
| 184 | + pgid="pgtrigger_snapshot_insert_03cf9", |
| 185 | + table="baseapp_files_file", |
| 186 | + when="AFTER", |
| 187 | + ), |
| 188 | + ), |
| 189 | + ), |
| 190 | + pgtrigger.migrations.AddTrigger( |
| 191 | + model_name="file", |
| 192 | + trigger=pgtrigger.compiler.Trigger( |
| 193 | + name="snapshot_update", |
| 194 | + sql=pgtrigger.compiler.UpsertTriggerSql( |
| 195 | + condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)", |
| 196 | + func='INSERT INTO "baseapp_files_fileevent" ("content_type", "created", "created_by_id", "description", "file", "file_name", "file_size", "id", "modified", "name", "parent_content_type_id", "parent_object_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "updated") VALUES (NEW."content_type", NEW."created", NEW."created_by_id", NEW."description", NEW."file", NEW."file_name", NEW."file_size", NEW."id", NEW."modified", NEW."name", NEW."parent_content_type_id", NEW."parent_object_id", _pgh_attach_context(), NOW(), \'snapshot\', NEW."id", NEW."updated"); RETURN NULL;', |
| 197 | + hash="3985b330fe91b2800d985c283c58abf491adc075", |
| 198 | + operation="UPDATE", |
| 199 | + pgid="pgtrigger_snapshot_update_11b9c", |
| 200 | + table="baseapp_files_file", |
| 201 | + when="AFTER", |
| 202 | + ), |
| 203 | + ), |
| 204 | + ), |
| 205 | + ] |
0 commit comments