From f041c62ef02b9683966bace551e5c29a14fde415 Mon Sep 17 00:00:00 2001
From: Santos Gallegos <stsewd@proton.me>
Date: Thu, 30 Jan 2025 10:49:48 -0500
Subject: [PATCH] ImportedFile: use BigAutoField for primary key (#9669)

We could disable search indexing while we do the migration, but I don't
think that should be required, we have 11M records, but to migrate the
SphinxDomain model it took 15 min, and we had ~56M.

```python
In [7]: ImportedFile.objects.count()
Out[7]: 11527437
```

So some 3 min of not being able to index new versions doesn't seem
bad... There are two things that could happen:

- The query times out and we don't index that version.
- The query waits till the migration is done, nothing gets lost.

But if we disable search indexing we definitely
won't index new versions.

We don't use those models outside search indexing, so doc serving and
such shouldn't be affected.

ref https://github.com/readthedocs/readthedocs.org/issues/9492
---
 .../migrations/0144_alter_importedfile_id.py  | 19 +++++++++++++++++++
 readthedocs/projects/models.py                |  1 +
 2 files changed, 20 insertions(+)
 create mode 100644 readthedocs/projects/migrations/0144_alter_importedfile_id.py

diff --git a/readthedocs/projects/migrations/0144_alter_importedfile_id.py b/readthedocs/projects/migrations/0144_alter_importedfile_id.py
new file mode 100644
index 00000000000..aaecb4643cb
--- /dev/null
+++ b/readthedocs/projects/migrations/0144_alter_importedfile_id.py
@@ -0,0 +1,19 @@
+from django.db import migrations, models
+from django_safemigrate import Safe
+
+
+class Migration(migrations.Migration):
+
+    safe = Safe.after_deploy
+
+    dependencies = [
+        ("projects", "0143_addons_flyout_position"),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name="importedfile",
+            name="id",
+            field=models.BigAutoField(primary_key=True, serialize=False),
+        ),
+    ]
diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py
index 540f4a9828d..837fa6d3c30 100644
--- a/readthedocs/projects/models.py
+++ b/readthedocs/projects/models.py
@@ -1488,6 +1488,7 @@ class ImportedFile(models.Model):
     things like CDN invalidation.
     """
 
+    id = models.BigAutoField(primary_key=True)
     project = models.ForeignKey(
         Project,
         verbose_name=_("Project"),