-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrations: add created and updated fields to model (#11067)
* Integrations: add created and updated fields to model * Set fields as nullable * Add data migration * Format
- Loading branch information
Showing
3 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
readthedocs/integrations/migrations/0011_add_created_and_updated_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 4.2.9 on 2024-01-25 17:46 | ||
|
||
import django.utils.timezone | ||
import django_extensions.db.fields | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("integrations", "0010_remove_old_jsonfields"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name="integration", | ||
options={"get_latest_by": "modified"}, | ||
), | ||
migrations.AddField( | ||
model_name="integration", | ||
name="created", | ||
field=django_extensions.db.fields.CreationDateTimeField( | ||
auto_now_add=True, | ||
default=django.utils.timezone.now, | ||
verbose_name="created", | ||
null=True, | ||
blank=True, | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.AddField( | ||
model_name="integration", | ||
name="modified", | ||
field=django_extensions.db.fields.ModificationDateTimeField( | ||
auto_now=True, | ||
verbose_name="modified", | ||
null=True, | ||
blank=True, | ||
), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
readthedocs/integrations/migrations/0012_migrate_timestamp_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.9 on 2024-01-29 19:16 | ||
|
||
from django.db import migrations | ||
from django.utils import timezone | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
Integration = apps.get_model("integrations", "Integration") | ||
Integration.objects.filter(created=None).update(created=timezone.now()) | ||
Integration.objects.filter(modified=None).update(modified=timezone.now()) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("integrations", "0011_add_created_and_updated_fields"), | ||
] | ||
|
||
operations = [migrations.RunPython(forwards_func)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters