From 051ef74eb7c03c222b3f25550f61cb7d59bde78b Mon Sep 17 00:00:00 2001 From: Luke Van Seters Date: Fri, 26 Nov 2021 11:02:02 -0500 Subject: [PATCH] Convert block_timestmap from numeric to timestamp --- ...af_change_blocks_timestamp_to_timestamp.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 alembic/versions/04b76ab1d2af_change_blocks_timestamp_to_timestamp.py diff --git a/alembic/versions/04b76ab1d2af_change_blocks_timestamp_to_timestamp.py b/alembic/versions/04b76ab1d2af_change_blocks_timestamp_to_timestamp.py new file mode 100644 index 0000000..8ba541d --- /dev/null +++ b/alembic/versions/04b76ab1d2af_change_blocks_timestamp_to_timestamp.py @@ -0,0 +1,36 @@ +"""Change blocks.timestamp to timestamp + +Revision ID: 04b76ab1d2af +Revises: 2c90b2b8a80b +Create Date: 2021-11-26 15:31:21.111693 + +""" +import sqlalchemy as sa +from alembic import op + + +# revision identifiers, used by Alembic. +revision = "04b76ab1d2af" +down_revision = "0cef835f7b36" +branch_labels = None +depends_on = None + + +def upgrade(): + op.alter_column( + "blocks", + "block_timestamp", + type_=sa.TIMESTAMP, + nullable=False, + postgresql_using="TO_TIMESTAMP(block_timestamp)", + ) + + +def downgrade(): + op.alter_column( + "blocks", + "block_timestamp", + type_=sa.Numeric, + nullable=False, + postgresql_using="extract(epoch FROM block_timestamp)", + )