Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migrations to make DB datetimes tz aware #266

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Robin5605
Copy link
Contributor

Our models expect the datetimes to be timezone aware, however the database itself has timezone unaware datetimes. This should reconcile that by adding a migration to make the database timezones to be datetime aware.

@Robin5605 Robin5605 requested review from a team as code owners July 4, 2024 19:29
@jonathan-d-zhang jonathan-d-zhang force-pushed the robin/patch/make-datetimes-tz-aware branch 2 times, most recently from 2579baf to 2ab746b Compare August 4, 2024 21:39
@jonathan-d-zhang
Copy link
Contributor

jonathan-d-zhang commented Aug 4, 2024

up migration

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Generating static SQL
INFO  [alembic.runtime.migration] Will assume transactional DDL.
BEGIN;

INFO  [alembic.runtime.migration] Running upgrade 6991bcb18f89 -> 56627251b8c0, make datetimes tz aware
-- Running upgrade 6991bcb18f89 -> 56627251b8c0
ALTER TABLE scans
ALTER COLUMN queued_at TYPE TIMESTAMP WITH TIME ZONE USING queued_at AT TIME ZONE 'UTC',
ALTER COLUMN pending_at TYPE TIMESTAMP WITH TIME ZONE USING pending_at AT TIME ZONE 'UTC',
ALTER COLUMN finished_at TYPE TIMESTAMP WITH TIME ZONE USING finished_at AT TIME ZONE 'UTC',
ALTER COLUMN reported_at TYPE TIMESTAMP WITH TIME ZONE USING reported_at AT TIME ZONE 'UTC';;
ANALYZE scans;;
UPDATE alembic_version SET version_num='56627251b8c0' WHERE alembic_version.version_num = '6991bcb18f89';
COMMIT;

down migration:

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Generating static SQL
INFO  [alembic.runtime.migration] Will assume transactional DDL.
BEGIN;

INFO  [alembic.runtime.migration] Running downgrade 56627251b8c0 -> 6991bcb18f89, make datetimes tz aware
-- Running downgrade 56627251b8c0 -> 6991bcb18f89
ALTER TABLE scans
ALTER COLUMN reported_at TYPE TIMESTAMP WITHOUT TIME ZONE,
ALTER COLUMN finished_at TYPE TIMESTAMP WITHOUT TIME ZONE,
ALTER COLUMN pending_at TYPE TIMESTAMP WITHOUT TIME ZONE,
ALTER COLUMN queued_at TYPE TIMESTAMP WITHOUT TIME ZONE;;
ANALYZE scans;;
UPDATE alembic_version SET version_num='6991bcb18f89' WHERE alembic_version.version_num = '56627251b8c0';
COMMIT;

@jonathan-d-zhang jonathan-d-zhang force-pushed the robin/patch/make-datetimes-tz-aware branch from 2ab746b to 502ec9d Compare August 4, 2024 21:56
Our models expect the datetimes to be timezone aware, however the
database itself has timezone unaware datetimes. This should reconcile
that by adding a migration to make the database timezones to be datetime
aware.
@jonathan-d-zhang jonathan-d-zhang force-pushed the robin/patch/make-datetimes-tz-aware branch from 502ec9d to 80fa49b Compare August 4, 2024 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants