-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migrations to make DB datetimes tz aware
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.
- Loading branch information
1 parent
41dd32d
commit 502ec9d
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
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,84 @@ | ||
"""make datetimes tz aware | ||
Revision ID: 56627251b8c0 | ||
Revises: 6991bcb18f89 | ||
Create Date: 2024-07-04 14:23:08.370773 | ||
""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "56627251b8c0" | ||
down_revision = "6991bcb18f89" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.alter_column( | ||
"scans", | ||
"queued_at", | ||
existing_type=postgresql.TIMESTAMP(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=True, | ||
postgresql_using="queued_at AS TIME ZONE 'UTC'", | ||
) | ||
op.alter_column( | ||
"scans", | ||
"pending_at", | ||
existing_type=postgresql.TIMESTAMP(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=True, | ||
postgresql_using="pending_at AS TIME ZONE 'UTC'", | ||
) | ||
op.alter_column( | ||
"scans", | ||
"finished_at", | ||
existing_type=postgresql.TIMESTAMP(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=True, | ||
postgresql_using="finished_at AS TIME ZONE 'UTC'", | ||
) | ||
op.alter_column( | ||
"scans", | ||
"reported_at", | ||
existing_type=postgresql.TIMESTAMP(), | ||
type_=sa.DateTime(timezone=True), | ||
existing_nullable=True, | ||
postgresql_using="reported_at AS TIME ZONE 'UTC'", | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.alter_column( | ||
"scans", | ||
"reported_at", | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=postgresql.TIMESTAMP(), | ||
existing_nullable=True, | ||
) | ||
op.alter_column( | ||
"scans", | ||
"finished_at", | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=postgresql.TIMESTAMP(), | ||
existing_nullable=True, | ||
) | ||
op.alter_column( | ||
"scans", | ||
"pending_at", | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=postgresql.TIMESTAMP(), | ||
existing_nullable=True, | ||
) | ||
op.alter_column( | ||
"scans", | ||
"queued_at", | ||
existing_type=sa.DateTime(timezone=True), | ||
type_=postgresql.TIMESTAMP(), | ||
existing_nullable=True, | ||
) |