Skip to content

Commit c2c17cf

Browse files
chore: enforce USE_TZ setting expectations in migrations (ietf-tools#4386)
* chore: enforce USE_TZ setting expectations in migrations * chore: keep USE_TZ=False until changed manually
1 parent 8b52d27 commit c2c17cf

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

ietf/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
# to load the internationalization machinery.
115115
USE_I18N = False
116116

117-
USE_TZ = True
117+
USE_TZ = False
118118

119119
if SERVER_MODE == 'production':
120120
MEDIA_ROOT = '/a/www/www6s/lib/dt/media/'

ietf/utils/migrations/0002_convert_timestamps_to_utc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Generated by Django 2.2.28 on 2022-06-21 11:44
2+
#
3+
# Important: To avoid corrupting timestamps in the database, do not use this migration as a dependency for
4+
# future migrations. Use 0003_pause_to_change_use_tz instead.
5+
#
26

37
from django.conf import settings
48
from django.db import migrations, connection
@@ -107,6 +111,10 @@
107111

108112

109113
def forward(apps, schema_editor):
114+
# Check that the USE_TZ has been False so far, otherwise we might be corrupting timestamps. If this test
115+
# fails, be sure that no timestamps have been set since changing USE_TZ to True before re-running!
116+
assert not getattr(settings, 'USE_TZ', False), 'must keep USE_TZ = False until after this migration'
117+
110118
# Check that we can safely ignore celery beat columns - it defaults to UTC if CELERY_TIMEZONE is not set.
111119
celery_timezone = getattr(settings, 'CELERY_TIMEZONE', None)
112120
assert celery_timezone in ('UTC', None), 'update migration, celery is not using UTC'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 2.2.28 on 2022-08-29 10:16
2+
3+
from django.conf import settings
4+
from django.db import migrations
5+
6+
7+
def forward(apps, schema_editor):
8+
assert getattr(settings, 'USE_TZ', False), 'Please change USE_TZ to True before continuing.'
9+
10+
11+
def reverse(apps, schema_editor):
12+
assert not getattr(settings, 'USE_TZ', False), 'Please change USE_TZ to False before continuing.'
13+
14+
15+
class Migration(migrations.Migration):
16+
17+
dependencies = [
18+
('utils', '0002_convert_timestamps_to_utc'),
19+
]
20+
21+
operations = [
22+
migrations.RunPython(forward, reverse),
23+
]

0 commit comments

Comments
 (0)