"""fields_raw not nullable

Revision ID: 8e51ac616b91
Revises: 68293032700d
Create Date: 2023-07-28 07:30:34.147891

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '8e51ac616b91'
down_revision = '68293032700d'
branch_labels = None
depends_on = None


def upgrade():
    conn = op.get_bind()
    conn.execute("UPDATE steps SET fields_raw = '{}' WHERE fields_raw IS NULL")

    op.alter_column('steps', 'fields_raw',
               existing_type=postgresql.JSONB(astext_type=sa.Text()),
               nullable=False)


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('steps', 'fields_raw',
               existing_type=postgresql.JSONB(astext_type=sa.Text()),
               nullable=True)
    # ### end Alembic commands ###
