chore: enforce USE_TZ setting expectations in migrations (#4386)
* chore: enforce USE_TZ setting expectations in migrations * chore: keep USE_TZ=False until changed manually
This commit is contained in:
parent
8b52d27b02
commit
c2c17cfeb1
|
@ -114,7 +114,7 @@ SITE_ID = 1
|
|||
# to load the internationalization machinery.
|
||||
USE_I18N = False
|
||||
|
||||
USE_TZ = True
|
||||
USE_TZ = False
|
||||
|
||||
if SERVER_MODE == 'production':
|
||||
MEDIA_ROOT = '/a/www/www6s/lib/dt/media/'
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
# Generated by Django 2.2.28 on 2022-06-21 11:44
|
||||
#
|
||||
# Important: To avoid corrupting timestamps in the database, do not use this migration as a dependency for
|
||||
# future migrations. Use 0003_pause_to_change_use_tz instead.
|
||||
#
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, connection
|
||||
|
@ -107,6 +111,10 @@ expected_datetime_columns = (
|
|||
|
||||
|
||||
def forward(apps, schema_editor):
|
||||
# Check that the USE_TZ has been False so far, otherwise we might be corrupting timestamps. If this test
|
||||
# fails, be sure that no timestamps have been set since changing USE_TZ to True before re-running!
|
||||
assert not getattr(settings, 'USE_TZ', False), 'must keep USE_TZ = False until after this migration'
|
||||
|
||||
# Check that we can safely ignore celery beat columns - it defaults to UTC if CELERY_TIMEZONE is not set.
|
||||
celery_timezone = getattr(settings, 'CELERY_TIMEZONE', None)
|
||||
assert celery_timezone in ('UTC', None), 'update migration, celery is not using UTC'
|
||||
|
|
23
ietf/utils/migrations/0003_pause_to_change_use_tz.py
Normal file
23
ietf/utils/migrations/0003_pause_to_change_use_tz.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 2.2.28 on 2022-08-29 10:16
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def forward(apps, schema_editor):
|
||||
assert getattr(settings, 'USE_TZ', False), 'Please change USE_TZ to True before continuing.'
|
||||
|
||||
|
||||
def reverse(apps, schema_editor):
|
||||
assert not getattr(settings, 'USE_TZ', False), 'Please change USE_TZ to False before continuing.'
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('utils', '0002_convert_timestamps_to_utc'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(forward, reverse),
|
||||
]
|
Loading…
Reference in a new issue