From bd818f1cf2e29717834dc761914f260ba6c74f9f Mon Sep 17 00:00:00 2001 From: androiddrew Date: Mon, 7 May 2018 15:08:47 -0400 Subject: [PATCH] Upgraded to Timezone Aware Datetimes --- alembic.ini | 2 +- cookie_api/models.py | 4 +- ...eb9aabef1dc_changed_datetimes_to_be_utc.py | 67 +++++++++++++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 migrations/versions/7eb9aabef1dc_changed_datetimes_to_be_utc.py diff --git a/alembic.ini b/alembic.ini index 33b6827..45b6fb1 100644 --- a/alembic.ini +++ b/alembic.ini @@ -35,7 +35,7 @@ script_location = migrations # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = driver://user:pass@localhost/dbname +sqlalchemy.url = postgresql://apistar@localhost:5432/apistar # Logging configuration diff --git a/cookie_api/models.py b/cookie_api/models.py index 52d53e0..e19b4ce 100644 --- a/cookie_api/models.py +++ b/cookie_api/models.py @@ -25,8 +25,8 @@ Base = declarative_base() class DBMixin: id = Column(Integer, primary_key=True, autoincrement=True) - created_date = Column(DateTime, server_default=utcnow()) - modified_date = Column(DateTime, server_default=utcnow(), onupdate=utcnow()) + created_date = Column(DateTime(timezone=True), server_default=utcnow()) + modified_date = Column(DateTime(timezone=True), server_default=utcnow(), onupdate=utcnow()) def to_dict(self): d = self.__dict__.copy() diff --git a/migrations/versions/7eb9aabef1dc_changed_datetimes_to_be_utc.py b/migrations/versions/7eb9aabef1dc_changed_datetimes_to_be_utc.py new file mode 100644 index 0000000..eef833b --- /dev/null +++ b/migrations/versions/7eb9aabef1dc_changed_datetimes_to_be_utc.py @@ -0,0 +1,67 @@ +"""Changed Datetimes to be UTC + +Revision ID: 7eb9aabef1dc +Revises: 82595a1e5193 +Create Date: 2018-05-07 13:59:32.923484 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '7eb9aabef1dc' +down_revision = '82595a1e5193' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column( + table_name='cookies', + column_name='created_date', + type_=sa.DateTime(timezone=True) + ) + op.alter_column( + table_name='cookies', + column_name='modified_date', + type_=sa.DateTime(timezone=True) + ) + op.alter_column( + table_name='users', + column_name='created_date', + type_=sa.DateTime(timezone=True) + ) + op.alter_column( + table_name='users', + column_name='modified_date', + type_=sa.DateTime(timezone=True) + ) + op.alter_column( + table_name='orders', + column_name='created_date', + type_=sa.DateTime(timezone=True) + ) + op.alter_column( + table_name='orders', + column_name='modified_date', + type_=sa.DateTime(timezone=True) + ) + op.alter_column( + table_name='line_items', + column_name='created_date', + type_=sa.DateTime(timezone=True) + ) + op.alter_column( + table_name='line_items', + column_name='modified_date', + type_=sa.DateTime(timezone=True) + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + pass + # ### end Alembic commands ###