"""empty message

Revision ID: roc_dingo_0030_add_packet_acq_time
Revises: roc_dingo_0029_tm_log_partitioning
Create Date: 2024-03-19 16:11:52.588641

"""

from alembic import op
import sqlalchemy as sa

from poppy.pop.alembic.helpers import execute, user


# revision identifiers, used by Alembic.
revision = "roc_dingo_0030_add_packet_acq_time"
down_revision = "roc_dingo_0029_tm_log_partitioning"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "tm_log",
        sa.Column("acq_coarse_time", sa.BIGINT(), nullable=True),
        schema="pipeline",
    )
    op.add_column(
        "tm_log",
        sa.Column("acq_fine_time", sa.INTEGER(), nullable=True),
        schema="pipeline",
    )
    # ### end Alembic commands ###

    # added by hand
    # fix table permissions
    grant_user_seq = """GRANT USAGE, SELECT
        ON ALL SEQUENCES IN SCHEMA pipeline TO {0}""".format(user)
    execute(grant_user_seq)


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("tm_log", "acq_fine_time", schema="pipeline")
    op.drop_column("tm_log", "acq_coarse_time", schema="pipeline")
    # ### end Alembic commands ###
